@unhead/schema-org 0.6.0 → 1.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SchemaOrgUnheadPlugin-dd5249a4.d.ts +1525 -0
- package/dist/index.cjs +58 -1992
- package/dist/index.d.ts +4 -1525
- package/dist/index.mjs +5 -1939
- package/dist/shared/schema-org.02b3dc98.mjs +1970 -0
- package/dist/shared/schema-org.96234618.cjs +2025 -0
- package/dist/vue.cjs +367 -0
- package/dist/vue.d.ts +87 -0
- package/dist/vue.mjs +303 -0
- package/package.json +22 -10
package/dist/index.mjs
CHANGED
|
@@ -1,1941 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
export { H as HowToId, P as PrimaryArticleId, k as PrimaryBookId, m as PrimaryBreadcrumbId, s as PrimaryEventId, V as PrimaryWebPageId, Y as PrimaryWebSiteId, L as ProductId, R as RecipeId, $ as SchemaOrgUnheadPlugin, K as addressResolver, g as aggregateOfferResolver, h as aggregateRatingResolver, i as articleResolver, j as bookEditionResolver, l as bookResolver, o as breadcrumbResolver, p as commentResolver, q as courseResolver, c as createSchemaOrgGraph, a as dedupeNodes, d as defineSchemaOrgResolver, t as eventResolver, w as howToResolver, y as howToStepDirectionResolver, x as howToStepResolver, A as imageResolver, z as itemListResolver, B as jobPostingResolver, C as listItemResolver, D as localBusinessResolver, E as movieResolver, n as normaliseNodes, F as offerResolver, G as openingHoursResolver, I as organizationResolver, J as personResolver, u as placeResolver, M as productResolver, N as questionResolver, O as ratingResolver, X as readActionResolver, Q as recipeResolver, r as resolveMeta, b as resolveNode, e as resolveNodeId, f as resolveRelation, T as reviewResolver, _ as searchActionResolver, S as softwareAppResolver, U as videoResolver, v as virtualLocationResolver, W as webPageResolver, Z as webSiteResolver } from './shared/schema-org.02b3dc98.mjs';
|
|
2
2
|
import { useHead } from 'unhead';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return schema;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function idReference(node) {
|
|
9
|
-
return {
|
|
10
|
-
"@id": typeof node !== "string" ? node["@id"] : node
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
function resolvableDateToDate(val) {
|
|
14
|
-
try {
|
|
15
|
-
const date = val instanceof Date ? val : new Date(Date.parse(val));
|
|
16
|
-
return `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`;
|
|
17
|
-
} catch (e) {
|
|
18
|
-
}
|
|
19
|
-
return typeof val === "string" ? val : val.toString();
|
|
20
|
-
}
|
|
21
|
-
function resolvableDateToIso(val) {
|
|
22
|
-
if (!val)
|
|
23
|
-
return val;
|
|
24
|
-
try {
|
|
25
|
-
if (val instanceof Date)
|
|
26
|
-
return val.toISOString();
|
|
27
|
-
else
|
|
28
|
-
return new Date(Date.parse(val)).toISOString();
|
|
29
|
-
} catch (e) {
|
|
30
|
-
}
|
|
31
|
-
return typeof val === "string" ? val : val.toString();
|
|
32
|
-
}
|
|
33
|
-
const IdentityId = "#identity";
|
|
34
|
-
function setIfEmpty(node, field, value) {
|
|
35
|
-
if (!node?.[field] && value)
|
|
36
|
-
node[field] = value;
|
|
37
|
-
}
|
|
38
|
-
function asArray(input) {
|
|
39
|
-
return Array.isArray(input) ? input : [input];
|
|
40
|
-
}
|
|
41
|
-
function dedupeMerge(node, field, value) {
|
|
42
|
-
const dedupeMerge2 = [];
|
|
43
|
-
const input = asArray(node[field]);
|
|
44
|
-
dedupeMerge2.push(...input);
|
|
45
|
-
const data = new Set(dedupeMerge2);
|
|
46
|
-
data.add(value);
|
|
47
|
-
node[field] = [...data.values()].filter(Boolean);
|
|
48
|
-
}
|
|
49
|
-
function prefixId(url, id) {
|
|
50
|
-
if (hasProtocol(id))
|
|
51
|
-
return url;
|
|
52
|
-
if (!id.startsWith("#"))
|
|
53
|
-
id = `#${id}`;
|
|
54
|
-
return joinURL(url, id);
|
|
55
|
-
}
|
|
56
|
-
function trimLength(val, length) {
|
|
57
|
-
if (!val)
|
|
58
|
-
return val;
|
|
59
|
-
if (val.length > length) {
|
|
60
|
-
const trimmedString = val.substring(0, length);
|
|
61
|
-
return trimmedString.substring(0, Math.min(trimmedString.length, trimmedString.lastIndexOf(" ")));
|
|
62
|
-
}
|
|
63
|
-
return val;
|
|
64
|
-
}
|
|
65
|
-
function resolveDefaultType(node, defaultType) {
|
|
66
|
-
const val = node["@type"];
|
|
67
|
-
if (val === defaultType)
|
|
68
|
-
return;
|
|
69
|
-
const types = /* @__PURE__ */ new Set([
|
|
70
|
-
...asArray(defaultType),
|
|
71
|
-
...asArray(val)
|
|
72
|
-
]);
|
|
73
|
-
node["@type"] = types.size === 1 ? val : [...types.values()];
|
|
74
|
-
}
|
|
75
|
-
function resolveWithBase(base, urlOrPath) {
|
|
76
|
-
if (!urlOrPath || hasProtocol(urlOrPath) || !urlOrPath.startsWith("/") && !urlOrPath.startsWith("#"))
|
|
77
|
-
return urlOrPath;
|
|
78
|
-
return withBase(urlOrPath, base);
|
|
79
|
-
}
|
|
80
|
-
function resolveAsGraphKey(key) {
|
|
81
|
-
if (!key)
|
|
82
|
-
return key;
|
|
83
|
-
return key.substring(key.lastIndexOf("#"));
|
|
84
|
-
}
|
|
85
|
-
function stripEmptyProperties(obj) {
|
|
86
|
-
Object.keys(obj).forEach((k) => {
|
|
87
|
-
if (obj[k] && typeof obj[k] === "object") {
|
|
88
|
-
if (obj[k].__v_isReadonly || obj[k].__v_isRef)
|
|
89
|
-
return;
|
|
90
|
-
stripEmptyProperties(obj[k]);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
if (obj[k] === "" || obj[k] === null || typeof obj[k] === "undefined")
|
|
94
|
-
delete obj[k];
|
|
95
|
-
});
|
|
96
|
-
return obj;
|
|
97
|
-
}
|
|
98
|
-
function hashCode(s) {
|
|
99
|
-
let h = 9;
|
|
100
|
-
for (let i = 0; i < s.length; )
|
|
101
|
-
h = Math.imul(h ^ s.charCodeAt(i++), 9 ** 9);
|
|
102
|
-
return ((h ^ h >>> 9) + 65536).toString(16).substring(1, 8).toLowerCase();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const offerResolver = defineSchemaOrgResolver({
|
|
106
|
-
cast(node) {
|
|
107
|
-
if (typeof node === "number" || typeof node === "string") {
|
|
108
|
-
return {
|
|
109
|
-
price: node
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
return node;
|
|
113
|
-
},
|
|
114
|
-
defaults: {
|
|
115
|
-
"@type": "Offer",
|
|
116
|
-
"availability": "InStock"
|
|
117
|
-
},
|
|
118
|
-
resolve(node, ctx) {
|
|
119
|
-
setIfEmpty(node, "priceCurrency", ctx.meta.currency);
|
|
120
|
-
setIfEmpty(node, "priceValidUntil", new Date(Date.UTC((/* @__PURE__ */ new Date()).getFullYear() + 1, 12, -1, 0, 0, 0)));
|
|
121
|
-
if (node.url)
|
|
122
|
-
resolveWithBase(ctx.meta.host, node.url);
|
|
123
|
-
if (node.availability)
|
|
124
|
-
node.availability = withBase(node.availability, "https://schema.org/");
|
|
125
|
-
if (node.priceValidUntil)
|
|
126
|
-
node.priceValidUntil = resolvableDateToIso(node.priceValidUntil);
|
|
127
|
-
return node;
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
const aggregateOfferResolver = defineSchemaOrgResolver({
|
|
132
|
-
defaults: {
|
|
133
|
-
"@type": "AggregateOffer"
|
|
134
|
-
},
|
|
135
|
-
inheritMeta: [
|
|
136
|
-
{ meta: "currency", key: "priceCurrency" }
|
|
137
|
-
],
|
|
138
|
-
resolve(node, ctx) {
|
|
139
|
-
node.offers = resolveRelation(node.offers, ctx, offerResolver);
|
|
140
|
-
if (node.offers)
|
|
141
|
-
setIfEmpty(node, "offerCount", asArray(node.offers).length);
|
|
142
|
-
return node;
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
const aggregateRatingResolver = defineSchemaOrgResolver({
|
|
147
|
-
defaults: {
|
|
148
|
-
"@type": "AggregateRating"
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
const searchActionResolver = defineSchemaOrgResolver({
|
|
153
|
-
defaults: {
|
|
154
|
-
"@type": "SearchAction",
|
|
155
|
-
"target": {
|
|
156
|
-
"@type": "EntryPoint"
|
|
157
|
-
},
|
|
158
|
-
"query-input": {
|
|
159
|
-
"@type": "PropertyValueSpecification",
|
|
160
|
-
"valueRequired": true,
|
|
161
|
-
"valueName": "search_term_string"
|
|
162
|
-
}
|
|
163
|
-
},
|
|
164
|
-
resolve(node, ctx) {
|
|
165
|
-
if (typeof node.target === "string") {
|
|
166
|
-
node.target = {
|
|
167
|
-
"@type": "EntryPoint",
|
|
168
|
-
"urlTemplate": resolveWithBase(ctx.meta.host, node.target)
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
return node;
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
const PrimaryWebSiteId = "#website";
|
|
176
|
-
const webSiteResolver = defineSchemaOrgResolver({
|
|
177
|
-
defaults: {
|
|
178
|
-
"@type": "WebSite"
|
|
179
|
-
},
|
|
180
|
-
inheritMeta: [
|
|
181
|
-
"inLanguage",
|
|
182
|
-
{ meta: "host", key: "url" }
|
|
183
|
-
],
|
|
184
|
-
idPrefix: ["host", PrimaryWebSiteId],
|
|
185
|
-
resolve(node, ctx) {
|
|
186
|
-
node.potentialAction = resolveRelation(node.potentialAction, ctx, searchActionResolver, {
|
|
187
|
-
array: true
|
|
188
|
-
});
|
|
189
|
-
node.publisher = resolveRelation(node.publisher, ctx);
|
|
190
|
-
return node;
|
|
191
|
-
},
|
|
192
|
-
resolveRootNode(node, { find }) {
|
|
193
|
-
if (resolveAsGraphKey(node["@id"]) === PrimaryWebSiteId) {
|
|
194
|
-
const identity = find(IdentityId);
|
|
195
|
-
if (identity)
|
|
196
|
-
setIfEmpty(node, "publisher", idReference(identity));
|
|
197
|
-
const webPage = find(PrimaryWebPageId);
|
|
198
|
-
if (webPage)
|
|
199
|
-
setIfEmpty(webPage, "isPartOf", idReference(node));
|
|
200
|
-
}
|
|
201
|
-
return node;
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
const listItemResolver = defineSchemaOrgResolver({
|
|
206
|
-
cast(node) {
|
|
207
|
-
if (typeof node === "string") {
|
|
208
|
-
node = {
|
|
209
|
-
name: node
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
return node;
|
|
213
|
-
},
|
|
214
|
-
defaults: {
|
|
215
|
-
"@type": "ListItem"
|
|
216
|
-
},
|
|
217
|
-
resolve(node, ctx) {
|
|
218
|
-
if (typeof node.item === "string")
|
|
219
|
-
node.item = resolveWithBase(ctx.meta.host, node.item);
|
|
220
|
-
else if (typeof node.item === "object")
|
|
221
|
-
node.item = resolveRelation(node.item, ctx);
|
|
222
|
-
return node;
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
const PrimaryBreadcrumbId = "#breadcrumb";
|
|
227
|
-
const breadcrumbResolver = defineSchemaOrgResolver({
|
|
228
|
-
defaults: {
|
|
229
|
-
"@type": "BreadcrumbList"
|
|
230
|
-
},
|
|
231
|
-
idPrefix: ["url", PrimaryBreadcrumbId],
|
|
232
|
-
resolve(breadcrumb, ctx) {
|
|
233
|
-
if (breadcrumb.itemListElement) {
|
|
234
|
-
let index = 1;
|
|
235
|
-
breadcrumb.itemListElement = resolveRelation(breadcrumb.itemListElement, ctx, listItemResolver, {
|
|
236
|
-
array: true,
|
|
237
|
-
afterResolve(node) {
|
|
238
|
-
setIfEmpty(node, "position", index++);
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
return breadcrumb;
|
|
243
|
-
},
|
|
244
|
-
resolveRootNode(node, { find }) {
|
|
245
|
-
const webPage = find(PrimaryWebPageId);
|
|
246
|
-
if (webPage)
|
|
247
|
-
setIfEmpty(webPage, "breadcrumb", idReference(node));
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
const imageResolver = defineSchemaOrgResolver({
|
|
252
|
-
alias: "image",
|
|
253
|
-
cast(input) {
|
|
254
|
-
if (typeof input === "string") {
|
|
255
|
-
input = {
|
|
256
|
-
url: input
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
return input;
|
|
260
|
-
},
|
|
261
|
-
defaults: {
|
|
262
|
-
"@type": "ImageObject"
|
|
263
|
-
},
|
|
264
|
-
inheritMeta: [
|
|
265
|
-
// @todo possibly only do if there's a caption
|
|
266
|
-
"inLanguage"
|
|
267
|
-
],
|
|
268
|
-
idPrefix: "host",
|
|
269
|
-
resolve(image, { meta }) {
|
|
270
|
-
image.url = resolveWithBase(meta.host, image.url);
|
|
271
|
-
setIfEmpty(image, "contentUrl", image.url);
|
|
272
|
-
if (image.height && !image.width)
|
|
273
|
-
delete image.height;
|
|
274
|
-
if (image.width && !image.height)
|
|
275
|
-
delete image.width;
|
|
276
|
-
return image;
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
const addressResolver = defineSchemaOrgResolver({
|
|
281
|
-
defaults: {
|
|
282
|
-
"@type": "PostalAddress"
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
const organizationResolver = defineSchemaOrgResolver({
|
|
287
|
-
defaults: {
|
|
288
|
-
"@type": "Organization"
|
|
289
|
-
},
|
|
290
|
-
idPrefix: ["host", IdentityId],
|
|
291
|
-
inheritMeta: [
|
|
292
|
-
{ meta: "host", key: "url" }
|
|
293
|
-
],
|
|
294
|
-
resolve(node, ctx) {
|
|
295
|
-
resolveDefaultType(node, "Organization");
|
|
296
|
-
node.address = resolveRelation(node.address, ctx, addressResolver);
|
|
297
|
-
return node;
|
|
298
|
-
},
|
|
299
|
-
resolveRootNode(node, ctx) {
|
|
300
|
-
const isIdentity = resolveAsGraphKey(node["@id"]) === IdentityId;
|
|
301
|
-
const webPage = ctx.find(PrimaryWebPageId);
|
|
302
|
-
if (node.logo) {
|
|
303
|
-
node.logo = resolveRelation(node.logo, ctx, imageResolver, {
|
|
304
|
-
root: true,
|
|
305
|
-
afterResolve(logo) {
|
|
306
|
-
if (isIdentity)
|
|
307
|
-
logo["@id"] = prefixId(ctx.meta.host, "#logo");
|
|
308
|
-
setIfEmpty(logo, "caption", node.name);
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
if (webPage)
|
|
312
|
-
setIfEmpty(webPage, "primaryImageOfPage", idReference(node.logo));
|
|
313
|
-
}
|
|
314
|
-
if (isIdentity && webPage)
|
|
315
|
-
setIfEmpty(webPage, "about", idReference(node));
|
|
316
|
-
const webSite = ctx.find(PrimaryWebSiteId);
|
|
317
|
-
if (webSite)
|
|
318
|
-
setIfEmpty(webSite, "publisher", idReference(node));
|
|
319
|
-
}
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
const personResolver = defineSchemaOrgResolver({
|
|
323
|
-
cast(node) {
|
|
324
|
-
if (typeof node === "string") {
|
|
325
|
-
return {
|
|
326
|
-
name: node
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
return node;
|
|
330
|
-
},
|
|
331
|
-
defaults: {
|
|
332
|
-
"@type": "Person"
|
|
333
|
-
},
|
|
334
|
-
idPrefix: ["host", IdentityId],
|
|
335
|
-
resolveRootNode(node, { find, meta }) {
|
|
336
|
-
if (resolveAsGraphKey(node["@id"]) === IdentityId) {
|
|
337
|
-
setIfEmpty(node, "url", meta.host);
|
|
338
|
-
const webPage = find(PrimaryWebPageId);
|
|
339
|
-
if (webPage)
|
|
340
|
-
setIfEmpty(webPage, "about", idReference(node));
|
|
341
|
-
const webSite = find(PrimaryWebSiteId);
|
|
342
|
-
if (webSite)
|
|
343
|
-
setIfEmpty(webSite, "publisher", idReference(node));
|
|
344
|
-
}
|
|
345
|
-
const article = find(PrimaryArticleId);
|
|
346
|
-
if (article)
|
|
347
|
-
setIfEmpty(article, "author", idReference(node));
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
const readActionResolver = defineSchemaOrgResolver({
|
|
352
|
-
defaults: {
|
|
353
|
-
"@type": "ReadAction"
|
|
354
|
-
},
|
|
355
|
-
resolve(node, ctx) {
|
|
356
|
-
if (!node.target.includes(ctx.meta.url))
|
|
357
|
-
node.target.unshift(ctx.meta.url);
|
|
358
|
-
return node;
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
const PrimaryWebPageId = "#webpage";
|
|
363
|
-
const webPageResolver = defineSchemaOrgResolver({
|
|
364
|
-
defaults({ meta }) {
|
|
365
|
-
const endPath = withoutTrailingSlash(meta.url.substring(meta.url.lastIndexOf("/") + 1));
|
|
366
|
-
let type = "WebPage";
|
|
367
|
-
switch (endPath) {
|
|
368
|
-
case "about":
|
|
369
|
-
case "about-us":
|
|
370
|
-
type = "AboutPage";
|
|
371
|
-
break;
|
|
372
|
-
case "search":
|
|
373
|
-
type = "SearchResultsPage";
|
|
374
|
-
break;
|
|
375
|
-
case "checkout":
|
|
376
|
-
type = "CheckoutPage";
|
|
377
|
-
break;
|
|
378
|
-
case "contact":
|
|
379
|
-
case "get-in-touch":
|
|
380
|
-
case "contact-us":
|
|
381
|
-
type = "ContactPage";
|
|
382
|
-
break;
|
|
383
|
-
case "faq":
|
|
384
|
-
type = "FAQPage";
|
|
385
|
-
break;
|
|
386
|
-
}
|
|
387
|
-
const defaults = {
|
|
388
|
-
"@type": type
|
|
389
|
-
};
|
|
390
|
-
return defaults;
|
|
391
|
-
},
|
|
392
|
-
idPrefix: ["url", PrimaryWebPageId],
|
|
393
|
-
inheritMeta: [
|
|
394
|
-
{ meta: "title", key: "name" },
|
|
395
|
-
"description",
|
|
396
|
-
"datePublished",
|
|
397
|
-
"dateModified",
|
|
398
|
-
"url"
|
|
399
|
-
],
|
|
400
|
-
resolve(node, ctx) {
|
|
401
|
-
node.dateModified = resolvableDateToIso(node.dateModified);
|
|
402
|
-
node.datePublished = resolvableDateToIso(node.datePublished);
|
|
403
|
-
resolveDefaultType(node, "WebPage");
|
|
404
|
-
node.about = resolveRelation(node.about, ctx, organizationResolver);
|
|
405
|
-
node.breadcrumb = resolveRelation(node.breadcrumb, ctx, breadcrumbResolver);
|
|
406
|
-
node.author = resolveRelation(node.author, ctx, personResolver);
|
|
407
|
-
node.primaryImageOfPage = resolveRelation(node.primaryImageOfPage, ctx, imageResolver);
|
|
408
|
-
node.potentialAction = resolveRelation(node.potentialAction, ctx, readActionResolver);
|
|
409
|
-
if (node["@type"] === "WebPage") {
|
|
410
|
-
setIfEmpty(node, "potentialAction", [
|
|
411
|
-
{
|
|
412
|
-
"@type": "ReadAction",
|
|
413
|
-
"target": [ctx.meta.url]
|
|
414
|
-
}
|
|
415
|
-
]);
|
|
416
|
-
}
|
|
417
|
-
return node;
|
|
418
|
-
},
|
|
419
|
-
resolveRootNode(webPage, { find, meta }) {
|
|
420
|
-
const identity = find(IdentityId);
|
|
421
|
-
const webSite = find(PrimaryWebSiteId);
|
|
422
|
-
const logo = find("#logo");
|
|
423
|
-
if (identity && meta.url === meta.host)
|
|
424
|
-
setIfEmpty(webPage, "about", idReference(identity));
|
|
425
|
-
if (logo)
|
|
426
|
-
setIfEmpty(webPage, "primaryImageOfPage", idReference(logo));
|
|
427
|
-
if (webSite)
|
|
428
|
-
setIfEmpty(webPage, "isPartOf", idReference(webSite));
|
|
429
|
-
const breadcrumb = find(PrimaryBreadcrumbId);
|
|
430
|
-
if (breadcrumb)
|
|
431
|
-
setIfEmpty(webPage, "breadcrumb", idReference(breadcrumb));
|
|
432
|
-
return webPage;
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
|
|
436
|
-
const PrimaryArticleId = "#article";
|
|
437
|
-
const articleResolver = defineSchemaOrgResolver({
|
|
438
|
-
defaults: {
|
|
439
|
-
"@type": "Article"
|
|
440
|
-
},
|
|
441
|
-
inheritMeta: [
|
|
442
|
-
"inLanguage",
|
|
443
|
-
"description",
|
|
444
|
-
"image",
|
|
445
|
-
"dateModified",
|
|
446
|
-
"datePublished",
|
|
447
|
-
{ meta: "title", key: "headline" }
|
|
448
|
-
],
|
|
449
|
-
idPrefix: ["url", PrimaryArticleId],
|
|
450
|
-
resolve(node, ctx) {
|
|
451
|
-
node.author = resolveRelation(node.author, ctx, personResolver, {
|
|
452
|
-
root: true
|
|
453
|
-
});
|
|
454
|
-
node.publisher = resolveRelation(node.publisher, ctx);
|
|
455
|
-
node.dateModified = resolvableDateToIso(node.dateModified);
|
|
456
|
-
node.datePublished = resolvableDateToIso(node.datePublished);
|
|
457
|
-
resolveDefaultType(node, "Article");
|
|
458
|
-
node.headline = trimLength(node.headline, 110);
|
|
459
|
-
return node;
|
|
460
|
-
},
|
|
461
|
-
resolveRootNode(node, { find, meta }) {
|
|
462
|
-
const webPage = find(PrimaryWebPageId);
|
|
463
|
-
const identity = find(IdentityId);
|
|
464
|
-
if (node.image && !node.thumbnailUrl) {
|
|
465
|
-
const firstImage = asArray(node.image)[0];
|
|
466
|
-
if (typeof firstImage === "string")
|
|
467
|
-
setIfEmpty(node, "thumbnailUrl", resolveWithBase(meta.host, firstImage));
|
|
468
|
-
else if (firstImage?.["@id"])
|
|
469
|
-
setIfEmpty(node, "thumbnailUrl", find(firstImage["@id"])?.url);
|
|
470
|
-
}
|
|
471
|
-
if (identity) {
|
|
472
|
-
setIfEmpty(node, "publisher", idReference(identity));
|
|
473
|
-
setIfEmpty(node, "author", idReference(identity));
|
|
474
|
-
}
|
|
475
|
-
if (webPage) {
|
|
476
|
-
setIfEmpty(node, "isPartOf", idReference(webPage));
|
|
477
|
-
setIfEmpty(node, "mainEntityOfPage", idReference(webPage));
|
|
478
|
-
setIfEmpty(webPage, "potentialAction", [
|
|
479
|
-
{
|
|
480
|
-
"@type": "ReadAction",
|
|
481
|
-
"target": [meta.url]
|
|
482
|
-
}
|
|
483
|
-
]);
|
|
484
|
-
setIfEmpty(webPage, "dateModified", node.dateModified);
|
|
485
|
-
setIfEmpty(webPage, "datePublished", node.datePublished);
|
|
486
|
-
}
|
|
487
|
-
return node;
|
|
488
|
-
}
|
|
489
|
-
});
|
|
490
|
-
|
|
491
|
-
const bookEditionResolver = defineSchemaOrgResolver({
|
|
492
|
-
defaults: {
|
|
493
|
-
"@type": "Book"
|
|
494
|
-
},
|
|
495
|
-
inheritMeta: [
|
|
496
|
-
"inLanguage"
|
|
497
|
-
],
|
|
498
|
-
resolve(node, ctx) {
|
|
499
|
-
if (node.bookFormat)
|
|
500
|
-
node.bookFormat = withBase(node.bookFormat, "https://schema.org/");
|
|
501
|
-
if (node.datePublished)
|
|
502
|
-
node.datePublished = resolvableDateToDate(node.datePublished);
|
|
503
|
-
node.author = resolveRelation(node.author, ctx);
|
|
504
|
-
return node;
|
|
505
|
-
},
|
|
506
|
-
resolveRootNode(node, { find }) {
|
|
507
|
-
const identity = find(IdentityId);
|
|
508
|
-
if (identity)
|
|
509
|
-
setIfEmpty(node, "provider", idReference(identity));
|
|
510
|
-
return node;
|
|
511
|
-
}
|
|
512
|
-
});
|
|
513
|
-
const PrimaryBookId = "#book";
|
|
514
|
-
const bookResolver = defineSchemaOrgResolver({
|
|
515
|
-
defaults: {
|
|
516
|
-
"@type": "Book"
|
|
517
|
-
},
|
|
518
|
-
inheritMeta: [
|
|
519
|
-
"description",
|
|
520
|
-
"url",
|
|
521
|
-
{ meta: "title", key: "name" }
|
|
522
|
-
],
|
|
523
|
-
idPrefix: ["url", PrimaryBookId],
|
|
524
|
-
resolve(node, ctx) {
|
|
525
|
-
node.workExample = resolveRelation(node.workExample, ctx, bookEditionResolver);
|
|
526
|
-
node.author = resolveRelation(node.author, ctx);
|
|
527
|
-
if (node.url)
|
|
528
|
-
withBase(node.url, ctx.meta.host);
|
|
529
|
-
return node;
|
|
530
|
-
},
|
|
531
|
-
resolveRootNode(node, { find }) {
|
|
532
|
-
const identity = find(IdentityId);
|
|
533
|
-
if (identity)
|
|
534
|
-
setIfEmpty(node, "author", idReference(identity));
|
|
535
|
-
return node;
|
|
536
|
-
}
|
|
537
|
-
});
|
|
538
|
-
|
|
539
|
-
const commentResolver = defineSchemaOrgResolver({
|
|
540
|
-
defaults: {
|
|
541
|
-
"@type": "Comment"
|
|
542
|
-
},
|
|
543
|
-
idPrefix: "url",
|
|
544
|
-
resolve(node, ctx) {
|
|
545
|
-
node.author = resolveRelation(node.author, ctx, personResolver, {
|
|
546
|
-
root: true
|
|
547
|
-
});
|
|
548
|
-
return node;
|
|
549
|
-
},
|
|
550
|
-
resolveRootNode(node, { find }) {
|
|
551
|
-
const article = find(PrimaryArticleId);
|
|
552
|
-
if (article)
|
|
553
|
-
setIfEmpty(node, "about", idReference(article));
|
|
554
|
-
}
|
|
555
|
-
});
|
|
556
|
-
|
|
557
|
-
const courseResolver = defineSchemaOrgResolver({
|
|
558
|
-
defaults: {
|
|
559
|
-
"@type": "Course"
|
|
560
|
-
},
|
|
561
|
-
resolve(node, ctx) {
|
|
562
|
-
node.provider = resolveRelation(node.provider, ctx, organizationResolver, {
|
|
563
|
-
root: true
|
|
564
|
-
});
|
|
565
|
-
return node;
|
|
566
|
-
},
|
|
567
|
-
resolveRootNode(node, { find }) {
|
|
568
|
-
const identity = find(IdentityId);
|
|
569
|
-
if (identity)
|
|
570
|
-
setIfEmpty(node, "provider", idReference(identity));
|
|
571
|
-
return node;
|
|
572
|
-
}
|
|
573
|
-
});
|
|
574
|
-
|
|
575
|
-
const placeResolver = defineSchemaOrgResolver({
|
|
576
|
-
defaults: {
|
|
577
|
-
"@type": "Place"
|
|
578
|
-
},
|
|
579
|
-
resolve(node, ctx) {
|
|
580
|
-
if (typeof node.address !== "string")
|
|
581
|
-
node.address = resolveRelation(node.address, ctx, addressResolver);
|
|
582
|
-
return node;
|
|
583
|
-
}
|
|
584
|
-
});
|
|
585
|
-
|
|
586
|
-
const virtualLocationResolver = defineSchemaOrgResolver({
|
|
587
|
-
cast(node) {
|
|
588
|
-
if (typeof node === "string") {
|
|
589
|
-
return {
|
|
590
|
-
url: node
|
|
591
|
-
};
|
|
592
|
-
}
|
|
593
|
-
return node;
|
|
594
|
-
},
|
|
595
|
-
defaults: {
|
|
596
|
-
"@type": "VirtualLocation"
|
|
597
|
-
}
|
|
598
|
-
});
|
|
599
|
-
|
|
600
|
-
const PrimaryEventId = "#event";
|
|
601
|
-
const eventResolver = defineSchemaOrgResolver({
|
|
602
|
-
defaults: {
|
|
603
|
-
"@type": "Event"
|
|
604
|
-
},
|
|
605
|
-
inheritMeta: [
|
|
606
|
-
"inLanguage",
|
|
607
|
-
"description",
|
|
608
|
-
"image",
|
|
609
|
-
{ meta: "title", key: "name" }
|
|
610
|
-
],
|
|
611
|
-
idPrefix: ["url", PrimaryEventId],
|
|
612
|
-
resolve(node, ctx) {
|
|
613
|
-
if (node.location) {
|
|
614
|
-
const isVirtual = node.location === "string" || node.location?.url !== "undefined";
|
|
615
|
-
node.location = resolveRelation(node.location, ctx, isVirtual ? virtualLocationResolver : placeResolver);
|
|
616
|
-
}
|
|
617
|
-
node.performer = resolveRelation(node.performer, ctx, personResolver, {
|
|
618
|
-
root: true
|
|
619
|
-
});
|
|
620
|
-
node.organizer = resolveRelation(node.organizer, ctx, organizationResolver, {
|
|
621
|
-
root: true
|
|
622
|
-
});
|
|
623
|
-
node.offers = resolveRelation(node.offers, ctx, offerResolver);
|
|
624
|
-
if (node.eventAttendanceMode)
|
|
625
|
-
node.eventAttendanceMode = withBase(node.eventAttendanceMode, "https://schema.org/");
|
|
626
|
-
if (node.eventStatus)
|
|
627
|
-
node.eventStatus = withBase(node.eventStatus, "https://schema.org/");
|
|
628
|
-
const isOnline = node.eventStatus === "https://schema.org/EventMovedOnline";
|
|
629
|
-
const dates = ["startDate", "previousStartDate", "endDate"];
|
|
630
|
-
dates.forEach((date) => {
|
|
631
|
-
if (!isOnline) {
|
|
632
|
-
if (node[date] instanceof Date && node[date].getHours() === 0 && node[date].getMinutes() === 0)
|
|
633
|
-
node[date] = resolvableDateToDate(node[date]);
|
|
634
|
-
} else {
|
|
635
|
-
node[date] = resolvableDateToIso(node[date]);
|
|
636
|
-
}
|
|
637
|
-
});
|
|
638
|
-
setIfEmpty(node, "endDate", node.startDate);
|
|
639
|
-
return node;
|
|
640
|
-
},
|
|
641
|
-
resolveRootNode(node, { find }) {
|
|
642
|
-
const identity = find(IdentityId);
|
|
643
|
-
if (identity)
|
|
644
|
-
setIfEmpty(node, "organizer", idReference(identity));
|
|
645
|
-
}
|
|
646
|
-
});
|
|
647
|
-
|
|
648
|
-
const howToStepDirectionResolver = defineSchemaOrgResolver({
|
|
649
|
-
cast(node) {
|
|
650
|
-
if (typeof node === "string") {
|
|
651
|
-
return {
|
|
652
|
-
text: node
|
|
653
|
-
};
|
|
654
|
-
}
|
|
655
|
-
return node;
|
|
656
|
-
},
|
|
657
|
-
defaults: {
|
|
658
|
-
"@type": "HowToDirection"
|
|
659
|
-
}
|
|
660
|
-
});
|
|
661
|
-
|
|
662
|
-
const howToStepResolver = defineSchemaOrgResolver({
|
|
663
|
-
cast(node) {
|
|
664
|
-
if (typeof node === "string") {
|
|
665
|
-
return {
|
|
666
|
-
text: node
|
|
667
|
-
};
|
|
668
|
-
}
|
|
669
|
-
return node;
|
|
670
|
-
},
|
|
671
|
-
defaults: {
|
|
672
|
-
"@type": "HowToStep"
|
|
673
|
-
},
|
|
674
|
-
resolve(step, ctx) {
|
|
675
|
-
if (step.url)
|
|
676
|
-
step.url = resolveWithBase(ctx.meta.url, step.url);
|
|
677
|
-
if (step.image) {
|
|
678
|
-
step.image = resolveRelation(step.image, ctx, imageResolver, {
|
|
679
|
-
root: true
|
|
680
|
-
});
|
|
681
|
-
}
|
|
682
|
-
if (step.itemListElement)
|
|
683
|
-
step.itemListElement = resolveRelation(step.itemListElement, ctx, howToStepDirectionResolver);
|
|
684
|
-
return step;
|
|
685
|
-
}
|
|
686
|
-
});
|
|
687
|
-
|
|
688
|
-
const HowToId = "#howto";
|
|
689
|
-
const howToResolver = defineSchemaOrgResolver({
|
|
690
|
-
defaults: {
|
|
691
|
-
"@type": "HowTo"
|
|
692
|
-
},
|
|
693
|
-
inheritMeta: [
|
|
694
|
-
"description",
|
|
695
|
-
"image",
|
|
696
|
-
"inLanguage",
|
|
697
|
-
{ meta: "title", key: "name" }
|
|
698
|
-
],
|
|
699
|
-
idPrefix: ["url", HowToId],
|
|
700
|
-
resolve(node, ctx) {
|
|
701
|
-
node.step = resolveRelation(node.step, ctx, howToStepResolver);
|
|
702
|
-
return node;
|
|
703
|
-
},
|
|
704
|
-
resolveRootNode(node, { find }) {
|
|
705
|
-
const webPage = find(PrimaryWebPageId);
|
|
706
|
-
if (webPage)
|
|
707
|
-
setIfEmpty(node, "mainEntityOfPage", idReference(webPage));
|
|
708
|
-
}
|
|
709
|
-
});
|
|
710
|
-
|
|
711
|
-
const itemListResolver = defineSchemaOrgResolver({
|
|
712
|
-
defaults: {
|
|
713
|
-
"@type": "ItemList"
|
|
714
|
-
},
|
|
715
|
-
resolve(node, ctx) {
|
|
716
|
-
if (node.itemListElement) {
|
|
717
|
-
let index = 1;
|
|
718
|
-
node.itemListElement = resolveRelation(node.itemListElement, ctx, listItemResolver, {
|
|
719
|
-
array: true,
|
|
720
|
-
afterResolve(node2) {
|
|
721
|
-
setIfEmpty(node2, "position", index++);
|
|
722
|
-
}
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
return node;
|
|
726
|
-
}
|
|
727
|
-
});
|
|
728
|
-
|
|
729
|
-
const quantitativeValueResolver = defineSchemaOrgResolver({
|
|
730
|
-
defaults: {
|
|
731
|
-
"@type": "QuantitativeValue"
|
|
732
|
-
}
|
|
733
|
-
});
|
|
734
|
-
const monetaryAmountResolver = defineSchemaOrgResolver({
|
|
735
|
-
defaults: {
|
|
736
|
-
"@type": "MonetaryAmount"
|
|
737
|
-
},
|
|
738
|
-
resolve(node, ctx) {
|
|
739
|
-
node.value = resolveRelation(node.value, ctx, quantitativeValueResolver);
|
|
740
|
-
return node;
|
|
741
|
-
}
|
|
742
|
-
});
|
|
743
|
-
|
|
744
|
-
const jobPostingResolver = defineSchemaOrgResolver({
|
|
745
|
-
defaults: {
|
|
746
|
-
"@type": "JobPosting"
|
|
747
|
-
},
|
|
748
|
-
resolve(node, ctx) {
|
|
749
|
-
node.datePosted = resolvableDateToIso(node.datePosted);
|
|
750
|
-
node.hiringOrganization = resolveRelation(node.hiringOrganization, ctx, organizationResolver);
|
|
751
|
-
node.jobLocation = resolveRelation(node.jobLocation, ctx, placeResolver);
|
|
752
|
-
node.baseSalary = resolveRelation(node.baseSalary, ctx, monetaryAmountResolver);
|
|
753
|
-
node.validThrough = resolvableDateToIso(node.validThrough);
|
|
754
|
-
return node;
|
|
755
|
-
}
|
|
756
|
-
});
|
|
757
|
-
|
|
758
|
-
const openingHoursResolver = defineSchemaOrgResolver({
|
|
759
|
-
defaults: {
|
|
760
|
-
"@type": "OpeningHoursSpecification",
|
|
761
|
-
"opens": "00:00",
|
|
762
|
-
"closes": "23:59"
|
|
763
|
-
}
|
|
764
|
-
});
|
|
765
|
-
|
|
766
|
-
const localBusinessResolver = defineSchemaOrgResolver({
|
|
767
|
-
defaults: {
|
|
768
|
-
"@type": ["Organization", "LocalBusiness"]
|
|
769
|
-
},
|
|
770
|
-
inheritMeta: [
|
|
771
|
-
{ key: "url", meta: "host" },
|
|
772
|
-
{ key: "currenciesAccepted", meta: "currency" }
|
|
773
|
-
],
|
|
774
|
-
idPrefix: ["host", IdentityId],
|
|
775
|
-
resolve(node, ctx) {
|
|
776
|
-
resolveDefaultType(node, ["Organization", "LocalBusiness"]);
|
|
777
|
-
node.address = resolveRelation(node.address, ctx, addressResolver);
|
|
778
|
-
node.openingHoursSpecification = resolveRelation(node.openingHoursSpecification, ctx, openingHoursResolver);
|
|
779
|
-
node.logo = resolveRelation(node.logo, ctx, imageResolver, {
|
|
780
|
-
afterResolve(logo) {
|
|
781
|
-
const hasLogo = !!ctx.find("#logo");
|
|
782
|
-
if (!hasLogo)
|
|
783
|
-
logo["@id"] = prefixId(ctx.meta.host, "#logo");
|
|
784
|
-
setIfEmpty(logo, "caption", node.name);
|
|
785
|
-
}
|
|
786
|
-
});
|
|
787
|
-
return node;
|
|
788
|
-
}
|
|
789
|
-
});
|
|
790
|
-
|
|
791
|
-
const ratingResolver = defineSchemaOrgResolver({
|
|
792
|
-
cast(node) {
|
|
793
|
-
if (node === "number") {
|
|
794
|
-
return {
|
|
795
|
-
ratingValue: node
|
|
796
|
-
};
|
|
797
|
-
}
|
|
798
|
-
return node;
|
|
799
|
-
},
|
|
800
|
-
defaults: {
|
|
801
|
-
"@type": "Rating",
|
|
802
|
-
"bestRating": 5,
|
|
803
|
-
"worstRating": 1
|
|
804
|
-
}
|
|
805
|
-
});
|
|
806
|
-
|
|
807
|
-
const reviewResolver = defineSchemaOrgResolver({
|
|
808
|
-
defaults: {
|
|
809
|
-
"@type": "Review"
|
|
810
|
-
},
|
|
811
|
-
inheritMeta: [
|
|
812
|
-
"inLanguage"
|
|
813
|
-
],
|
|
814
|
-
resolve(review, ctx) {
|
|
815
|
-
review.reviewRating = resolveRelation(review.reviewRating, ctx, ratingResolver);
|
|
816
|
-
review.author = resolveRelation(review.author, ctx, personResolver);
|
|
817
|
-
return review;
|
|
818
|
-
}
|
|
819
|
-
});
|
|
820
|
-
|
|
821
|
-
const videoResolver = defineSchemaOrgResolver({
|
|
822
|
-
cast(input) {
|
|
823
|
-
if (typeof input === "string") {
|
|
824
|
-
input = {
|
|
825
|
-
url: input
|
|
826
|
-
};
|
|
827
|
-
}
|
|
828
|
-
return input;
|
|
829
|
-
},
|
|
830
|
-
alias: "video",
|
|
831
|
-
defaults: {
|
|
832
|
-
"@type": "VideoObject"
|
|
833
|
-
},
|
|
834
|
-
inheritMeta: [
|
|
835
|
-
{ meta: "title", key: "name" },
|
|
836
|
-
"description",
|
|
837
|
-
"image",
|
|
838
|
-
"inLanguage",
|
|
839
|
-
{ meta: "datePublished", key: "uploadDate" }
|
|
840
|
-
],
|
|
841
|
-
idPrefix: "host",
|
|
842
|
-
resolve(video, ctx) {
|
|
843
|
-
if (video.uploadDate)
|
|
844
|
-
video.uploadDate = resolvableDateToIso(video.uploadDate);
|
|
845
|
-
video.url = resolveWithBase(ctx.meta.host, video.url);
|
|
846
|
-
if (video.caption && !video.description)
|
|
847
|
-
video.description = video.caption;
|
|
848
|
-
if (!video.description)
|
|
849
|
-
video.description = "No description";
|
|
850
|
-
if (video.thumbnailUrl)
|
|
851
|
-
video.thumbnailUrl = resolveRelation(video.thumbnailUrl, ctx, imageResolver);
|
|
852
|
-
return video;
|
|
853
|
-
},
|
|
854
|
-
resolveRootNode(video, { find }) {
|
|
855
|
-
if (video.image && !video.thumbnailUrl) {
|
|
856
|
-
const firstImage = asArray(video.image)[0];
|
|
857
|
-
setIfEmpty(video, "thumbnailUrl", find(firstImage["@id"])?.url);
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
});
|
|
861
|
-
|
|
862
|
-
const movieResolver = defineSchemaOrgResolver({
|
|
863
|
-
defaults: {
|
|
864
|
-
"@type": "Movie"
|
|
865
|
-
},
|
|
866
|
-
resolve(node, ctx) {
|
|
867
|
-
node.aggregateRating = resolveRelation(node.aggregateRating, ctx, aggregateRatingResolver);
|
|
868
|
-
node.review = resolveRelation(node.review, ctx, reviewResolver);
|
|
869
|
-
node.director = resolveRelation(node.director, ctx, personResolver);
|
|
870
|
-
node.actor = resolveRelation(node.actor, ctx, personResolver);
|
|
871
|
-
node.trailer = resolveRelation(node.trailer, ctx, videoResolver);
|
|
872
|
-
if (node.dateCreated)
|
|
873
|
-
node.dateCreated = resolvableDateToDate(node.dateCreated);
|
|
874
|
-
return node;
|
|
875
|
-
}
|
|
876
|
-
});
|
|
877
|
-
|
|
878
|
-
const defaults = {
|
|
879
|
-
ignoreUnknown: false,
|
|
880
|
-
respectType: false,
|
|
881
|
-
respectFunctionNames: false,
|
|
882
|
-
respectFunctionProperties: false,
|
|
883
|
-
unorderedObjects: true,
|
|
884
|
-
unorderedArrays: false,
|
|
885
|
-
unorderedSets: false
|
|
886
|
-
};
|
|
887
|
-
function objectHash(object, options = {}) {
|
|
888
|
-
options = { ...defaults, ...options };
|
|
889
|
-
const hasher = createHasher(options);
|
|
890
|
-
hasher.dispatch(object);
|
|
891
|
-
return hasher.toString();
|
|
892
|
-
}
|
|
893
|
-
function createHasher(options) {
|
|
894
|
-
const buff = [];
|
|
895
|
-
let context = [];
|
|
896
|
-
const write = (str) => {
|
|
897
|
-
buff.push(str);
|
|
898
|
-
};
|
|
899
|
-
return {
|
|
900
|
-
toString() {
|
|
901
|
-
return buff.join("");
|
|
902
|
-
},
|
|
903
|
-
getContext() {
|
|
904
|
-
return context;
|
|
905
|
-
},
|
|
906
|
-
dispatch(value) {
|
|
907
|
-
if (options.replacer) {
|
|
908
|
-
value = options.replacer(value);
|
|
909
|
-
}
|
|
910
|
-
const type = value === null ? "null" : typeof value;
|
|
911
|
-
return this["_" + type](value);
|
|
912
|
-
},
|
|
913
|
-
_object(object) {
|
|
914
|
-
if (object && typeof object.toJSON === "function") {
|
|
915
|
-
return this._object(object.toJSON());
|
|
916
|
-
}
|
|
917
|
-
const pattern = /\[object (.*)]/i;
|
|
918
|
-
const objString = Object.prototype.toString.call(object);
|
|
919
|
-
const _objType = pattern.exec(objString);
|
|
920
|
-
const objType = _objType ? _objType[1].toLowerCase() : "unknown:[" + objString.toLowerCase() + "]";
|
|
921
|
-
let objectNumber = null;
|
|
922
|
-
if ((objectNumber = context.indexOf(object)) >= 0) {
|
|
923
|
-
return this.dispatch("[CIRCULAR:" + objectNumber + "]");
|
|
924
|
-
} else {
|
|
925
|
-
context.push(object);
|
|
926
|
-
}
|
|
927
|
-
if (typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(object)) {
|
|
928
|
-
write("buffer:");
|
|
929
|
-
return write(object.toString("utf8"));
|
|
930
|
-
}
|
|
931
|
-
if (objType !== "object" && objType !== "function" && objType !== "asyncfunction") {
|
|
932
|
-
if (this["_" + objType]) {
|
|
933
|
-
this["_" + objType](object);
|
|
934
|
-
} else if (!options.ignoreUnknown) {
|
|
935
|
-
this._unkown(object, objType);
|
|
936
|
-
}
|
|
937
|
-
} else {
|
|
938
|
-
let keys = Object.keys(object);
|
|
939
|
-
if (options.unorderedObjects) {
|
|
940
|
-
keys = keys.sort();
|
|
941
|
-
}
|
|
942
|
-
if (options.respectType !== false && !isNativeFunction(object)) {
|
|
943
|
-
keys.splice(0, 0, "prototype", "__proto__", "letructor");
|
|
944
|
-
}
|
|
945
|
-
if (options.excludeKeys) {
|
|
946
|
-
keys = keys.filter(function(key) {
|
|
947
|
-
return !options.excludeKeys(key);
|
|
948
|
-
});
|
|
949
|
-
}
|
|
950
|
-
write("object:" + keys.length + ":");
|
|
951
|
-
for (const key of keys) {
|
|
952
|
-
this.dispatch(key);
|
|
953
|
-
write(":");
|
|
954
|
-
if (!options.excludeValues) {
|
|
955
|
-
this.dispatch(object[key]);
|
|
956
|
-
}
|
|
957
|
-
write(",");
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
},
|
|
961
|
-
_array(arr, unordered) {
|
|
962
|
-
unordered = typeof unordered !== "undefined" ? unordered : options.unorderedArrays !== false;
|
|
963
|
-
write("array:" + arr.length + ":");
|
|
964
|
-
if (!unordered || arr.length <= 1) {
|
|
965
|
-
for (const entry of arr) {
|
|
966
|
-
this.dispatch(entry);
|
|
967
|
-
}
|
|
968
|
-
return;
|
|
969
|
-
}
|
|
970
|
-
const contextAdditions = [];
|
|
971
|
-
const entries = arr.map((entry) => {
|
|
972
|
-
const hasher = createHasher(options);
|
|
973
|
-
hasher.dispatch(entry);
|
|
974
|
-
contextAdditions.push(hasher.getContext());
|
|
975
|
-
return hasher.toString();
|
|
976
|
-
});
|
|
977
|
-
context = [...context, ...contextAdditions];
|
|
978
|
-
entries.sort();
|
|
979
|
-
return this._array(entries, false);
|
|
980
|
-
},
|
|
981
|
-
_date(date) {
|
|
982
|
-
return write("date:" + date.toJSON());
|
|
983
|
-
},
|
|
984
|
-
_symbol(sym) {
|
|
985
|
-
return write("symbol:" + sym.toString());
|
|
986
|
-
},
|
|
987
|
-
_unkown(value, type) {
|
|
988
|
-
write(type);
|
|
989
|
-
if (!value) {
|
|
990
|
-
return;
|
|
991
|
-
}
|
|
992
|
-
write(":");
|
|
993
|
-
if (value && typeof value.entries === "function") {
|
|
994
|
-
return this._array(
|
|
995
|
-
Array.from(value.entries()),
|
|
996
|
-
true
|
|
997
|
-
/* ordered */
|
|
998
|
-
);
|
|
999
|
-
}
|
|
1000
|
-
},
|
|
1001
|
-
_error(err) {
|
|
1002
|
-
return write("error:" + err.toString());
|
|
1003
|
-
},
|
|
1004
|
-
_boolean(bool) {
|
|
1005
|
-
return write("bool:" + bool.toString());
|
|
1006
|
-
},
|
|
1007
|
-
_string(string) {
|
|
1008
|
-
write("string:" + string.length + ":");
|
|
1009
|
-
write(string.toString());
|
|
1010
|
-
},
|
|
1011
|
-
_function(fn) {
|
|
1012
|
-
write("fn:");
|
|
1013
|
-
if (isNativeFunction(fn)) {
|
|
1014
|
-
this.dispatch("[native]");
|
|
1015
|
-
} else {
|
|
1016
|
-
this.dispatch(fn.toString());
|
|
1017
|
-
}
|
|
1018
|
-
if (options.respectFunctionNames !== false) {
|
|
1019
|
-
this.dispatch("function-name:" + String(fn.name));
|
|
1020
|
-
}
|
|
1021
|
-
if (options.respectFunctionProperties) {
|
|
1022
|
-
this._object(fn);
|
|
1023
|
-
}
|
|
1024
|
-
},
|
|
1025
|
-
_number(number) {
|
|
1026
|
-
return write("number:" + number.toString());
|
|
1027
|
-
},
|
|
1028
|
-
_xml(xml) {
|
|
1029
|
-
return write("xml:" + xml.toString());
|
|
1030
|
-
},
|
|
1031
|
-
_null() {
|
|
1032
|
-
return write("Null");
|
|
1033
|
-
},
|
|
1034
|
-
_undefined() {
|
|
1035
|
-
return write("Undefined");
|
|
1036
|
-
},
|
|
1037
|
-
_regexp(regex) {
|
|
1038
|
-
return write("regex:" + regex.toString());
|
|
1039
|
-
},
|
|
1040
|
-
_uint8array(arr) {
|
|
1041
|
-
write("uint8array:");
|
|
1042
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
1043
|
-
},
|
|
1044
|
-
_uint8clampedarray(arr) {
|
|
1045
|
-
write("uint8clampedarray:");
|
|
1046
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
1047
|
-
},
|
|
1048
|
-
_int8array(arr) {
|
|
1049
|
-
write("int8array:");
|
|
1050
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
1051
|
-
},
|
|
1052
|
-
_uint16array(arr) {
|
|
1053
|
-
write("uint16array:");
|
|
1054
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
1055
|
-
},
|
|
1056
|
-
_int16array(arr) {
|
|
1057
|
-
write("int16array:");
|
|
1058
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
1059
|
-
},
|
|
1060
|
-
_uint32array(arr) {
|
|
1061
|
-
write("uint32array:");
|
|
1062
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
1063
|
-
},
|
|
1064
|
-
_int32array(arr) {
|
|
1065
|
-
write("int32array:");
|
|
1066
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
1067
|
-
},
|
|
1068
|
-
_float32array(arr) {
|
|
1069
|
-
write("float32array:");
|
|
1070
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
1071
|
-
},
|
|
1072
|
-
_float64array(arr) {
|
|
1073
|
-
write("float64array:");
|
|
1074
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
1075
|
-
},
|
|
1076
|
-
_arraybuffer(arr) {
|
|
1077
|
-
write("arraybuffer:");
|
|
1078
|
-
return this.dispatch(new Uint8Array(arr));
|
|
1079
|
-
},
|
|
1080
|
-
_url(url) {
|
|
1081
|
-
return write("url:" + url.toString());
|
|
1082
|
-
},
|
|
1083
|
-
_map(map) {
|
|
1084
|
-
write("map:");
|
|
1085
|
-
const arr = [...map];
|
|
1086
|
-
return this._array(arr, options.unorderedSets !== false);
|
|
1087
|
-
},
|
|
1088
|
-
_set(set) {
|
|
1089
|
-
write("set:");
|
|
1090
|
-
const arr = [...set];
|
|
1091
|
-
return this._array(arr, options.unorderedSets !== false);
|
|
1092
|
-
},
|
|
1093
|
-
_file(file) {
|
|
1094
|
-
write("file:");
|
|
1095
|
-
return this.dispatch([file.name, file.size, file.type, file.lastModfied]);
|
|
1096
|
-
},
|
|
1097
|
-
_blob() {
|
|
1098
|
-
if (options.ignoreUnknown) {
|
|
1099
|
-
return write("[blob]");
|
|
1100
|
-
}
|
|
1101
|
-
throw new Error(
|
|
1102
|
-
'Hashing Blob objects is currently not supported\nUse "options.replacer" or "options.ignoreUnknown"\n'
|
|
1103
|
-
);
|
|
1104
|
-
},
|
|
1105
|
-
_domwindow() {
|
|
1106
|
-
return write("domwindow");
|
|
1107
|
-
},
|
|
1108
|
-
_bigint(number) {
|
|
1109
|
-
return write("bigint:" + number.toString());
|
|
1110
|
-
},
|
|
1111
|
-
/* Node.js standard native objects */
|
|
1112
|
-
_process() {
|
|
1113
|
-
return write("process");
|
|
1114
|
-
},
|
|
1115
|
-
_timer() {
|
|
1116
|
-
return write("timer");
|
|
1117
|
-
},
|
|
1118
|
-
_pipe() {
|
|
1119
|
-
return write("pipe");
|
|
1120
|
-
},
|
|
1121
|
-
_tcp() {
|
|
1122
|
-
return write("tcp");
|
|
1123
|
-
},
|
|
1124
|
-
_udp() {
|
|
1125
|
-
return write("udp");
|
|
1126
|
-
},
|
|
1127
|
-
_tty() {
|
|
1128
|
-
return write("tty");
|
|
1129
|
-
},
|
|
1130
|
-
_statwatcher() {
|
|
1131
|
-
return write("statwatcher");
|
|
1132
|
-
},
|
|
1133
|
-
_securecontext() {
|
|
1134
|
-
return write("securecontext");
|
|
1135
|
-
},
|
|
1136
|
-
_connection() {
|
|
1137
|
-
return write("connection");
|
|
1138
|
-
},
|
|
1139
|
-
_zlib() {
|
|
1140
|
-
return write("zlib");
|
|
1141
|
-
},
|
|
1142
|
-
_context() {
|
|
1143
|
-
return write("context");
|
|
1144
|
-
},
|
|
1145
|
-
_nodescript() {
|
|
1146
|
-
return write("nodescript");
|
|
1147
|
-
},
|
|
1148
|
-
_httpparser() {
|
|
1149
|
-
return write("httpparser");
|
|
1150
|
-
},
|
|
1151
|
-
_dataview() {
|
|
1152
|
-
return write("dataview");
|
|
1153
|
-
},
|
|
1154
|
-
_signal() {
|
|
1155
|
-
return write("signal");
|
|
1156
|
-
},
|
|
1157
|
-
_fsevent() {
|
|
1158
|
-
return write("fsevent");
|
|
1159
|
-
},
|
|
1160
|
-
_tlswrap() {
|
|
1161
|
-
return write("tlswrap");
|
|
1162
|
-
}
|
|
1163
|
-
};
|
|
1164
|
-
}
|
|
1165
|
-
function isNativeFunction(f) {
|
|
1166
|
-
if (typeof f !== "function") {
|
|
1167
|
-
return false;
|
|
1168
|
-
}
|
|
1169
|
-
const exp = /^function\s+\w*\s*\(\s*\)\s*{\s+\[native code]\s+}$/i;
|
|
1170
|
-
return exp.exec(Function.prototype.toString.call(f)) != null;
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
|
-
class WordArray {
|
|
1174
|
-
constructor(words, sigBytes) {
|
|
1175
|
-
words = this.words = words || [];
|
|
1176
|
-
this.sigBytes = sigBytes !== void 0 ? sigBytes : words.length * 4;
|
|
1177
|
-
}
|
|
1178
|
-
toString(encoder) {
|
|
1179
|
-
return (encoder || Hex).stringify(this);
|
|
1180
|
-
}
|
|
1181
|
-
concat(wordArray) {
|
|
1182
|
-
this.clamp();
|
|
1183
|
-
if (this.sigBytes % 4) {
|
|
1184
|
-
for (let i = 0; i < wordArray.sigBytes; i++) {
|
|
1185
|
-
const thatByte = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
|
1186
|
-
this.words[this.sigBytes + i >>> 2] |= thatByte << 24 - (this.sigBytes + i) % 4 * 8;
|
|
1187
|
-
}
|
|
1188
|
-
} else {
|
|
1189
|
-
for (let j = 0; j < wordArray.sigBytes; j += 4) {
|
|
1190
|
-
this.words[this.sigBytes + j >>> 2] = wordArray.words[j >>> 2];
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
this.sigBytes += wordArray.sigBytes;
|
|
1194
|
-
return this;
|
|
1195
|
-
}
|
|
1196
|
-
clamp() {
|
|
1197
|
-
this.words[this.sigBytes >>> 2] &= 4294967295 << 32 - this.sigBytes % 4 * 8;
|
|
1198
|
-
this.words.length = Math.ceil(this.sigBytes / 4);
|
|
1199
|
-
}
|
|
1200
|
-
clone() {
|
|
1201
|
-
return new WordArray([...this.words]);
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
const Hex = {
|
|
1205
|
-
stringify(wordArray) {
|
|
1206
|
-
const hexChars = [];
|
|
1207
|
-
for (let i = 0; i < wordArray.sigBytes; i++) {
|
|
1208
|
-
const bite = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
|
1209
|
-
hexChars.push((bite >>> 4).toString(16), (bite & 15).toString(16));
|
|
1210
|
-
}
|
|
1211
|
-
return hexChars.join("");
|
|
1212
|
-
}
|
|
1213
|
-
};
|
|
1214
|
-
const Base64 = {
|
|
1215
|
-
stringify(wordArray) {
|
|
1216
|
-
const keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
1217
|
-
const base64Chars = [];
|
|
1218
|
-
for (let i = 0; i < wordArray.sigBytes; i += 3) {
|
|
1219
|
-
const byte1 = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
|
1220
|
-
const byte2 = wordArray.words[i + 1 >>> 2] >>> 24 - (i + 1) % 4 * 8 & 255;
|
|
1221
|
-
const byte3 = wordArray.words[i + 2 >>> 2] >>> 24 - (i + 2) % 4 * 8 & 255;
|
|
1222
|
-
const triplet = byte1 << 16 | byte2 << 8 | byte3;
|
|
1223
|
-
for (let j = 0; j < 4 && i * 8 + j * 6 < wordArray.sigBytes * 8; j++) {
|
|
1224
|
-
base64Chars.push(keyStr.charAt(triplet >>> 6 * (3 - j) & 63));
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
return base64Chars.join("");
|
|
1228
|
-
}
|
|
1229
|
-
};
|
|
1230
|
-
const Latin1 = {
|
|
1231
|
-
parse(latin1Str) {
|
|
1232
|
-
const latin1StrLength = latin1Str.length;
|
|
1233
|
-
const words = [];
|
|
1234
|
-
for (let i = 0; i < latin1StrLength; i++) {
|
|
1235
|
-
words[i >>> 2] |= (latin1Str.charCodeAt(i) & 255) << 24 - i % 4 * 8;
|
|
1236
|
-
}
|
|
1237
|
-
return new WordArray(words, latin1StrLength);
|
|
1238
|
-
}
|
|
1239
|
-
};
|
|
1240
|
-
const Utf8 = {
|
|
1241
|
-
parse(utf8Str) {
|
|
1242
|
-
return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
|
|
1243
|
-
}
|
|
1244
|
-
};
|
|
1245
|
-
class BufferedBlockAlgorithm {
|
|
1246
|
-
constructor() {
|
|
1247
|
-
this._minBufferSize = 0;
|
|
1248
|
-
this.blockSize = 512 / 32;
|
|
1249
|
-
this.reset();
|
|
1250
|
-
}
|
|
1251
|
-
reset() {
|
|
1252
|
-
this._data = new WordArray();
|
|
1253
|
-
this._nDataBytes = 0;
|
|
1254
|
-
}
|
|
1255
|
-
_append(data) {
|
|
1256
|
-
if (typeof data === "string") {
|
|
1257
|
-
data = Utf8.parse(data);
|
|
1258
|
-
}
|
|
1259
|
-
this._data.concat(data);
|
|
1260
|
-
this._nDataBytes += data.sigBytes;
|
|
1261
|
-
}
|
|
1262
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1263
|
-
_doProcessBlock(_dataWords, _offset) {
|
|
1264
|
-
}
|
|
1265
|
-
_process(doFlush) {
|
|
1266
|
-
let processedWords;
|
|
1267
|
-
let nBlocksReady = this._data.sigBytes / (this.blockSize * 4);
|
|
1268
|
-
if (doFlush) {
|
|
1269
|
-
nBlocksReady = Math.ceil(nBlocksReady);
|
|
1270
|
-
} else {
|
|
1271
|
-
nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
|
|
1272
|
-
}
|
|
1273
|
-
const nWordsReady = nBlocksReady * this.blockSize;
|
|
1274
|
-
const nBytesReady = Math.min(nWordsReady * 4, this._data.sigBytes);
|
|
1275
|
-
if (nWordsReady) {
|
|
1276
|
-
for (let offset = 0; offset < nWordsReady; offset += this.blockSize) {
|
|
1277
|
-
this._doProcessBlock(this._data.words, offset);
|
|
1278
|
-
}
|
|
1279
|
-
processedWords = this._data.words.splice(0, nWordsReady);
|
|
1280
|
-
this._data.sigBytes -= nBytesReady;
|
|
1281
|
-
}
|
|
1282
|
-
return new WordArray(processedWords, nBytesReady);
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
class Hasher extends BufferedBlockAlgorithm {
|
|
1286
|
-
update(messageUpdate) {
|
|
1287
|
-
this._append(messageUpdate);
|
|
1288
|
-
this._process();
|
|
1289
|
-
return this;
|
|
1290
|
-
}
|
|
1291
|
-
finalize(messageUpdate) {
|
|
1292
|
-
if (messageUpdate) {
|
|
1293
|
-
this._append(messageUpdate);
|
|
1294
|
-
}
|
|
1295
|
-
}
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
const H = [
|
|
1299
|
-
1779033703,
|
|
1300
|
-
-1150833019,
|
|
1301
|
-
1013904242,
|
|
1302
|
-
-1521486534,
|
|
1303
|
-
1359893119,
|
|
1304
|
-
-1694144372,
|
|
1305
|
-
528734635,
|
|
1306
|
-
1541459225
|
|
1307
|
-
];
|
|
1308
|
-
const K = [
|
|
1309
|
-
1116352408,
|
|
1310
|
-
1899447441,
|
|
1311
|
-
-1245643825,
|
|
1312
|
-
-373957723,
|
|
1313
|
-
961987163,
|
|
1314
|
-
1508970993,
|
|
1315
|
-
-1841331548,
|
|
1316
|
-
-1424204075,
|
|
1317
|
-
-670586216,
|
|
1318
|
-
310598401,
|
|
1319
|
-
607225278,
|
|
1320
|
-
1426881987,
|
|
1321
|
-
1925078388,
|
|
1322
|
-
-2132889090,
|
|
1323
|
-
-1680079193,
|
|
1324
|
-
-1046744716,
|
|
1325
|
-
-459576895,
|
|
1326
|
-
-272742522,
|
|
1327
|
-
264347078,
|
|
1328
|
-
604807628,
|
|
1329
|
-
770255983,
|
|
1330
|
-
1249150122,
|
|
1331
|
-
1555081692,
|
|
1332
|
-
1996064986,
|
|
1333
|
-
-1740746414,
|
|
1334
|
-
-1473132947,
|
|
1335
|
-
-1341970488,
|
|
1336
|
-
-1084653625,
|
|
1337
|
-
-958395405,
|
|
1338
|
-
-710438585,
|
|
1339
|
-
113926993,
|
|
1340
|
-
338241895,
|
|
1341
|
-
666307205,
|
|
1342
|
-
773529912,
|
|
1343
|
-
1294757372,
|
|
1344
|
-
1396182291,
|
|
1345
|
-
1695183700,
|
|
1346
|
-
1986661051,
|
|
1347
|
-
-2117940946,
|
|
1348
|
-
-1838011259,
|
|
1349
|
-
-1564481375,
|
|
1350
|
-
-1474664885,
|
|
1351
|
-
-1035236496,
|
|
1352
|
-
-949202525,
|
|
1353
|
-
-778901479,
|
|
1354
|
-
-694614492,
|
|
1355
|
-
-200395387,
|
|
1356
|
-
275423344,
|
|
1357
|
-
430227734,
|
|
1358
|
-
506948616,
|
|
1359
|
-
659060556,
|
|
1360
|
-
883997877,
|
|
1361
|
-
958139571,
|
|
1362
|
-
1322822218,
|
|
1363
|
-
1537002063,
|
|
1364
|
-
1747873779,
|
|
1365
|
-
1955562222,
|
|
1366
|
-
2024104815,
|
|
1367
|
-
-2067236844,
|
|
1368
|
-
-1933114872,
|
|
1369
|
-
-1866530822,
|
|
1370
|
-
-1538233109,
|
|
1371
|
-
-1090935817,
|
|
1372
|
-
-965641998
|
|
1373
|
-
];
|
|
1374
|
-
const W = [];
|
|
1375
|
-
class SHA256 extends Hasher {
|
|
1376
|
-
constructor() {
|
|
1377
|
-
super();
|
|
1378
|
-
this.reset();
|
|
1379
|
-
}
|
|
1380
|
-
reset() {
|
|
1381
|
-
super.reset();
|
|
1382
|
-
this._hash = new WordArray([...H]);
|
|
1383
|
-
}
|
|
1384
|
-
_doProcessBlock(M, offset) {
|
|
1385
|
-
const H2 = this._hash.words;
|
|
1386
|
-
let a = H2[0];
|
|
1387
|
-
let b = H2[1];
|
|
1388
|
-
let c = H2[2];
|
|
1389
|
-
let d = H2[3];
|
|
1390
|
-
let e = H2[4];
|
|
1391
|
-
let f = H2[5];
|
|
1392
|
-
let g = H2[6];
|
|
1393
|
-
let h = H2[7];
|
|
1394
|
-
for (let i = 0; i < 64; i++) {
|
|
1395
|
-
if (i < 16) {
|
|
1396
|
-
W[i] = M[offset + i] | 0;
|
|
1397
|
-
} else {
|
|
1398
|
-
const gamma0x = W[i - 15];
|
|
1399
|
-
const gamma0 = (gamma0x << 25 | gamma0x >>> 7) ^ (gamma0x << 14 | gamma0x >>> 18) ^ gamma0x >>> 3;
|
|
1400
|
-
const gamma1x = W[i - 2];
|
|
1401
|
-
const gamma1 = (gamma1x << 15 | gamma1x >>> 17) ^ (gamma1x << 13 | gamma1x >>> 19) ^ gamma1x >>> 10;
|
|
1402
|
-
W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
|
|
1403
|
-
}
|
|
1404
|
-
const ch = e & f ^ ~e & g;
|
|
1405
|
-
const maj = a & b ^ a & c ^ b & c;
|
|
1406
|
-
const sigma0 = (a << 30 | a >>> 2) ^ (a << 19 | a >>> 13) ^ (a << 10 | a >>> 22);
|
|
1407
|
-
const sigma1 = (e << 26 | e >>> 6) ^ (e << 21 | e >>> 11) ^ (e << 7 | e >>> 25);
|
|
1408
|
-
const t1 = h + sigma1 + ch + K[i] + W[i];
|
|
1409
|
-
const t2 = sigma0 + maj;
|
|
1410
|
-
h = g;
|
|
1411
|
-
g = f;
|
|
1412
|
-
f = e;
|
|
1413
|
-
e = d + t1 | 0;
|
|
1414
|
-
d = c;
|
|
1415
|
-
c = b;
|
|
1416
|
-
b = a;
|
|
1417
|
-
a = t1 + t2 | 0;
|
|
1418
|
-
}
|
|
1419
|
-
H2[0] = H2[0] + a | 0;
|
|
1420
|
-
H2[1] = H2[1] + b | 0;
|
|
1421
|
-
H2[2] = H2[2] + c | 0;
|
|
1422
|
-
H2[3] = H2[3] + d | 0;
|
|
1423
|
-
H2[4] = H2[4] + e | 0;
|
|
1424
|
-
H2[5] = H2[5] + f | 0;
|
|
1425
|
-
H2[6] = H2[6] + g | 0;
|
|
1426
|
-
H2[7] = H2[7] + h | 0;
|
|
1427
|
-
}
|
|
1428
|
-
finalize(messageUpdate) {
|
|
1429
|
-
super.finalize(messageUpdate);
|
|
1430
|
-
const nBitsTotal = this._nDataBytes * 8;
|
|
1431
|
-
const nBitsLeft = this._data.sigBytes * 8;
|
|
1432
|
-
this._data.words[nBitsLeft >>> 5] |= 128 << 24 - nBitsLeft % 32;
|
|
1433
|
-
this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 14] = Math.floor(
|
|
1434
|
-
nBitsTotal / 4294967296
|
|
1435
|
-
);
|
|
1436
|
-
this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 15] = nBitsTotal;
|
|
1437
|
-
this._data.sigBytes = this._data.words.length * 4;
|
|
1438
|
-
this._process();
|
|
1439
|
-
return this._hash;
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1442
|
-
function sha256base64(message) {
|
|
1443
|
-
return new SHA256().finalize(message).toString(Base64);
|
|
1444
|
-
}
|
|
1445
|
-
|
|
1446
|
-
function hash(object, options = {}) {
|
|
1447
|
-
const hashed = typeof object === "string" ? object : objectHash(object, options);
|
|
1448
|
-
return sha256base64(hashed).slice(0, 10);
|
|
1449
|
-
}
|
|
1450
|
-
|
|
1451
|
-
const ProductId = "#product";
|
|
1452
|
-
const productResolver = defineSchemaOrgResolver({
|
|
1453
|
-
defaults: {
|
|
1454
|
-
"@type": "Product"
|
|
1455
|
-
},
|
|
1456
|
-
inheritMeta: [
|
|
1457
|
-
"description",
|
|
1458
|
-
"image",
|
|
1459
|
-
{ meta: "title", key: "name" }
|
|
1460
|
-
],
|
|
1461
|
-
idPrefix: ["url", ProductId],
|
|
1462
|
-
resolve(node, ctx) {
|
|
1463
|
-
setIfEmpty(node, "sku", hash(node.name));
|
|
1464
|
-
node.aggregateOffer = resolveRelation(node.aggregateOffer, ctx, aggregateOfferResolver);
|
|
1465
|
-
node.aggregateRating = resolveRelation(node.aggregateRating, ctx, aggregateRatingResolver);
|
|
1466
|
-
node.offers = resolveRelation(node.offers, ctx, offerResolver);
|
|
1467
|
-
node.review = resolveRelation(node.review, ctx, reviewResolver);
|
|
1468
|
-
return node;
|
|
1469
|
-
},
|
|
1470
|
-
resolveRootNode(product, { find }) {
|
|
1471
|
-
const webPage = find(PrimaryWebPageId);
|
|
1472
|
-
const identity = find(IdentityId);
|
|
1473
|
-
if (identity)
|
|
1474
|
-
setIfEmpty(product, "brand", idReference(identity));
|
|
1475
|
-
if (webPage)
|
|
1476
|
-
setIfEmpty(product, "mainEntityOfPage", idReference(webPage));
|
|
1477
|
-
return product;
|
|
1478
|
-
}
|
|
1479
|
-
});
|
|
1480
|
-
|
|
1481
|
-
const answerResolver = defineSchemaOrgResolver({
|
|
1482
|
-
cast(node) {
|
|
1483
|
-
if (typeof node === "string") {
|
|
1484
|
-
return {
|
|
1485
|
-
text: node
|
|
1486
|
-
};
|
|
1487
|
-
}
|
|
1488
|
-
return node;
|
|
1489
|
-
},
|
|
1490
|
-
defaults: {
|
|
1491
|
-
"@type": "Answer"
|
|
1492
|
-
}
|
|
1493
|
-
});
|
|
1494
|
-
|
|
1495
|
-
const questionResolver = defineSchemaOrgResolver({
|
|
1496
|
-
defaults: {
|
|
1497
|
-
"@type": "Question"
|
|
1498
|
-
},
|
|
1499
|
-
inheritMeta: [
|
|
1500
|
-
"inLanguage"
|
|
1501
|
-
],
|
|
1502
|
-
idPrefix: "url",
|
|
1503
|
-
resolve(question, ctx) {
|
|
1504
|
-
if (question.question)
|
|
1505
|
-
question.name = question.question;
|
|
1506
|
-
if (question.answer)
|
|
1507
|
-
question.acceptedAnswer = question.answer;
|
|
1508
|
-
question.acceptedAnswer = resolveRelation(question.acceptedAnswer, ctx, answerResolver);
|
|
1509
|
-
return question;
|
|
1510
|
-
},
|
|
1511
|
-
resolveRootNode(question, { find }) {
|
|
1512
|
-
const webPage = find(PrimaryWebPageId);
|
|
1513
|
-
if (webPage && asArray(webPage["@type"]).includes("FAQPage"))
|
|
1514
|
-
dedupeMerge(webPage, "mainEntity", idReference(question));
|
|
1515
|
-
}
|
|
1516
|
-
});
|
|
1517
|
-
|
|
1518
|
-
const RecipeId = "#recipe";
|
|
1519
|
-
const recipeResolver = defineSchemaOrgResolver({
|
|
1520
|
-
defaults: {
|
|
1521
|
-
"@type": "Recipe"
|
|
1522
|
-
},
|
|
1523
|
-
inheritMeta: [
|
|
1524
|
-
{ meta: "title", key: "name" },
|
|
1525
|
-
"description",
|
|
1526
|
-
"image",
|
|
1527
|
-
"datePublished"
|
|
1528
|
-
],
|
|
1529
|
-
idPrefix: ["url", RecipeId],
|
|
1530
|
-
resolve(node, ctx) {
|
|
1531
|
-
node.recipeInstructions = resolveRelation(node.recipeInstructions, ctx, howToStepResolver);
|
|
1532
|
-
return node;
|
|
1533
|
-
},
|
|
1534
|
-
resolveRootNode(node, { find }) {
|
|
1535
|
-
const article = find(PrimaryArticleId);
|
|
1536
|
-
const webPage = find(PrimaryWebPageId);
|
|
1537
|
-
if (article)
|
|
1538
|
-
setIfEmpty(node, "mainEntityOfPage", idReference(article));
|
|
1539
|
-
else if (webPage)
|
|
1540
|
-
setIfEmpty(node, "mainEntityOfPage", idReference(webPage));
|
|
1541
|
-
if (article?.author)
|
|
1542
|
-
setIfEmpty(node, "author", article.author);
|
|
1543
|
-
return node;
|
|
1544
|
-
}
|
|
1545
|
-
});
|
|
1546
|
-
|
|
1547
|
-
const softwareAppResolver = defineSchemaOrgResolver({
|
|
1548
|
-
defaults: {
|
|
1549
|
-
"@type": "SoftwareApplication"
|
|
1550
|
-
},
|
|
1551
|
-
resolve(node, ctx) {
|
|
1552
|
-
resolveDefaultType(node, "SoftwareApplication");
|
|
1553
|
-
node.offers = resolveRelation(node.offers, ctx, offerResolver);
|
|
1554
|
-
node.aggregateRating = resolveRelation(node.aggregateRating, ctx, aggregateRatingResolver);
|
|
1555
|
-
node.review = resolveRelation(node.review, ctx, reviewResolver);
|
|
1556
|
-
return node;
|
|
1557
|
-
}
|
|
1558
|
-
});
|
|
1559
|
-
|
|
1560
|
-
function loadResolver(resolver) {
|
|
1561
|
-
switch (resolver) {
|
|
1562
|
-
case "address":
|
|
1563
|
-
return addressResolver;
|
|
1564
|
-
case "aggregateOffer":
|
|
1565
|
-
return aggregateOfferResolver;
|
|
1566
|
-
case "aggregateRating":
|
|
1567
|
-
return aggregateRatingResolver;
|
|
1568
|
-
case "article":
|
|
1569
|
-
return articleResolver;
|
|
1570
|
-
case "breadcrumb":
|
|
1571
|
-
return breadcrumbResolver;
|
|
1572
|
-
case "comment":
|
|
1573
|
-
return commentResolver;
|
|
1574
|
-
case "event":
|
|
1575
|
-
return eventResolver;
|
|
1576
|
-
case "virtualLocation":
|
|
1577
|
-
return virtualLocationResolver;
|
|
1578
|
-
case "place":
|
|
1579
|
-
return placeResolver;
|
|
1580
|
-
case "howTo":
|
|
1581
|
-
return howToResolver;
|
|
1582
|
-
case "howToStep":
|
|
1583
|
-
return howToStepResolver;
|
|
1584
|
-
case "image":
|
|
1585
|
-
return imageResolver;
|
|
1586
|
-
case "localBusiness":
|
|
1587
|
-
return localBusinessResolver;
|
|
1588
|
-
case "offer":
|
|
1589
|
-
return offerResolver;
|
|
1590
|
-
case "openingHours":
|
|
1591
|
-
return openingHoursResolver;
|
|
1592
|
-
case "organization":
|
|
1593
|
-
return organizationResolver;
|
|
1594
|
-
case "person":
|
|
1595
|
-
return personResolver;
|
|
1596
|
-
case "product":
|
|
1597
|
-
return productResolver;
|
|
1598
|
-
case "question":
|
|
1599
|
-
return questionResolver;
|
|
1600
|
-
case "recipe":
|
|
1601
|
-
return recipeResolver;
|
|
1602
|
-
case "review":
|
|
1603
|
-
return reviewResolver;
|
|
1604
|
-
case "video":
|
|
1605
|
-
return videoResolver;
|
|
1606
|
-
case "webPage":
|
|
1607
|
-
return webPageResolver;
|
|
1608
|
-
case "webSite":
|
|
1609
|
-
return webSiteResolver;
|
|
1610
|
-
case "book":
|
|
1611
|
-
return bookResolver;
|
|
1612
|
-
case "course":
|
|
1613
|
-
return courseResolver;
|
|
1614
|
-
case "itemList":
|
|
1615
|
-
return itemListResolver;
|
|
1616
|
-
case "jobPosting":
|
|
1617
|
-
return jobPostingResolver;
|
|
1618
|
-
case "listItem":
|
|
1619
|
-
return listItemResolver;
|
|
1620
|
-
case "movie":
|
|
1621
|
-
return movieResolver;
|
|
1622
|
-
case "searchAction":
|
|
1623
|
-
return searchActionResolver;
|
|
1624
|
-
case "readAction":
|
|
1625
|
-
return readActionResolver;
|
|
1626
|
-
case "softwareApp":
|
|
1627
|
-
return softwareAppResolver;
|
|
1628
|
-
case "bookEdition":
|
|
1629
|
-
return bookEditionResolver;
|
|
1630
|
-
}
|
|
1631
|
-
return null;
|
|
1632
|
-
}
|
|
1633
|
-
|
|
1634
|
-
const resolver = {
|
|
1635
|
-
__proto__: null,
|
|
1636
|
-
loadResolver: loadResolver
|
|
1637
|
-
};
|
|
1638
|
-
|
|
1639
|
-
function resolveMeta(meta) {
|
|
1640
|
-
if (!meta.host && meta.canonicalHost)
|
|
1641
|
-
meta.host = meta.canonicalHost;
|
|
1642
|
-
if (!meta.tagPosition && meta.position)
|
|
1643
|
-
meta.tagPosition = meta.position;
|
|
1644
|
-
if (!meta.currency && meta.defaultCurrency)
|
|
1645
|
-
meta.currency = meta.defaultCurrency;
|
|
1646
|
-
if (!meta.inLanguage && meta.defaultLanguage)
|
|
1647
|
-
meta.inLanguage = meta.defaultLanguage;
|
|
1648
|
-
if (!meta.path)
|
|
1649
|
-
meta.path = "/";
|
|
1650
|
-
if (!meta.host && typeof document !== "undefined")
|
|
1651
|
-
meta.host = document.location.host;
|
|
1652
|
-
if (!meta.url && meta.canonicalUrl)
|
|
1653
|
-
meta.url = meta.canonicalUrl;
|
|
1654
|
-
if (meta.path !== "/") {
|
|
1655
|
-
if (meta.trailingSlash && !hasTrailingSlash(meta.path))
|
|
1656
|
-
meta.path = withTrailingSlash(meta.path);
|
|
1657
|
-
else if (!meta.trailingSlash && hasTrailingSlash(meta.path))
|
|
1658
|
-
meta.path = withoutTrailingSlash(meta.path);
|
|
1659
|
-
}
|
|
1660
|
-
meta.url = joinURL(meta.host, meta.path);
|
|
1661
|
-
return {
|
|
1662
|
-
...meta,
|
|
1663
|
-
host: meta.host,
|
|
1664
|
-
url: meta.url,
|
|
1665
|
-
currency: meta.currency,
|
|
1666
|
-
image: meta.image,
|
|
1667
|
-
inLanguage: meta.inLanguage,
|
|
1668
|
-
title: meta.title,
|
|
1669
|
-
description: meta.description,
|
|
1670
|
-
datePublished: meta.datePublished,
|
|
1671
|
-
dateModified: meta.dateModified
|
|
1672
|
-
};
|
|
1673
|
-
}
|
|
1674
|
-
function resolveNode(node, ctx, resolver) {
|
|
1675
|
-
if (resolver?.cast)
|
|
1676
|
-
node = resolver.cast(node, ctx);
|
|
1677
|
-
if (resolver?.defaults) {
|
|
1678
|
-
let defaults = resolver.defaults || {};
|
|
1679
|
-
if (typeof defaults === "function")
|
|
1680
|
-
defaults = defaults(ctx);
|
|
1681
|
-
node = {
|
|
1682
|
-
...defaults,
|
|
1683
|
-
...node
|
|
1684
|
-
};
|
|
1685
|
-
}
|
|
1686
|
-
resolver.inheritMeta?.forEach((entry) => {
|
|
1687
|
-
if (typeof entry === "string")
|
|
1688
|
-
setIfEmpty(node, entry, ctx.meta[entry]);
|
|
1689
|
-
else
|
|
1690
|
-
setIfEmpty(node, entry.key, ctx.meta[entry.meta]);
|
|
1691
|
-
});
|
|
1692
|
-
if (resolver?.resolve)
|
|
1693
|
-
node = resolver.resolve(node, ctx);
|
|
1694
|
-
for (const k in node) {
|
|
1695
|
-
const v = node[k];
|
|
1696
|
-
if (typeof v === "object" && v?._resolver)
|
|
1697
|
-
node[k] = resolveRelation(v, ctx, v._resolver);
|
|
1698
|
-
}
|
|
1699
|
-
stripEmptyProperties(node);
|
|
1700
|
-
return node;
|
|
1701
|
-
}
|
|
1702
|
-
function resolveNodeId(node, ctx, resolver, resolveAsRoot = false) {
|
|
1703
|
-
const prefix = Array.isArray(resolver.idPrefix) ? resolver.idPrefix[0] : resolver.idPrefix;
|
|
1704
|
-
if (!prefix)
|
|
1705
|
-
return node;
|
|
1706
|
-
if (node["@id"] && !node["@id"].startsWith(ctx.meta.host)) {
|
|
1707
|
-
node["@id"] = prefixId(ctx.meta[prefix], node["@id"]);
|
|
1708
|
-
return node;
|
|
1709
|
-
}
|
|
1710
|
-
const rootId = Array.isArray(resolver.idPrefix) ? resolver.idPrefix?.[1] : void 0;
|
|
1711
|
-
if (resolveAsRoot && rootId) {
|
|
1712
|
-
node["@id"] = prefixId(ctx.meta[prefix], rootId);
|
|
1713
|
-
}
|
|
1714
|
-
if (!node["@id"]) {
|
|
1715
|
-
let alias = resolver?.alias;
|
|
1716
|
-
if (!alias) {
|
|
1717
|
-
const type = asArray(node["@type"])?.[0] || "";
|
|
1718
|
-
alias = type.toLowerCase();
|
|
1719
|
-
}
|
|
1720
|
-
const hashNodeData = {};
|
|
1721
|
-
Object.entries(node).forEach(([key, val]) => {
|
|
1722
|
-
if (!key.startsWith("_"))
|
|
1723
|
-
hashNodeData[key] = val;
|
|
1724
|
-
});
|
|
1725
|
-
node["@id"] = prefixId(ctx.meta[prefix], `#/schema/${alias}/${hashCode(JSON.stringify(hashNodeData))}`);
|
|
1726
|
-
}
|
|
1727
|
-
return node;
|
|
1728
|
-
}
|
|
1729
|
-
function resolveRelation(input, ctx, fallbackResolver, options = {}) {
|
|
1730
|
-
if (!input)
|
|
1731
|
-
return input;
|
|
1732
|
-
const ids = asArray(input).map((a) => {
|
|
1733
|
-
if (Object.keys(a).length === 1 && a["@id"])
|
|
1734
|
-
return a;
|
|
1735
|
-
let resolver = fallbackResolver;
|
|
1736
|
-
if (a._resolver) {
|
|
1737
|
-
resolver = a._resolver;
|
|
1738
|
-
if (typeof resolver === "string")
|
|
1739
|
-
resolver = loadResolver(resolver);
|
|
1740
|
-
delete a._resolver;
|
|
1741
|
-
}
|
|
1742
|
-
if (!resolver)
|
|
1743
|
-
return a;
|
|
1744
|
-
let node = resolveNode(a, ctx, resolver);
|
|
1745
|
-
if (options.afterResolve)
|
|
1746
|
-
options.afterResolve(node);
|
|
1747
|
-
if (options.generateId || options.root)
|
|
1748
|
-
node = resolveNodeId(node, ctx, resolver, false);
|
|
1749
|
-
if (options.root) {
|
|
1750
|
-
if (resolver.resolveRootNode)
|
|
1751
|
-
resolver.resolveRootNode(node, ctx);
|
|
1752
|
-
ctx.push(node);
|
|
1753
|
-
return idReference(node["@id"]);
|
|
1754
|
-
}
|
|
1755
|
-
return node;
|
|
1756
|
-
});
|
|
1757
|
-
if (!options.array && ids.length === 1)
|
|
1758
|
-
return ids[0];
|
|
1759
|
-
return ids;
|
|
1760
|
-
}
|
|
1761
|
-
|
|
1762
|
-
function isObject(value) {
|
|
1763
|
-
return value !== null && typeof value === "object";
|
|
1764
|
-
}
|
|
1765
|
-
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
1766
|
-
if (!isObject(defaults)) {
|
|
1767
|
-
return _defu(baseObject, {}, namespace, merger);
|
|
1768
|
-
}
|
|
1769
|
-
const object = Object.assign({}, defaults);
|
|
1770
|
-
for (const key in baseObject) {
|
|
1771
|
-
if (key === "__proto__" || key === "constructor") {
|
|
1772
|
-
continue;
|
|
1773
|
-
}
|
|
1774
|
-
const value = baseObject[key];
|
|
1775
|
-
if (value === null || value === void 0) {
|
|
1776
|
-
continue;
|
|
1777
|
-
}
|
|
1778
|
-
if (merger && merger(object, key, value, namespace)) {
|
|
1779
|
-
continue;
|
|
1780
|
-
}
|
|
1781
|
-
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
1782
|
-
object[key] = [...value, ...object[key]];
|
|
1783
|
-
} else if (isObject(value) && isObject(object[key])) {
|
|
1784
|
-
object[key] = _defu(
|
|
1785
|
-
value,
|
|
1786
|
-
object[key],
|
|
1787
|
-
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
1788
|
-
merger
|
|
1789
|
-
);
|
|
1790
|
-
} else {
|
|
1791
|
-
object[key] = value;
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
return object;
|
|
1795
|
-
}
|
|
1796
|
-
function createDefu(merger) {
|
|
1797
|
-
return (...arguments_) => (
|
|
1798
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
1799
|
-
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
1800
|
-
);
|
|
1801
|
-
}
|
|
1802
|
-
const defu = createDefu();
|
|
1803
|
-
|
|
1804
|
-
function groupBy(array, predicate) {
|
|
1805
|
-
return array.reduce((acc, value, index, array2) => {
|
|
1806
|
-
const key = predicate(value, index, array2);
|
|
1807
|
-
if (!acc[key])
|
|
1808
|
-
acc[key] = [];
|
|
1809
|
-
acc[key].push(value);
|
|
1810
|
-
return acc;
|
|
1811
|
-
}, {});
|
|
1812
|
-
}
|
|
1813
|
-
function dedupeNodes(nodes) {
|
|
1814
|
-
const dedupedNodes = {};
|
|
1815
|
-
for (const key of nodes.keys()) {
|
|
1816
|
-
const n = nodes[key];
|
|
1817
|
-
const nodeKey = resolveAsGraphKey(n["@id"] || hash(n));
|
|
1818
|
-
if (dedupedNodes[nodeKey])
|
|
1819
|
-
dedupedNodes[nodeKey] = defu(nodes[key], dedupedNodes[nodeKey]);
|
|
1820
|
-
else
|
|
1821
|
-
dedupedNodes[nodeKey] = nodes[key];
|
|
1822
|
-
}
|
|
1823
|
-
return Object.values(dedupedNodes);
|
|
1824
|
-
}
|
|
1825
|
-
function normaliseNodes(nodes) {
|
|
1826
|
-
const sortedNodeKeys = nodes.keys();
|
|
1827
|
-
const dedupedNodes = {};
|
|
1828
|
-
for (const key of sortedNodeKeys) {
|
|
1829
|
-
const n = nodes[key];
|
|
1830
|
-
const nodeKey = resolveAsGraphKey(n["@id"] || hash(n));
|
|
1831
|
-
const groupedKeys = groupBy(Object.keys(n), (key2) => {
|
|
1832
|
-
const val = n[key2];
|
|
1833
|
-
if (key2.startsWith("_"))
|
|
1834
|
-
return "ignored";
|
|
1835
|
-
if (Array.isArray(val) || typeof val === "object")
|
|
1836
|
-
return "relations";
|
|
1837
|
-
return "primitives";
|
|
1838
|
-
});
|
|
1839
|
-
const keys = [
|
|
1840
|
-
...(groupedKeys.primitives || []).sort(),
|
|
1841
|
-
...(groupedKeys.relations || []).sort()
|
|
1842
|
-
];
|
|
1843
|
-
let newNode = {};
|
|
1844
|
-
for (const key2 of keys)
|
|
1845
|
-
newNode[key2] = n[key2];
|
|
1846
|
-
if (dedupedNodes[nodeKey])
|
|
1847
|
-
newNode = defu(newNode, dedupedNodes[nodeKey]);
|
|
1848
|
-
dedupedNodes[nodeKey] = newNode;
|
|
1849
|
-
}
|
|
1850
|
-
return Object.values(dedupedNodes);
|
|
1851
|
-
}
|
|
1852
|
-
|
|
1853
|
-
function createSchemaOrgGraph() {
|
|
1854
|
-
const ctx = {
|
|
1855
|
-
find(id) {
|
|
1856
|
-
const key = resolveAsGraphKey(id);
|
|
1857
|
-
return ctx.nodes.filter((n) => !!n["@id"]).find((n) => resolveAsGraphKey(n["@id"]) === key);
|
|
1858
|
-
},
|
|
1859
|
-
push(input) {
|
|
1860
|
-
asArray(input).forEach((node) => {
|
|
1861
|
-
const registeredNode = node;
|
|
1862
|
-
ctx.nodes.push(registeredNode);
|
|
1863
|
-
});
|
|
1864
|
-
},
|
|
1865
|
-
resolveGraph(meta) {
|
|
1866
|
-
ctx.meta = resolveMeta({ ...meta });
|
|
1867
|
-
ctx.nodes.forEach((node, key) => {
|
|
1868
|
-
const resolver = node._resolver;
|
|
1869
|
-
if (resolver) {
|
|
1870
|
-
node = resolveNode(node, ctx, resolver);
|
|
1871
|
-
node = resolveNodeId(node, ctx, resolver, true);
|
|
1872
|
-
}
|
|
1873
|
-
ctx.nodes[key] = node;
|
|
1874
|
-
});
|
|
1875
|
-
ctx.nodes = dedupeNodes(ctx.nodes);
|
|
1876
|
-
ctx.nodes.forEach((node) => {
|
|
1877
|
-
if (node.image && typeof node.image === "string") {
|
|
1878
|
-
node.image = resolveRelation(node.image, ctx, imageResolver, {
|
|
1879
|
-
root: true
|
|
1880
|
-
});
|
|
1881
|
-
}
|
|
1882
|
-
if (node._resolver?.resolveRootNode)
|
|
1883
|
-
node._resolver.resolveRootNode(node, ctx);
|
|
1884
|
-
delete node._resolver;
|
|
1885
|
-
});
|
|
1886
|
-
return normaliseNodes(ctx.nodes);
|
|
1887
|
-
},
|
|
1888
|
-
nodes: [],
|
|
1889
|
-
meta: {}
|
|
1890
|
-
};
|
|
1891
|
-
return ctx;
|
|
1892
|
-
}
|
|
1893
|
-
|
|
1894
|
-
function SchemaOrgUnheadPlugin(config, meta) {
|
|
1895
|
-
config = resolveMeta({ ...config });
|
|
1896
|
-
let graph;
|
|
1897
|
-
const resolvedMeta = {};
|
|
1898
|
-
return {
|
|
1899
|
-
hooks: {
|
|
1900
|
-
"entries:resolve": function() {
|
|
1901
|
-
graph = createSchemaOrgGraph();
|
|
1902
|
-
},
|
|
1903
|
-
"tag:normalise": async function({ tag }) {
|
|
1904
|
-
if (tag.key === "schema-org-graph") {
|
|
1905
|
-
const { loadResolver } = await Promise.resolve().then(function () { return resolver; });
|
|
1906
|
-
const nodes = await tag.props.nodes;
|
|
1907
|
-
for (const node of Array.isArray(nodes) ? nodes : [nodes]) {
|
|
1908
|
-
const newNode = {
|
|
1909
|
-
...node,
|
|
1910
|
-
_resolver: loadResolver(await node._resolver)
|
|
1911
|
-
};
|
|
1912
|
-
graph.push(newNode);
|
|
1913
|
-
}
|
|
1914
|
-
tag.tagPosition = config.tagPosition === "head" ? "head" : "bodyClose";
|
|
1915
|
-
}
|
|
1916
|
-
if (tag.tag === "title")
|
|
1917
|
-
resolvedMeta.title = tag.textContent;
|
|
1918
|
-
else if (tag.tag === "meta" && tag.props.name === "description")
|
|
1919
|
-
resolvedMeta.description = tag.props.content;
|
|
1920
|
-
else if (tag.tag === "link" && tag.props.rel === "canonical")
|
|
1921
|
-
resolvedMeta.url = tag.props.href;
|
|
1922
|
-
else if (tag.tag === "meta" && tag.props.property === "og:image")
|
|
1923
|
-
resolvedMeta.image = tag.props.content;
|
|
1924
|
-
},
|
|
1925
|
-
"tags:resolve": async function(ctx) {
|
|
1926
|
-
for (const tag of ctx.tags) {
|
|
1927
|
-
if (tag.tag === "script" && tag.key === "schema-org-graph") {
|
|
1928
|
-
tag.innerHTML = JSON.stringify({
|
|
1929
|
-
"@context": "https://schema.org",
|
|
1930
|
-
"@graph": graph.resolveGraph({ ...config, ...resolvedMeta, ...await meta() })
|
|
1931
|
-
}, null, 2);
|
|
1932
|
-
delete tag.props.nodes;
|
|
1933
|
-
}
|
|
1934
|
-
}
|
|
1935
|
-
}
|
|
1936
|
-
}
|
|
1937
|
-
};
|
|
1938
|
-
}
|
|
3
|
+
import 'ufo';
|
|
4
|
+
import '@unhead/shared';
|
|
1939
5
|
|
|
1940
6
|
function provideResolver(input, resolver) {
|
|
1941
7
|
if (!input)
|
|
@@ -2054,7 +120,7 @@ function useSchemaOrg(input) {
|
|
|
2054
120
|
nodes: input
|
|
2055
121
|
}
|
|
2056
122
|
]
|
|
2057
|
-
}
|
|
123
|
+
});
|
|
2058
124
|
}
|
|
2059
125
|
|
|
2060
|
-
export {
|
|
126
|
+
export { defineAddress, defineAggregateOffer, defineAggregateRating, defineArticle, defineBook, defineBookEdition, defineBreadcrumb, defineComment, defineCourse, defineEvent, defineHowTo, defineHowToStep, defineImage, defineItemList, defineJobPosting, defineListItem, defineLocalBusiness, defineMovie, defineOffer, defineOpeningHours, defineOrganization, definePerson, definePlace, defineProduct, defineQuestion, defineReadAction, defineRecipe, defineReview, defineSearchAction, defineSoftwareApp, defineVideo, defineVirtualLocation, defineWebPage, defineWebSite, useSchemaOrg };
|