Skip to content

Commit

Permalink
Updated finalize scripts to handle title, name, version
Browse files Browse the repository at this point in the history
  • Loading branch information
bherr2 committed Nov 29, 2023
1 parent 1366647 commit cfa5a96
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/finalizing/utils/generate-doi-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
11 changes: 6 additions & 5 deletions src/finalizing/utils/generate-index-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/finalizing/utils/generate-readme-md.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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);
}

0 comments on commit cfa5a96

Please sign in to comment.