Skip to content

Commit

Permalink
perf: use native frontmatter edit method instead of graymatter
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenlx committed May 5, 2023
1 parent d618f4b commit 3948b68
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 68 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "alx-folder-note",
"name": "AidenLx's Folder Note",
"version": "0.16.4",
"minAppVersion": "0.14.8",
"minAppVersion": "1.1.0",
"description": "Add description, summary and more info to folders with folder notes.",
"author": "AidenLx",
"authorUrl": "https://github.com/aidenlx",
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-simple-import-sort": "~7.0.0",
"fast-deep-equal": "^3.1.3",
"gray-matter": "^4.0.3",
"monkey-around": "^2.3.0",
"obsidian": "~1.2.8",
"path-browserify": "^1.0.1",
Expand Down
55 changes: 0 additions & 55 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 7 additions & 11 deletions src/modules/set-folder-icon.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import type { IconInfo } from "@aidenlx/obsidian-icon-shortcodes/lib/icon-packs/types";
import matter from "gray-matter";
import { MarkdownView, TFile, TFolder } from "obsidian";

import type ALxFolderNote from "../fn-main";

const registerSetFolderIconCmd = (plugin: ALxFolderNote) => {
const { workspace, vault } = plugin.app;
const setIconField = async (icon: IconInfo | null, file: TFile) =>
icon &&
vault.modify(
file,
(matter(await vault.read(file)).stringify as any)(
{ icon: icon.id },
{ flowLevel: 3, indent: 4 },
),
);
const { workspace, vault, fileManager } = plugin.app;
const setIconField = async (icon: IconInfo | null, file: TFile) => {
if (!icon) return;
await fileManager.processFrontMatter(file, (fm) => {
fm.icon = icon.id;
});
};
plugin.addCommand({
id: "set-folder-icon",
name: "Set Folder Icon",
Expand Down

0 comments on commit 3948b68

Please sign in to comment.