Edit view-manager: edit getFrontMatter to json fromat

This commit is contained in:
Hyeonseo Nam 2023-03-20 01:03:03 +09:00
parent fd4adf989a
commit 29e81bc97f

View file

@ -1,4 +1,4 @@
import { App, MarkdownView, Notice, Editor, getAllTags, TagCache} from "obsidian";
import { App, MarkdownView, Notice, Editor, getAllTags, TagCache, FrontMatterCache} from "obsidian";
export class ViewManager {
app: App;
@ -26,12 +26,15 @@ export class ViewManager {
return null;
}
async getFrontMatter(): Promise<Record<string, unknown> | null> {
async getFrontMatter(): Promise<string | null> {
const activeView = this.app.workspace.getActiveViewOfType(MarkdownView);
if (activeView) {
const file = activeView.file;
const cache = this.app.metadataCache.getFileCache(file);
return cache?.frontmatter || null;
const frontmatter:FrontMatterCache | undefined = this.app.metadataCache.getFileCache(file)?.frontmatter;
if (frontmatter && frontmatter.hasOwnProperty('position')) {
delete frontmatter.position;
}
return JSON.stringify(frontmatter);
}
return null;
}