@unhead/schema-org
Version:
Unhead Schema.org for Simple and Automated Google Rich Results
55 lines (52 loc) • 1.59 kB
JavaScript
import { withBase } from 'ufo';
import { d as defineSchemaOrgResolver, a9 as IdentityId, a6 as setIfEmpty, a7 as idReference, ab as resolvableDateToDate, e as resolveRelation } from '../shared/schema-org.Cp6bpwL2.mjs';
import 'unhead/plugins';
import 'unhead/utils';
const bookEditionResolver = defineSchemaOrgResolver({
defaults: {
"@type": "Book"
},
inheritMeta: [
"inLanguage"
],
resolve(node, ctx) {
if (node.bookFormat)
node.bookFormat = withBase(node.bookFormat, "https://schema.org/");
if (node.datePublished)
node.datePublished = resolvableDateToDate(node.datePublished);
node.author = resolveRelation(node.author, ctx);
return node;
},
resolveRootNode(node, { find }) {
const identity = find(IdentityId);
if (identity)
setIfEmpty(node, "provider", idReference(identity));
return node;
}
});
const PrimaryBookId = "#book";
const bookResolver = defineSchemaOrgResolver({
defaults: {
"@type": "Book"
},
inheritMeta: [
"description",
"url",
{ meta: "title", key: "name" }
],
idPrefix: ["url", PrimaryBookId],
resolve(node, ctx) {
node.workExample = resolveRelation(node.workExample, ctx, bookEditionResolver);
node.author = resolveRelation(node.author, ctx);
if (node.url)
withBase(node.url, ctx.meta.host);
return node;
},
resolveRootNode(node, { find }) {
const identity = find(IdentityId);
if (identity)
setIfEmpty(node, "author", idReference(identity));
return node;
}
});
export { PrimaryBookId, bookEditionResolver, bookResolver };