diff --git a/src/finalizing/utils/generate-doi-xml.js b/src/finalizing/utils/generate-doi-xml.js index 519048d..cf13699 100644 --- a/src/finalizing/utils/generate-doi-xml.js +++ b/src/finalizing/utils/generate-doi-xml.js @@ -27,7 +27,7 @@ const TYPE_MAPPINGS = { extension_fixes: { ai: 'svg', xlsx: 'csv' } }; -export function renderDoiXml(templateFile, metadata) { +export function renderDoiXml(templateFile, context, metadata) { const env = new Environment(undefined, { autoescape: false }); env.addFilter('fileExtension', (str) => { str = Array.isArray(str) ? str[0] : str; @@ -42,13 +42,13 @@ export function renderDoiXml(templateFile, metadata) { ); env.addFilter('year', (str) => String(str || new Date().getFullYear()).match(/\d\d\d\d/)[0]) const template = readFileSync(templateFile).toString(); - return env.renderString(template, { ...TYPE_MAPPINGS, ...metadata }); + return env.renderString(template, { ...TYPE_MAPPINGS, ...metadata, ...context.selectedDigitalObject }); } export function writeDoiXml(context, metadata) { const obj = context.selectedDigitalObject; const templateFile = resolve(context.processorHome, 'src/finalizing/templates/doi-xml.njk'); - const xmlString = renderDoiXml(templateFile, metadata); + const xmlString = renderDoiXml(templateFile, context, metadata); const doiXmlFile = resolve(context.deploymentHome, obj.doString, 'doi.xml'); writeFileSync(doiXmlFile, xmlString); } diff --git a/src/finalizing/utils/generate-index-html.js b/src/finalizing/utils/generate-index-html.js index 6964752..1ebdbc3 100644 --- a/src/finalizing/utils/generate-index-html.js +++ b/src/finalizing/utils/generate-index-html.js @@ -2,7 +2,7 @@ import { readFileSync, writeFileSync } from 'fs'; import nunjucks, { Environment } from 'nunjucks'; import { resolve } from 'path'; -export function renderIndexHtml(templateFile, metadata) { +export function renderIndexHtml(templateFile, context, metadata) { const env = new Environment(undefined, { autoescape: false }); env.addFilter('json', function (value) { if (value instanceof nunjucks.runtime.SafeString) { @@ -12,7 +12,7 @@ export function renderIndexHtml(templateFile, metadata) { return nunjucks.runtime.markSafe(jsonString) }) env.addGlobal("getStructuredData", function() { - return getStructuredData(metadata); + return getStructuredData(context, metadata); }); const template = readFileSync(templateFile).toString(); return env.renderString(template, metadata); @@ -21,13 +21,14 @@ export function renderIndexHtml(templateFile, metadata) { export function writeIndexHtml(context, metadata) { const obj = context.selectedDigitalObject; const templateFile = resolve(context.processorHome, 'src/finalizing/templates/index-html.njk'); - const htmlString = renderIndexHtml(templateFile, metadata); + const htmlString = renderIndexHtml(templateFile, context, metadata); const filePath = resolve(context.deploymentHome, obj.doString, 'index.html'); writeFileSync(filePath, htmlString); } -function getStructuredData(metadata) { - const { title, description, type, name, version, doi, hubmapId, license, citation, creators, funders } = metadata; +function getStructuredData(context, metadata) { + const { title, description, doi, hubmapId, license, citation, creators, funders } = metadata; + const { type, name, version } = context.selectedDigitalObject; return { "@context": "https://schema.org/", "@type": "Dataset", diff --git a/src/finalizing/utils/generate-readme-md.js b/src/finalizing/utils/generate-readme-md.js index 75e4bbd..df65ae4 100644 --- a/src/finalizing/utils/generate-readme-md.js +++ b/src/finalizing/utils/generate-readme-md.js @@ -7,7 +7,7 @@ const TYPE_MAPPINGS = { cite_model_mappings: { 'asct-b': 'Data Table', '2d-ftu': '2D Data', omap: 'OMAP Tables', 'ref-organ': '3D Data' } }; -export function renderReadmeMd(templateFile, metadata) { +export function renderReadmeMd(templateFile, context, metadata) { const env = new Environment(undefined, { autoescape: false }); env.addFilter('authorList', (list) => { @@ -23,13 +23,13 @@ export function renderReadmeMd(templateFile, metadata) { }).join(' '); }) ?? ''; const template = readFileSync(templateFile).toString(); - return env.renderString(template, { ...TYPE_MAPPINGS, ...metadata }); + return env.renderString(template, { ...TYPE_MAPPINGS, ...metadata, ...context.selectedDigitalObject }); } export function writeReadmeMd(context, metadata) { const obj = context.selectedDigitalObject; const templateFile = resolve(context.processorHome, 'src/finalizing/templates/readme-md.njk'); - const mdString = renderReadmeMd(templateFile, metadata); + const mdString = renderReadmeMd(templateFile, context, metadata); const mdFile = resolve(context.deploymentHome, obj.doString, 'README.md'); writeFileSync(mdFile, mdString); }