Skip to content

Commit 438d6fa

Browse files
author
Nathan Salter
committed
Map schema.org pending properties
1 parent 8c4e2c6 commit 438d6fa

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

scripts/build.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,28 @@ for (const asset of assets) {
9696
},
9797
}).getBody());
9898

99+
100+
const schemaOrgDataModel = (() => {
101+
// Note even though schema.org has migrated http://pending.schema.org/ to https://schema.org/
102+
// We still use https://pending.schema.org/ to simplify the tooling (as the modelling specification does not
103+
// allow for arbitrary pending terms to be used as-is, they must instead be added to a custom extension)
104+
const getPrefixReplacedId = (entity) => {
105+
if (entity['https://schema.org/isPartOf']
106+
&& entity['https://schema.org/isPartOf']['@id'] !== 'https://meta.schema.org') {
107+
return entity['@id'].replace(/^https:\/\/schema.org/, entity['https://schema.org/isPartOf']['@id']);
108+
}
109+
return entity['@id'];
110+
};
111+
112+
return schema['@graph'].map(entity => getPrefixReplacedId(entity));
113+
})();
114+
115+
99116
fs.writeFileSync(
100117
path.join(distPath, `${asset.name}.js`),
101118
`/* eslint-disable */
102119
// This is a generated file. Do not edit manually.
103-
module.exports = ${JSON.stringify(schema)};`,
120+
module.exports = ${JSON.stringify({ schema, ...{ '@graph': schemaOrgDataModel } })};`,
104121
() => {},
105122
);
106123
}

0 commit comments

Comments
 (0)