${raw(updatedMarkdown)}
${raw(pageScript)}
${newMetadata.length ? raw(updateMetadata(newMetadata)) : ""}
`;
};
// H E L P E R S
function createMetaTags(metaObject) {
/**
NOTE:
For Markdown files, the custom yaml should look like this:
meta:
- description: Description goes here
This does not currently work with parameters like "og:image"
// https://github.com/lbryio/lbry.tech/issues/30
*/
let html = "";
for (const metaProperty in metaObject) {
html += `document.getElementsByTagName("meta")["${metaProperty}"].content = "${metaObject[metaProperty]}";\n`;
}
return html;
}
function partialFinder(markdownBody) {
const regexToFindPartials = /<\w+\/>/g;
const partials = markdownBody.match(regexToFindPartials);
if (!partials) return markdownBody;
for (const partial of partials) {
const filename = decamelize(partial, "-").replace("<", "").replace("/>", "");
const fileExistsTest = exists(`./app/views/partials/${filename}.js`); // `local` results in error if used here and file !exist
if (fileExistsTest) {
const partialFunction = local(`/app/views/partials/${filename}.js`);
if (filename === "ecosystem" || filename === "feature-links") {
const neatPartial = new partialFunction;
markdownBody = markdownBody.replace(partial, neatPartial.render());
}
else markdownBody = markdownBody.replace(partial, partialFunction);
}
}
return markdownBody;
}
function updateMetadata(metadataDetails) {
const generatedMetadata = [];
for (const metadataDetail of metadataDetails) {
generatedMetadata.push(createMetaTags(metadataDetail));
}
return html`
`;
}