mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-01 19:49:54 +02:00
core: fix md with frontmatter export
This commit is contained in:
@@ -266,7 +266,6 @@ export class Notes implements ICollection {
|
||||
);
|
||||
|
||||
const content = getContentFromData(type, data);
|
||||
|
||||
const contentString =
|
||||
rawContent ||
|
||||
(format === "html"
|
||||
@@ -275,10 +274,19 @@ export class Notes implements ICollection {
|
||||
? content.toMD()
|
||||
: content.toTXT());
|
||||
|
||||
const tags = (await this.db.relations.to(note, "tag").resolve()).map(
|
||||
(tag) => tag.title
|
||||
);
|
||||
const color = (await this.db.relations.to(note, "color").resolve(1)).at(
|
||||
0
|
||||
)?.title;
|
||||
|
||||
return options?.disableTemplate
|
||||
? contentString
|
||||
: buildFromTemplate(format, {
|
||||
...note,
|
||||
tags,
|
||||
color,
|
||||
content: contentString
|
||||
});
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ export interface IStorage {
|
||||
readMulti<T>(keys: string[]): Promise<[string, T][]>;
|
||||
read<T>(key: string, isArray?: boolean): Promise<T | undefined>;
|
||||
remove(key: string): Promise<void>;
|
||||
removeMulti(keys: string[]): Promise<void>;
|
||||
clear(): Promise<void>;
|
||||
getAllKeys(): Promise<string[]>;
|
||||
encrypt(key: SerializedKey, plainText: string): Promise<Cipher<"base64">>;
|
||||
|
||||
@@ -81,7 +81,7 @@ class DatabaseLogWriter {
|
||||
async rotate() {
|
||||
const logKeys = (await this.storage.getAllKeys()).sort();
|
||||
const keysToRemove = [];
|
||||
for (let key of logKeys) {
|
||||
for (const key of logKeys) {
|
||||
const keyParts = key.split(":");
|
||||
if (keyParts.length === 1 || parseInt(keyParts[1]) < Date.now() - WEEK) {
|
||||
keysToRemove.push(key);
|
||||
|
||||
@@ -38,7 +38,7 @@ export function template(data: TemplateData) {
|
||||
data.favorite ? `<meta name="favorite" content="${data.favorite}" />` : ""
|
||||
}
|
||||
${data.color ? `<meta name="color" content="${data.color}" />` : ""}
|
||||
${data.tags ? `<meta name="tags" content="${data.tags}" />` : ""}
|
||||
${data.tags ? `<meta name="tags" content="${data.tags.join(", ")}" />` : ""}
|
||||
<link rel="stylesheet" href="https://app.notesnook.com/assets/editor-styles.css?d=${
|
||||
process.env.NN_BUILD_TIMESTAMP || "1690887574068"
|
||||
}">
|
||||
|
||||
@@ -22,7 +22,11 @@ import { buildHTML } from "./html";
|
||||
import { buildMarkdown, templateWithFrontmatter } from "./md";
|
||||
import { buildText } from "./text";
|
||||
|
||||
export type TemplateData = Note & { content: string };
|
||||
export type TemplateData = Omit<Note, "tags" | "color"> & {
|
||||
tags?: string[];
|
||||
color?: string;
|
||||
content: string;
|
||||
};
|
||||
|
||||
export async function buildFromTemplate(
|
||||
format: "md" | "txt" | "html" | "md-frontmatter",
|
||||
|
||||
@@ -41,6 +41,6 @@ function buildFrontmatter(data: TemplateData) {
|
||||
if (data.pinned) lines.push(`pinned: ${data.pinned}`);
|
||||
if (data.favorite) lines.push(`favorite: ${data.favorite}`);
|
||||
if (data.color) lines.push(`color: ${data.color}`);
|
||||
if (data.tags) lines.push(`tags: ${data.tags}`);
|
||||
if (data.tags) lines.push(`tags: ${data.tags.join(", ")}`);
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user