mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-01 19:49:54 +02:00
core: update export templates
This commit is contained in:
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -17,15 +17,10 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { buildPage } from "../helper";
|
||||
import HTMLTemplate from "./template";
|
||||
|
||||
function createMetaTag(name, content) {
|
||||
return `<meta name="nn-${name}" content="${content}">`;
|
||||
}
|
||||
|
||||
function buildHTML(templateData) {
|
||||
return buildPage(HTMLTemplate, createMetaTag, templateData);
|
||||
return HTMLTemplate(templateData);
|
||||
}
|
||||
|
||||
export default { buildHTML };
|
||||
|
||||
@@ -17,23 +17,23 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
const template = `<!DOCTYPE html>
|
||||
const template = (data) => `<!DOCTYPE html>
|
||||
<html lang="en-US">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
|
||||
<meta
|
||||
name="description"
|
||||
content="{{headline}}"
|
||||
content="${data.headline}"
|
||||
/>
|
||||
<title>{{title}} - Notesnook</title>
|
||||
<meta name="created-on" content="{{createdOn}}" />
|
||||
<meta name="last-edited-on" content="{{editedOn}}" />
|
||||
<meta name="tags" content="{{tags}}" />
|
||||
<title>${data.title} - Notesnook</title>
|
||||
<meta name="created-on" content="${data.createdOn}" />
|
||||
<meta name="last-edited-on" content="${data.editedOn}" />
|
||||
${data.tags ? `<meta name="tags" content="${data.tags}" />` : ""}
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{title}}</h1>
|
||||
{{content}}
|
||||
<h1>${data.title}</h1>
|
||||
${data.content}
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
@@ -17,16 +17,10 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 };
|
||||
|
||||
@@ -17,10 +17,10 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
const template = `# {{title}}
|
||||
const template = (data) => `# ${data.title}
|
||||
|
||||
{{content}}
|
||||
${data.content}
|
||||
---
|
||||
|
||||
_Tags: {{tags}}_`;
|
||||
${data.tags ? `${data.tags}` : ""}`;
|
||||
export default template;
|
||||
|
||||
@@ -17,11 +17,10 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { buildPage } from "../helper";
|
||||
import TextTemplate from "./template";
|
||||
|
||||
function buildText(templateData) {
|
||||
return buildPage(TextTemplate, undefined, templateData);
|
||||
return TextTemplate(templateData);
|
||||
}
|
||||
|
||||
export default { buildText };
|
||||
|
||||
@@ -17,12 +17,12 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
const template = `{{title}}
|
||||
const template = (data) => `${data.title}
|
||||
----------
|
||||
|
||||
{{content}}
|
||||
${data.content}
|
||||
|
||||
----------
|
||||
Tags: {{tags}}`;
|
||||
Tags: ${data.tags}`;
|
||||
|
||||
export default template;
|
||||
|
||||
Reference in New Issue
Block a user