Skip to content

Commit

Permalink
release: 1.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
HananoshikaYomaru committed Dec 12, 2023
1 parent f6474b7 commit c4f13e7
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "publish-url",
"name": "Publish url",
"version": "1.0.7",
"version": "1.0.8",
"minAppVersion": "0.15.0",
"description": "Obsidian Publish url to the clipboard",
"author": "Hananoshika Yomaru",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-publish-url",
"version": "1.0.7",
"version": "1.0.8",
"description": "Get the publish url",
"main": "main.js",
"scripts": {
Expand Down
33 changes: 27 additions & 6 deletions src/NoticeManager.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
import { Notice, Plugin } from "obsidian";

// map the color to the color of the notice
const colorMap = {
success: "green",
warning: "yellow",
error: "red",
info: "blue",
};

export class NoticeManager {
plugin: Plugin;
constructor(plugin: Plugin) {
this.plugin = plugin;
}

createNotice = (
message: string | DocumentFragment,
duration?: number | undefined
message: string,
duration?: number | undefined,
color?: "success" | "warning" | "error" | "info"
): Notice => {
const notice = new Notice(
`${this.plugin.manifest.name}: ${message}`,
duration
);
let notice: Notice;
if (color) {
// create a fragment, create a div inside, set the color and text of the div
const fragment = document.createDocumentFragment();
const div = document.createElement("div");
div.style.color = colorMap[color];
div.setText(`${this.plugin.manifest.name}: ${message}`);
fragment.appendChild(div);

notice = new Notice(fragment, duration);
} else {
notice = new Notice(
`${this.plugin.manifest.name}: ${message}`,
duration
);
}
return notice;
};
}
19 changes: 16 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ export default class PublishUrlSetting extends Plugin {
return isMarkdownFile(file);
}

// get the current note cover and description
// if the current note has no cover or description, show a warning notice
const frontmatter =
that.app.metadataCache.getFileCache(file)?.frontmatter;
const cover = frontmatter?.cover;
const description = frontmatter?.description;
if (!cover || !description) {
that.createNotice(
"Current note has no cover or description",
5000,
"warning"
);
}

// get the publish url
const publishUrl = that.copyPublishUrl(file);
const theogUrl = that.copyTheogUrl(
Expand Down Expand Up @@ -150,9 +164,8 @@ export default class PublishUrlSetting extends Plugin {
};

createNotice = (
message: string | DocumentFragment,
duration?: number | undefined
): Notice => this.noticeManager.createNotice(message, duration);
...props: Parameters<NoticeManager["createNotice"]>
): Notice => this.noticeManager.createNotice(...props);

onunload() {
super.onunload();
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"1.0.4": "0.15.0",
"1.0.5": "0.15.0",
"1.0.6": "0.15.0",
"1.0.7": "0.15.0"
"1.0.7": "0.15.0",
"1.0.8": "0.15.0"
}

0 comments on commit c4f13e7

Please sign in to comment.