diff --git a/scripts/build.js b/scripts/build.js index 8cc67f78..d9bcca3a 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -96,11 +96,28 @@ for (const asset of assets) { }, }).getBody()); + const schemaOrgDataModel = (() => { + // Note even though schema.org has migrated http://pending.schema.org/ to https://schema.org/ + // We still use https://pending.schema.org/ to simplify the tooling (as the modelling specification does not + // allow for arbitrary pending terms to be used as-is, they must instead be added to a custom extension) + const getPrefixReplaced = (entity) => { + if (entity['schema:isPartOf'] + && entity['schema:isPartOf']['@id'] === 'https://pending.schema.org') { + + entity['@id'] = entity['@id'].replace(/^schema:/, 'pending:'); + return entity; + } + return entity; + }; + + return schema['@graph'].map(entity => getPrefixReplaced(entity)); + })(); + fs.writeFileSync( path.join(distPath, `${asset.name}.js`), `/* eslint-disable */ // This is a generated file. Do not edit manually. - module.exports = ${JSON.stringify(schema)};`, + module.exports = ${JSON.stringify({ schema, ...{ '@graph': schemaOrgDataModel } })};`, () => {}, ); }