diff --git a/packages/core/utils/templates/helper.js b/packages/core/utils/templates/helper.js deleted file mode 100644 index 459ee4d2b..000000000 --- a/packages/core/utils/templates/helper.js +++ /dev/null @@ -1,57 +0,0 @@ -/* -This file is part of the Notesnook project (https://notesnook.com/) - -Copyright (C) 2022 Streetwriters (Private) Limited - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -import { formatDate } from "../date"; - -function generateMetaTags(metadata, createMetaTag) { - let metaTags = []; - for (let key in metadata) { - let value = metadata[key]; - if (typeof value === "object" && !Array.isArray(value)) continue; - else if (Array.isArray(value)) value = value.join(", "); - - // we must have no new line characters - if (typeof value === "string") value = value.replace(/\r?\n|\r/g, ""); - - metaTags.push(createMetaTag(key, value)); - } - return metaTags; -} - -export function buildPage( - template, - createMetaTag, - { metadata, title, headline, content, createdOn, editedOn, tags } -) { - let page = template; - - if (createMetaTag) - page = page.replace( - /{{metaTags}}/g, - generateMetaTags(metadata, createMetaTag).join("\n") - ); - - page = page.replace(/{{title}}/g, title); - page = page.replace(/{{headline}}/g, headline); - page = page.replace(/{{content}}/g, content); - page = page.replace(/{{createdOn}}/g, formatDate(createdOn)); - page = page.replace(/{{editedOn}}/g, formatDate(editedOn)); - page = page.replace(/{{tags}}/g, tags); - return page; -} diff --git a/packages/core/utils/templates/html/builder.js b/packages/core/utils/templates/html/builder.js index 1636a0998..a3a5b6406 100644 --- a/packages/core/utils/templates/html/builder.js +++ b/packages/core/utils/templates/html/builder.js @@ -17,15 +17,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -import { buildPage } from "../helper"; import HTMLTemplate from "./template"; -function createMetaTag(name, content) { - return ``; -} - function buildHTML(templateData) { - return buildPage(HTMLTemplate, createMetaTag, templateData); + return HTMLTemplate(templateData); } export default { buildHTML }; diff --git a/packages/core/utils/templates/html/template.js b/packages/core/utils/templates/html/template.js index b7a9ca0e9..164a68d86 100644 --- a/packages/core/utils/templates/html/template.js +++ b/packages/core/utils/templates/html/template.js @@ -17,23 +17,23 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -const template = ` +const template = (data) => ` - {{title}} - Notesnook - - - + ${data.title} - Notesnook + + + ${data.tags ? `` : ""} -

{{title}}

- {{content}} +

${data.title}

+ ${data.content} `; diff --git a/packages/core/utils/templates/markdown/builder.js b/packages/core/utils/templates/markdown/builder.js index c62455169..d10888db0 100644 --- a/packages/core/utils/templates/markdown/builder.js +++ b/packages/core/utils/templates/markdown/builder.js @@ -17,16 +17,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -import { buildPage } from "../helper"; import MDTemplate from "./template"; -function createMetaTag(name, content) { - if (!content || content.length <= 0) return ""; - return `[nn-${name}]:- "${content}"`; -} - function buildMarkdown(templateData) { - return buildPage(MDTemplate, createMetaTag, templateData); + return MDTemplate(templateData); } export default { buildMarkdown }; diff --git a/packages/core/utils/templates/markdown/template.js b/packages/core/utils/templates/markdown/template.js index d56ff1843..ee40f75ab 100644 --- a/packages/core/utils/templates/markdown/template.js +++ b/packages/core/utils/templates/markdown/template.js @@ -17,10 +17,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -const template = `# {{title}} +const template = (data) => `# ${data.title} -{{content}} +${data.content} --- -_Tags: {{tags}}_`; +${data.tags ? `${data.tags}` : ""}`; export default template; diff --git a/packages/core/utils/templates/text/builder.js b/packages/core/utils/templates/text/builder.js index e31598870..e61ed30f6 100644 --- a/packages/core/utils/templates/text/builder.js +++ b/packages/core/utils/templates/text/builder.js @@ -17,11 +17,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -import { buildPage } from "../helper"; import TextTemplate from "./template"; function buildText(templateData) { - return buildPage(TextTemplate, undefined, templateData); + return TextTemplate(templateData); } export default { buildText }; diff --git a/packages/core/utils/templates/text/template.js b/packages/core/utils/templates/text/template.js index 0f09a23d5..7b4be4923 100644 --- a/packages/core/utils/templates/text/template.js +++ b/packages/core/utils/templates/text/template.js @@ -17,12 +17,12 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -const template = `{{title}} +const template = (data) => `${data.title} ---------- -{{content}} +${data.content} ---------- -Tags: {{tags}}`; +Tags: ${data.tags}`; export default template;