generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#207 Allow the event deletion from frontmatter
- Loading branch information
Showing
6 changed files
with
90 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { Editor, MarkdownView } from "obsidian"; | ||
import { createNotice } from "./NoticeHelper"; | ||
import { googleGetEvent } from "../googleApi/GoogleGetEvent"; | ||
import _ from "lodash"; | ||
import { googleDeleteEvent } from "../googleApi/GoogleDeleteEvent"; | ||
|
||
export const deleteEventFromFrontmatter = async (editor: Editor, view: MarkdownView) => { | ||
let fileContent = editor.getValue(); | ||
|
||
//Use a copy to prevent problems when running the command multiple times | ||
const frontmatter: any = _.cloneDeep(app?.metadataCache?.getFileCache(view.file)?.frontmatter) ?? {}; | ||
|
||
if(!frontmatter["event-id"]){ | ||
createNotice("No event id found in note", true); | ||
return; | ||
} | ||
|
||
const event_id = frontmatter["event-id"]; | ||
const event = await googleGetEvent(event_id); | ||
const gotDeleted = await googleDeleteEvent(event); | ||
|
||
if(gotDeleted) { | ||
const lineRegex = new RegExp(`event-id: ${event_id}(\r\n|\r|\n)`, "g"); | ||
fileContent = fileContent.replace(lineRegex, ""); | ||
editor.setValue(fileContent); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters