A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
web: add md with frontmatter export
Abdullah Atta134904b5512c
diff --git a/apps/web/src/common/export.ts b/apps/web/src/common/export.tsindex b84a1bb4c..1a0c07ed7 100644--- a/apps/web/src/common/export.ts+++ b/apps/web/src/common/export.ts@@ -25,6 +25,14 @@ import { showToast } from "../utils/toast";import { sanitizeFilename } from "@notesnook/common";import Vault from "./vault";+const FORMAT_TO_EXT = {+ pdf: "pdf",+ md: "md",+ txt: "txt",+ html: "html",+ "md-frontmatter": "md"+} as const;+export async function exportToPDF(title: string,content: string@@ -69,7 +77,7 @@ export async function exportToPDF(}export async function exportNotes(- format: "pdf" | "md" | "txt" | "html",+ format: "pdf" | "md" | "txt" | "html" | "md-frontmatter",noteIds: string[]): Promise<boolean> {return await TaskManager.startTask({@@ -139,10 +147,10 @@ export async function exportNotes(if (files.length === 1) {saveAs(new Blob([Buffer.from(files[0].content, "utf-8")]),- `${sanitizeFilename(files[0].filename)}.${format}`+ `${sanitizeFilename(files[0].filename)}.${FORMAT_TO_EXT[format]}`);} else {- const zipped = await zip(files, format);+ const zipped = await zip(files, FORMAT_TO_EXT[format]);saveAs(new Blob([zipped.buffer]), "notes.zip");}diff --git a/apps/web/src/components/note/index.tsx b/apps/web/src/components/note/index.tsxindex 54fb79bc9..73b3e34de 100644--- a/apps/web/src/components/note/index.tsx+++ b/apps/web/src/components/note/index.tsx@@ -305,6 +305,12 @@ const formats = [icon: Markdown,subtitle: "Can be opened in any plain-text or markdown editor."},+ {+ type: "md-frontmatter",+ title: "Markdown + Frontmatter",+ icon: Markdown,+ subtitle: "Can be opened in any plain-text or markdown editor."+ },{type: "html",title: "HTML",diff --git a/packages/core/src/models/note.js b/packages/core/src/models/note.jsindex 621c882f8..d4a5c5da5 100644--- a/packages/core/src/models/note.js+++ b/packages/core/src/models/note.js@@ -88,6 +88,7 @@ export default class Note {async export(to = "html", contentItem, template = true, rawHTML) {if (to !== "txt" && !(await checkIsUserPremium(CHECK_IDS.noteExport)))return false;+ if (!this.data) return false;const templateData = {metadata: this.data,diff --git a/packages/core/src/utils/templates/markdown/template.js b/packages/core/src/utils/templates/markdown/template.jsindex 9889e66e7..ba6e65abc 100644--- a/packages/core/src/utils/templates/markdown/template.js+++ b/packages/core/src/utils/templates/markdown/template.js@@ -22,15 +22,22 @@ export const template = (data) => `# ${data.title}${data.content}`;export const templateWithFrontmatter = (data) => `----title: ${JSON.stringify(data.title || "")}-created_at: ${data.createdOn}-updated_at: ${data.editedOn}-pinned: ${data.metadata.pinned}-favorite: ${data.metadata.favorite}-color: ${data.metadata.color}-tags: ${data.tags}+${buildFrontmatter(data)}---# ${data.title}${data.content}`;++function buildFrontmatter(data) {+ const lines = [+ `title: ${JSON.stringify(data.title || "")}`,+ `created_at: ${data.createdOn}`,+ `updated_at: ${data.editedOn}`+ ];+ if (data.metadata.pinned) lines.push(`pinned: ${data.metadata.pinned}`);+ if (data.metadata.favorite) lines.push(`favorite: ${data.metadata.favorite}`);+ if (data.metadata.color) lines.push(`color: ${data.metadata.color}`);+ if (data.tags) lines.push(`tags: ${data.tags}`);+ return lines.join("\n");+}