Skip to content

Commit

Permalink
release: 1.0.24
Browse files Browse the repository at this point in the history
  • Loading branch information
HananoshikaYomaru committed Nov 30, 2023
1 parent 5113c67 commit 636a9fc
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 25 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.23",
"version": "1.0.24",
"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.23",
"version": "1.0.24",
"description": "A plugin for Obsidian that generates frontmatter for notes.",
"main": "main.js",
"scripts": {
Expand Down
12 changes: 10 additions & 2 deletions src/FrontmatterGeneratorPluginSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ export interface FrontmatterGeneratorPluginSettings {
internal: {
ignoredFolders: string[];
};
runOnModify: boolean;
/**
* run on modify when user is not in the file
*/
runOnModifyNotInFile: boolean;
/**
* run on modify when user is in the file
*/
runOnModifyInFile: boolean;
sortYamlKey: boolean;
}
export const DEFAULT_SETTINGS: FrontmatterGeneratorPluginSettings = {
Expand All @@ -13,6 +20,7 @@ export const DEFAULT_SETTINGS: FrontmatterGeneratorPluginSettings = {
internal: {
ignoredFolders: [],
},
runOnModify: false,
runOnModifyNotInFile: false,
runOnModifyInFile: false,
sortYamlKey: true,
};
42 changes: 26 additions & 16 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,23 +222,34 @@ export default class FrontmatterGeneratorPlugin extends Plugin {

this.registerEvent(
this.app.vault.on("modify", async (file) => {
if (!this.settings.runOnModify) return;
const view =
this.app.workspace.getActiveViewOfType(MarkdownView);
const isUsingPropertiesEditor =
view?.getMode() === "preview" ||
(view?.getMode() === "source" &&
// @ts-ignore
!view.currentMode.sourceMode);
// the markdown preview type is not complete
// view.currentMode.type === "source" / "preview"
const editor = view?.editor;

// get current file from the active view
const activeFile = this.app.workspace.getActiveFile();

// even if the active file is the target file, we still need to check if the user is using the properties editor
if (
!this.settings.runOnModifyInFile &&
activeFile === file &&
editor &&
!isUsingPropertiesEditor
)
return;

if (!this.settings.runOnModifyNotInFile && activeFile !== file)
return;
if (this.lock) return;
try {
if (file instanceof TFile && isMarkdownFile(file)) {
const activeFile = this.app.workspace.getActiveFile();
const view =
this.app.workspace.getActiveViewOfType(
MarkdownView
);
const isUsingPropertiesEditor =
view?.getMode() === "preview" ||
(view?.getMode() === "source" &&
// @ts-ignore
!view.currentMode.sourceMode);
// the markdown preview type is not complete
// view.currentMode.type === "source" / "preview"
const editor = view?.editor;
if (activeFile === file && editor) {
if (isUsingPropertiesEditor)
await this.runFile(file);
Expand All @@ -256,8 +267,7 @@ export default class FrontmatterGeneratorPlugin extends Plugin {

this.registerEvent(
this.app.workspace.on("editor-change", async (editor) => {
if (!this.settings.runOnModify) return;
if (this.lock) return;
if (!this.settings.runOnModifyInFile) return;
this.lock = true;
try {
const file = this.app.workspace.getActiveFile();
Expand Down
24 changes: 20 additions & 4 deletions src/ui/SettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,29 @@ export class SettingTab extends PluginSettingTab {
});

new Setting(containerEl)
.setName("Run on modify")
.setDesc("Run the plugin when a file is modified")
.setName("Run on modify not in file")
.setDesc(
"Run the plugin when a file is modified and the file is not in active markdown view"
)
.addToggle((toggle) => {
toggle
.setValue(this.plugin.settings.runOnModify)
.setValue(this.plugin.settings.runOnModifyNotInFile)
.onChange(async (value) => {
this.plugin.settings.runOnModify = value;
this.plugin.settings.runOnModifyNotInFile = value;
await this.plugin.saveSettings();
});
});

new Setting(containerEl)
.setName("Run on modify in file")
.setDesc(
"Run the plugin when a file is modified and the file is in active markdown view"
)
.addToggle((toggle) => {
toggle
.setValue(this.plugin.settings.runOnModifyInFile)
.onChange(async (value) => {
this.plugin.settings.runOnModifyInFile = value;
await this.plugin.saveSettings();
});
});
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
"1.0.20": "0.15.0",
"1.0.21": "0.15.0",
"1.0.22": "0.15.0",
"1.0.23": "0.15.0"
"1.0.23": "0.15.0",
"1.0.24": "0.15.0"
}

0 comments on commit 636a9fc

Please sign in to comment.