Skip to content

Commit

Permalink
release: 1.0.23
Browse files Browse the repository at this point in the history
  • Loading branch information
HananoshikaYomaru committed Nov 30, 2023
1 parent d4670f2 commit 5113c67
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 39 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "frontmatter-generator",
"name": "Frontmatter generator",
"version": "1.0.22",
"version": "1.0.23",
"minAppVersion": "0.15.0",
"description": "Generate frontmatter for your notes from json and javascript",
"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-frontmatter-generator",
"version": "1.0.22",
"version": "1.0.23",
"description": "A plugin for Obsidian that generates frontmatter for notes.",
"main": "main.js",
"scripts": {
Expand Down
63 changes: 31 additions & 32 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,48 +181,47 @@ export default class FrontmatterGeneratorPlugin extends Plugin {
this.app.workspace.on("file-menu", async (menu, file) => {
if (file instanceof TFile && isMarkdownFile(file)) {
menu.addItem((item) => {
item.setTitle(
"Generate frontmatter for this file"
).onClick(async () => {
const activeFile =
this.app.workspace.getActiveFile();
const view =
this.app.workspace.getActiveViewOfType(
MarkdownView
);
const editor = view?.editor;
const isUsingPropertiesEditor =
view?.getMode() === "source" &&
// @ts-ignore
!view.currentMode.sourceMode;
if (
activeFile === file &&
editor &&
!isUsingPropertiesEditor
) {
this.runFileSync(file, editor);
} else if (
activeFile === file &&
editor &&
isUsingPropertiesEditor
) {
await this.runFile(file);
}
});
item.setIcon("file-cog")
.setTitle("Generate frontmatter for this file")
.onClick(async () => {
const activeFile =
this.app.workspace.getActiveFile();
const view =
this.app.workspace.getActiveViewOfType(
MarkdownView
);
const editor = view?.editor;
const isUsingPropertiesEditor =
view?.getMode() === "source" &&
// @ts-ignore
!view.currentMode.sourceMode;
if (
activeFile === file &&
editor &&
!isUsingPropertiesEditor
) {
this.runFileSync(file, editor);
} else if (
activeFile === file &&
editor &&
isUsingPropertiesEditor
) {
await this.runFile(file);
}
});
});
} else if (file instanceof TFolder) {
menu.addItem((item) => {
item.setTitle(
"Generate frontmatter in this folder"
).onClick(() => this.runAllFilesInFolder(file));
item.setIcon("file-cog")
.setTitle("Generate frontmatter in this folder")
.onClick(() => this.runAllFilesInFolder(file));
});
}
})
);

this.registerEvent(
this.app.vault.on("modify", async (file) => {
console.log("modify", file);
if (!this.settings.runOnModify) return;
if (this.lock) return;
try {
Expand Down
17 changes: 13 additions & 4 deletions src/utils/obsidian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,31 @@ export function getAllFilesInFolder(startingFolder: TFolder): TFile[] {
export const getDataFromTextSync = (text: string) => {
const yamlText = getYAMLText(text);

const yamlObj = yamlText
? (parseYaml(yamlText) as { [x: string]: any })
: null;

const { body } = splitYamlAndBody(text);

const tags: string[] = [];
const yamlTags = yamlObj?.tags as string | string[] | undefined;

// if tags is a string, convert it to an array
const _tags = typeof yamlTags === "string" ? [yamlTags] : yamlTags;

const tags: string[] = _tags ? _tags.map((t) => `#${t}`) : [];
ignoreListOfTypes([IgnoreTypes.yaml], text, (text) => {
// get all the tags except the generated ones
tags.push(...matchTagRegex(text));

return text;
});

console.log(tags);

return {
text,
yamlText,
yamlObj: yamlText
? (parseYaml(yamlText) as { [x: string]: any })
: null,
yamlObj,
tags,
body,
};
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"1.0.19": "0.15.0",
"1.0.20": "0.15.0",
"1.0.21": "0.15.0",
"1.0.22": "0.15.0"
"1.0.22": "0.15.0",
"1.0.23": "0.15.0"
}

0 comments on commit 5113c67

Please sign in to comment.