@unhead/schema-org 0.4.1 → 0.6.0
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/index.cjs +333 -170
- package/dist/index.d.ts +41 -40
- package/dist/index.mjs +318 -156
- package/package.json +6 -5
package/dist/index.mjs
CHANGED
|
@@ -1,83 +1,24 @@
|
|
|
1
|
+
import { hasProtocol, joinURL, withBase, withoutTrailingSlash, hasTrailingSlash, withTrailingSlash } from 'ufo';
|
|
1
2
|
import { useHead } from 'unhead';
|
|
2
3
|
|
|
3
4
|
function defineSchemaOrgResolver(schema) {
|
|
4
5
|
return schema;
|
|
5
6
|
}
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
const TRAILING_SLASH_RE = /\/$|\/\?/;
|
|
13
|
-
function hasTrailingSlash(input = "", queryParameters = false) {
|
|
14
|
-
if (!queryParameters) {
|
|
15
|
-
return input.endsWith("/");
|
|
16
|
-
}
|
|
17
|
-
return TRAILING_SLASH_RE.test(input);
|
|
18
|
-
}
|
|
19
|
-
function withoutTrailingSlash(input = "", queryParameters = false) {
|
|
20
|
-
if (!queryParameters) {
|
|
21
|
-
return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
|
|
22
|
-
}
|
|
23
|
-
if (!hasTrailingSlash(input, true)) {
|
|
24
|
-
return input || "/";
|
|
25
|
-
}
|
|
26
|
-
const [s0, ...s] = input.split("?");
|
|
27
|
-
return (s0.slice(0, -1) || "/") + (s.length > 0 ? `?${s.join("?")}` : "");
|
|
28
|
-
}
|
|
29
|
-
function withTrailingSlash(input = "", queryParameters = false) {
|
|
30
|
-
if (!queryParameters) {
|
|
31
|
-
return input.endsWith("/") ? input : input + "/";
|
|
32
|
-
}
|
|
33
|
-
if (hasTrailingSlash(input, true)) {
|
|
34
|
-
return input || "/";
|
|
35
|
-
}
|
|
36
|
-
const [s0, ...s] = input.split("?");
|
|
37
|
-
return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "");
|
|
38
|
-
}
|
|
39
|
-
function hasLeadingSlash(input = "") {
|
|
40
|
-
return input.startsWith("/");
|
|
41
|
-
}
|
|
42
|
-
function withoutLeadingSlash(input = "") {
|
|
43
|
-
return (hasLeadingSlash(input) ? input.slice(1) : input) || "/";
|
|
44
|
-
}
|
|
45
|
-
function withBase(input, base) {
|
|
46
|
-
if (isEmptyURL(base) || hasProtocol(input)) {
|
|
47
|
-
return input;
|
|
48
|
-
}
|
|
49
|
-
const _base = withoutTrailingSlash(base);
|
|
50
|
-
if (input.startsWith(_base)) {
|
|
51
|
-
return input;
|
|
52
|
-
}
|
|
53
|
-
return joinURL(_base, input);
|
|
54
|
-
}
|
|
55
|
-
function isEmptyURL(url) {
|
|
56
|
-
return !url || url === "/";
|
|
57
|
-
}
|
|
58
|
-
function isNonEmptyURL(url) {
|
|
59
|
-
return url && url !== "/";
|
|
60
|
-
}
|
|
61
|
-
function joinURL(base, ...input) {
|
|
62
|
-
let url = base || "";
|
|
63
|
-
for (const index of input.filter((url2) => isNonEmptyURL(url2))) {
|
|
64
|
-
url = url ? withTrailingSlash(url) + withoutLeadingSlash(index) : index;
|
|
65
|
-
}
|
|
66
|
-
return url;
|
|
8
|
+
function idReference(node) {
|
|
9
|
+
return {
|
|
10
|
+
"@id": typeof node !== "string" ? node["@id"] : node
|
|
11
|
+
};
|
|
67
12
|
}
|
|
68
|
-
|
|
69
|
-
const idReference = (node) => ({
|
|
70
|
-
"@id": typeof node !== "string" ? node["@id"] : node
|
|
71
|
-
});
|
|
72
|
-
const resolvableDateToDate = (val) => {
|
|
13
|
+
function resolvableDateToDate(val) {
|
|
73
14
|
try {
|
|
74
15
|
const date = val instanceof Date ? val : new Date(Date.parse(val));
|
|
75
16
|
return `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`;
|
|
76
17
|
} catch (e) {
|
|
77
18
|
}
|
|
78
19
|
return typeof val === "string" ? val : val.toString();
|
|
79
|
-
}
|
|
80
|
-
|
|
20
|
+
}
|
|
21
|
+
function resolvableDateToIso(val) {
|
|
81
22
|
if (!val)
|
|
82
23
|
return val;
|
|
83
24
|
try {
|
|
@@ -88,29 +29,31 @@ const resolvableDateToIso = (val) => {
|
|
|
88
29
|
} catch (e) {
|
|
89
30
|
}
|
|
90
31
|
return typeof val === "string" ? val : val.toString();
|
|
91
|
-
}
|
|
32
|
+
}
|
|
92
33
|
const IdentityId = "#identity";
|
|
93
|
-
|
|
34
|
+
function setIfEmpty(node, field, value) {
|
|
94
35
|
if (!node?.[field] && value)
|
|
95
36
|
node[field] = value;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
37
|
+
}
|
|
38
|
+
function asArray(input) {
|
|
39
|
+
return Array.isArray(input) ? input : [input];
|
|
40
|
+
}
|
|
41
|
+
function dedupeMerge(node, field, value) {
|
|
99
42
|
const dedupeMerge2 = [];
|
|
100
43
|
const input = asArray(node[field]);
|
|
101
44
|
dedupeMerge2.push(...input);
|
|
102
45
|
const data = new Set(dedupeMerge2);
|
|
103
46
|
data.add(value);
|
|
104
47
|
node[field] = [...data.values()].filter(Boolean);
|
|
105
|
-
}
|
|
106
|
-
|
|
48
|
+
}
|
|
49
|
+
function prefixId(url, id) {
|
|
107
50
|
if (hasProtocol(id))
|
|
108
51
|
return url;
|
|
109
52
|
if (!id.startsWith("#"))
|
|
110
53
|
id = `#${id}`;
|
|
111
54
|
return joinURL(url, id);
|
|
112
|
-
}
|
|
113
|
-
|
|
55
|
+
}
|
|
56
|
+
function trimLength(val, length) {
|
|
114
57
|
if (!val)
|
|
115
58
|
return val;
|
|
116
59
|
if (val.length > length) {
|
|
@@ -118,8 +61,8 @@ const trimLength = (val, length) => {
|
|
|
118
61
|
return trimmedString.substring(0, Math.min(trimmedString.length, trimmedString.lastIndexOf(" ")));
|
|
119
62
|
}
|
|
120
63
|
return val;
|
|
121
|
-
}
|
|
122
|
-
|
|
64
|
+
}
|
|
65
|
+
function resolveDefaultType(node, defaultType) {
|
|
123
66
|
const val = node["@type"];
|
|
124
67
|
if (val === defaultType)
|
|
125
68
|
return;
|
|
@@ -128,18 +71,18 @@ const resolveDefaultType = (node, defaultType) => {
|
|
|
128
71
|
...asArray(val)
|
|
129
72
|
]);
|
|
130
73
|
node["@type"] = types.size === 1 ? val : [...types.values()];
|
|
131
|
-
}
|
|
132
|
-
|
|
74
|
+
}
|
|
75
|
+
function resolveWithBase(base, urlOrPath) {
|
|
133
76
|
if (!urlOrPath || hasProtocol(urlOrPath) || !urlOrPath.startsWith("/") && !urlOrPath.startsWith("#"))
|
|
134
77
|
return urlOrPath;
|
|
135
78
|
return withBase(urlOrPath, base);
|
|
136
|
-
}
|
|
137
|
-
|
|
79
|
+
}
|
|
80
|
+
function resolveAsGraphKey(key) {
|
|
138
81
|
if (!key)
|
|
139
82
|
return key;
|
|
140
83
|
return key.substring(key.lastIndexOf("#"));
|
|
141
|
-
}
|
|
142
|
-
|
|
84
|
+
}
|
|
85
|
+
function stripEmptyProperties(obj) {
|
|
143
86
|
Object.keys(obj).forEach((k) => {
|
|
144
87
|
if (obj[k] && typeof obj[k] === "object") {
|
|
145
88
|
if (obj[k].__v_isReadonly || obj[k].__v_isRef)
|
|
@@ -151,7 +94,7 @@ const stripEmptyProperties = (obj) => {
|
|
|
151
94
|
delete obj[k];
|
|
152
95
|
});
|
|
153
96
|
return obj;
|
|
154
|
-
}
|
|
97
|
+
}
|
|
155
98
|
function hashCode(s) {
|
|
156
99
|
let h = 9;
|
|
157
100
|
for (let i = 0; i < s.length; )
|
|
@@ -174,7 +117,7 @@ const offerResolver = defineSchemaOrgResolver({
|
|
|
174
117
|
},
|
|
175
118
|
resolve(node, ctx) {
|
|
176
119
|
setIfEmpty(node, "priceCurrency", ctx.meta.currency);
|
|
177
|
-
setIfEmpty(node, "priceValidUntil", new Date(Date.UTC(new Date().getFullYear() + 1, 12, -1, 0, 0, 0)));
|
|
120
|
+
setIfEmpty(node, "priceValidUntil", new Date(Date.UTC((/* @__PURE__ */ new Date()).getFullYear() + 1, 12, -1, 0, 0, 0)));
|
|
178
121
|
if (node.url)
|
|
179
122
|
resolveWithBase(ctx.meta.host, node.url);
|
|
180
123
|
if (node.availability)
|
|
@@ -968,6 +911,9 @@ function createHasher(options) {
|
|
|
968
911
|
return this["_" + type](value);
|
|
969
912
|
},
|
|
970
913
|
_object(object) {
|
|
914
|
+
if (object && typeof object.toJSON === "function") {
|
|
915
|
+
return this._object(object.toJSON());
|
|
916
|
+
}
|
|
971
917
|
const pattern = /\[object (.*)]/i;
|
|
972
918
|
const objString = Object.prototype.toString.call(object);
|
|
973
919
|
const _objType = pattern.exec(objString);
|
|
@@ -985,10 +931,8 @@ function createHasher(options) {
|
|
|
985
931
|
if (objType !== "object" && objType !== "function" && objType !== "asyncfunction") {
|
|
986
932
|
if (this["_" + objType]) {
|
|
987
933
|
this["_" + objType](object);
|
|
988
|
-
} else if (options.ignoreUnknown) {
|
|
989
|
-
|
|
990
|
-
} else {
|
|
991
|
-
throw new Error('Unknown object type "' + objType + '"');
|
|
934
|
+
} else if (!options.ignoreUnknown) {
|
|
935
|
+
this._unkown(object, objType);
|
|
992
936
|
}
|
|
993
937
|
} else {
|
|
994
938
|
let keys = Object.keys(object);
|
|
@@ -1040,6 +984,20 @@ function createHasher(options) {
|
|
|
1040
984
|
_symbol(sym) {
|
|
1041
985
|
return write("symbol:" + sym.toString());
|
|
1042
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
|
+
},
|
|
1043
1001
|
_error(err) {
|
|
1044
1002
|
return write("error:" + err.toString());
|
|
1045
1003
|
},
|
|
@@ -1140,7 +1098,9 @@ function createHasher(options) {
|
|
|
1140
1098
|
if (options.ignoreUnknown) {
|
|
1141
1099
|
return write("[blob]");
|
|
1142
1100
|
}
|
|
1143
|
-
throw new Error(
|
|
1101
|
+
throw new Error(
|
|
1102
|
+
'Hashing Blob objects is currently not supported\nUse "options.replacer" or "options.ignoreUnknown"\n'
|
|
1103
|
+
);
|
|
1144
1104
|
},
|
|
1145
1105
|
_domwindow() {
|
|
1146
1106
|
return write("domwindow");
|
|
@@ -1148,6 +1108,7 @@ function createHasher(options) {
|
|
|
1148
1108
|
_bigint(number) {
|
|
1149
1109
|
return write("bigint:" + number.toString());
|
|
1150
1110
|
},
|
|
1111
|
+
/* Node.js standard native objects */
|
|
1151
1112
|
_process() {
|
|
1152
1113
|
return write("process");
|
|
1153
1114
|
},
|
|
@@ -1245,10 +1206,7 @@ const Hex = {
|
|
|
1245
1206
|
const hexChars = [];
|
|
1246
1207
|
for (let i = 0; i < wordArray.sigBytes; i++) {
|
|
1247
1208
|
const bite = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
|
1248
|
-
hexChars.push(
|
|
1249
|
-
(bite >>> 4).toString(16),
|
|
1250
|
-
(bite & 15).toString(16)
|
|
1251
|
-
);
|
|
1209
|
+
hexChars.push((bite >>> 4).toString(16), (bite & 15).toString(16));
|
|
1252
1210
|
}
|
|
1253
1211
|
return hexChars.join("");
|
|
1254
1212
|
}
|
|
@@ -1301,6 +1259,7 @@ class BufferedBlockAlgorithm {
|
|
|
1301
1259
|
this._data.concat(data);
|
|
1302
1260
|
this._nDataBytes += data.sigBytes;
|
|
1303
1261
|
}
|
|
1262
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1304
1263
|
_doProcessBlock(_dataWords, _offset) {
|
|
1305
1264
|
}
|
|
1306
1265
|
_process(doFlush) {
|
|
@@ -1336,8 +1295,82 @@ class Hasher extends BufferedBlockAlgorithm {
|
|
|
1336
1295
|
}
|
|
1337
1296
|
}
|
|
1338
1297
|
|
|
1339
|
-
const H = [
|
|
1340
|
-
|
|
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
|
+
];
|
|
1341
1374
|
const W = [];
|
|
1342
1375
|
class SHA256 extends Hasher {
|
|
1343
1376
|
constructor() {
|
|
@@ -1397,7 +1430,9 @@ class SHA256 extends Hasher {
|
|
|
1397
1430
|
const nBitsTotal = this._nDataBytes * 8;
|
|
1398
1431
|
const nBitsLeft = this._data.sigBytes * 8;
|
|
1399
1432
|
this._data.words[nBitsLeft >>> 5] |= 128 << 24 - nBitsLeft % 32;
|
|
1400
|
-
this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 14] = Math.floor(
|
|
1433
|
+
this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 14] = Math.floor(
|
|
1434
|
+
nBitsTotal / 4294967296
|
|
1435
|
+
);
|
|
1401
1436
|
this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 15] = nBitsTotal;
|
|
1402
1437
|
this._data.sigBytes = this._data.words.length * 4;
|
|
1403
1438
|
this._process();
|
|
@@ -1601,7 +1636,7 @@ const resolver = {
|
|
|
1601
1636
|
loadResolver: loadResolver
|
|
1602
1637
|
};
|
|
1603
1638
|
|
|
1604
|
-
|
|
1639
|
+
function resolveMeta(meta) {
|
|
1605
1640
|
if (!meta.host && meta.canonicalHost)
|
|
1606
1641
|
meta.host = meta.canonicalHost;
|
|
1607
1642
|
if (!meta.tagPosition && meta.position)
|
|
@@ -1635,8 +1670,8 @@ const resolveMeta = (meta) => {
|
|
|
1635
1670
|
datePublished: meta.datePublished,
|
|
1636
1671
|
dateModified: meta.dateModified
|
|
1637
1672
|
};
|
|
1638
|
-
}
|
|
1639
|
-
|
|
1673
|
+
}
|
|
1674
|
+
function resolveNode(node, ctx, resolver) {
|
|
1640
1675
|
if (resolver?.cast)
|
|
1641
1676
|
node = resolver.cast(node, ctx);
|
|
1642
1677
|
if (resolver?.defaults) {
|
|
@@ -1663,8 +1698,8 @@ const resolveNode = (node, ctx, resolver) => {
|
|
|
1663
1698
|
}
|
|
1664
1699
|
stripEmptyProperties(node);
|
|
1665
1700
|
return node;
|
|
1666
|
-
}
|
|
1667
|
-
|
|
1701
|
+
}
|
|
1702
|
+
function resolveNodeId(node, ctx, resolver, resolveAsRoot = false) {
|
|
1668
1703
|
const prefix = Array.isArray(resolver.idPrefix) ? resolver.idPrefix[0] : resolver.idPrefix;
|
|
1669
1704
|
if (!prefix)
|
|
1670
1705
|
return node;
|
|
@@ -1690,7 +1725,7 @@ const resolveNodeId = (node, ctx, resolver, resolveAsRoot = false) => {
|
|
|
1690
1725
|
node["@id"] = prefixId(ctx.meta[prefix], `#/schema/${alias}/${hashCode(JSON.stringify(hashNodeData))}`);
|
|
1691
1726
|
}
|
|
1692
1727
|
return node;
|
|
1693
|
-
}
|
|
1728
|
+
}
|
|
1694
1729
|
function resolveRelation(input, ctx, fallbackResolver, options = {}) {
|
|
1695
1730
|
if (!input)
|
|
1696
1731
|
return input;
|
|
@@ -1724,14 +1759,70 @@ function resolveRelation(input, ctx, fallbackResolver, options = {}) {
|
|
|
1724
1759
|
return ids;
|
|
1725
1760
|
}
|
|
1726
1761
|
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
}
|
|
1734
|
-
const
|
|
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) {
|
|
1735
1826
|
const sortedNodeKeys = nodes.keys();
|
|
1736
1827
|
const dedupedNodes = {};
|
|
1737
1828
|
for (const key of sortedNodeKeys) {
|
|
@@ -1749,15 +1840,17 @@ const dedupeNodes = (nodes) => {
|
|
|
1749
1840
|
...(groupedKeys.primitives || []).sort(),
|
|
1750
1841
|
...(groupedKeys.relations || []).sort()
|
|
1751
1842
|
];
|
|
1752
|
-
|
|
1843
|
+
let newNode = {};
|
|
1753
1844
|
for (const key2 of keys)
|
|
1754
1845
|
newNode[key2] = n[key2];
|
|
1846
|
+
if (dedupedNodes[nodeKey])
|
|
1847
|
+
newNode = defu(newNode, dedupedNodes[nodeKey]);
|
|
1755
1848
|
dedupedNodes[nodeKey] = newNode;
|
|
1756
1849
|
}
|
|
1757
1850
|
return Object.values(dedupedNodes);
|
|
1758
|
-
}
|
|
1851
|
+
}
|
|
1759
1852
|
|
|
1760
|
-
|
|
1853
|
+
function createSchemaOrgGraph() {
|
|
1761
1854
|
const ctx = {
|
|
1762
1855
|
find(id) {
|
|
1763
1856
|
const key = resolveAsGraphKey(id);
|
|
@@ -1779,6 +1872,7 @@ const createSchemaOrgGraph = () => {
|
|
|
1779
1872
|
}
|
|
1780
1873
|
ctx.nodes[key] = node;
|
|
1781
1874
|
});
|
|
1875
|
+
ctx.nodes = dedupeNodes(ctx.nodes);
|
|
1782
1876
|
ctx.nodes.forEach((node) => {
|
|
1783
1877
|
if (node.image && typeof node.image === "string") {
|
|
1784
1878
|
node.image = resolveRelation(node.image, ctx, imageResolver, {
|
|
@@ -1789,13 +1883,13 @@ const createSchemaOrgGraph = () => {
|
|
|
1789
1883
|
node._resolver.resolveRootNode(node, ctx);
|
|
1790
1884
|
delete node._resolver;
|
|
1791
1885
|
});
|
|
1792
|
-
return
|
|
1886
|
+
return normaliseNodes(ctx.nodes);
|
|
1793
1887
|
},
|
|
1794
1888
|
nodes: [],
|
|
1795
1889
|
meta: {}
|
|
1796
1890
|
};
|
|
1797
1891
|
return ctx;
|
|
1798
|
-
}
|
|
1892
|
+
}
|
|
1799
1893
|
|
|
1800
1894
|
function SchemaOrgUnheadPlugin(config, meta) {
|
|
1801
1895
|
config = resolveMeta({ ...config });
|
|
@@ -1820,7 +1914,7 @@ function SchemaOrgUnheadPlugin(config, meta) {
|
|
|
1820
1914
|
tag.tagPosition = config.tagPosition === "head" ? "head" : "bodyClose";
|
|
1821
1915
|
}
|
|
1822
1916
|
if (tag.tag === "title")
|
|
1823
|
-
resolvedMeta.title = tag.
|
|
1917
|
+
resolvedMeta.title = tag.textContent;
|
|
1824
1918
|
else if (tag.tag === "meta" && tag.props.name === "description")
|
|
1825
1919
|
resolvedMeta.description = tag.props.content;
|
|
1826
1920
|
else if (tag.tag === "link" && tag.props.rel === "canonical")
|
|
@@ -1831,7 +1925,7 @@ function SchemaOrgUnheadPlugin(config, meta) {
|
|
|
1831
1925
|
"tags:resolve": async function(ctx) {
|
|
1832
1926
|
for (const tag of ctx.tags) {
|
|
1833
1927
|
if (tag.tag === "script" && tag.key === "schema-org-graph") {
|
|
1834
|
-
tag.
|
|
1928
|
+
tag.innerHTML = JSON.stringify({
|
|
1835
1929
|
"@context": "https://schema.org",
|
|
1836
1930
|
"@graph": graph.resolveGraph({ ...config, ...resolvedMeta, ...await meta() })
|
|
1837
1931
|
}, null, 2);
|
|
@@ -1843,46 +1937,114 @@ function SchemaOrgUnheadPlugin(config, meta) {
|
|
|
1843
1937
|
};
|
|
1844
1938
|
}
|
|
1845
1939
|
|
|
1846
|
-
|
|
1940
|
+
function provideResolver(input, resolver) {
|
|
1847
1941
|
if (!input)
|
|
1848
1942
|
input = {};
|
|
1849
1943
|
input._resolver = resolver;
|
|
1850
1944
|
return input;
|
|
1851
|
-
}
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1945
|
+
}
|
|
1946
|
+
function defineAddress(input) {
|
|
1947
|
+
return provideResolver(input, "address");
|
|
1948
|
+
}
|
|
1949
|
+
function defineAggregateOffer(input) {
|
|
1950
|
+
return provideResolver(input, "aggregateOffer");
|
|
1951
|
+
}
|
|
1952
|
+
function defineAggregateRating(input) {
|
|
1953
|
+
return provideResolver(input, "aggregateRating");
|
|
1954
|
+
}
|
|
1955
|
+
function defineArticle(input) {
|
|
1956
|
+
return provideResolver(input, "article");
|
|
1957
|
+
}
|
|
1958
|
+
function defineBreadcrumb(input) {
|
|
1959
|
+
return provideResolver(input, "breadcrumb");
|
|
1960
|
+
}
|
|
1961
|
+
function defineComment(input) {
|
|
1962
|
+
return provideResolver(input, "comment");
|
|
1963
|
+
}
|
|
1964
|
+
function defineEvent(input) {
|
|
1965
|
+
return provideResolver(input, "event");
|
|
1966
|
+
}
|
|
1967
|
+
function defineVirtualLocation(input) {
|
|
1968
|
+
return provideResolver(input, "virtualLocation");
|
|
1969
|
+
}
|
|
1970
|
+
function definePlace(input) {
|
|
1971
|
+
return provideResolver(input, "place");
|
|
1972
|
+
}
|
|
1973
|
+
function defineHowTo(input) {
|
|
1974
|
+
return provideResolver(input, "howTo");
|
|
1975
|
+
}
|
|
1976
|
+
function defineHowToStep(input) {
|
|
1977
|
+
return provideResolver(input, "howToStep");
|
|
1978
|
+
}
|
|
1979
|
+
function defineImage(input) {
|
|
1980
|
+
return provideResolver(input, "image");
|
|
1981
|
+
}
|
|
1982
|
+
function defineJobPosting(input) {
|
|
1983
|
+
return provideResolver(input, "jobPosting");
|
|
1984
|
+
}
|
|
1985
|
+
function defineLocalBusiness(input) {
|
|
1986
|
+
return provideResolver(input, "localBusiness");
|
|
1987
|
+
}
|
|
1988
|
+
function defineOffer(input) {
|
|
1989
|
+
return provideResolver(input, "offer");
|
|
1990
|
+
}
|
|
1991
|
+
function defineOpeningHours(input) {
|
|
1992
|
+
return provideResolver(input, "openingHours");
|
|
1993
|
+
}
|
|
1994
|
+
function defineOrganization(input) {
|
|
1995
|
+
return provideResolver(input, "organization");
|
|
1996
|
+
}
|
|
1997
|
+
function definePerson(input) {
|
|
1998
|
+
return provideResolver(input, "person");
|
|
1999
|
+
}
|
|
2000
|
+
function defineProduct(input) {
|
|
2001
|
+
return provideResolver(input, "product");
|
|
2002
|
+
}
|
|
2003
|
+
function defineQuestion(input) {
|
|
2004
|
+
return provideResolver(input, "question");
|
|
2005
|
+
}
|
|
2006
|
+
function defineRecipe(input) {
|
|
2007
|
+
return provideResolver(input, "recipe");
|
|
2008
|
+
}
|
|
2009
|
+
function defineReview(input) {
|
|
2010
|
+
return provideResolver(input, "review");
|
|
2011
|
+
}
|
|
2012
|
+
function defineVideo(input) {
|
|
2013
|
+
return provideResolver(input, "video");
|
|
2014
|
+
}
|
|
2015
|
+
function defineWebPage(input) {
|
|
2016
|
+
return provideResolver(input, "webPage");
|
|
2017
|
+
}
|
|
2018
|
+
function defineWebSite(input) {
|
|
2019
|
+
return provideResolver(input, "webSite");
|
|
2020
|
+
}
|
|
2021
|
+
function defineBook(input) {
|
|
2022
|
+
return provideResolver(input, "book");
|
|
2023
|
+
}
|
|
2024
|
+
function defineCourse(input) {
|
|
2025
|
+
return provideResolver(input, "course");
|
|
2026
|
+
}
|
|
2027
|
+
function defineItemList(input) {
|
|
2028
|
+
return provideResolver(input, "itemList");
|
|
2029
|
+
}
|
|
2030
|
+
function defineListItem(input) {
|
|
2031
|
+
return provideResolver(input, "listItem");
|
|
2032
|
+
}
|
|
2033
|
+
function defineMovie(input) {
|
|
2034
|
+
return provideResolver(input, "movie");
|
|
2035
|
+
}
|
|
2036
|
+
function defineSearchAction(input) {
|
|
2037
|
+
return provideResolver(input, "searchAction");
|
|
2038
|
+
}
|
|
2039
|
+
function defineReadAction(input) {
|
|
2040
|
+
return provideResolver(input, "readAction");
|
|
2041
|
+
}
|
|
2042
|
+
function defineSoftwareApp(input) {
|
|
2043
|
+
return provideResolver(input, "softwareApp");
|
|
2044
|
+
}
|
|
2045
|
+
function defineBookEdition(input) {
|
|
2046
|
+
return provideResolver(input, "bookEdition");
|
|
2047
|
+
}
|
|
1886
2048
|
function useSchemaOrg(input) {
|
|
1887
2049
|
return useHead({
|
|
1888
2050
|
script: [
|
|
@@ -1895,4 +2057,4 @@ function useSchemaOrg(input) {
|
|
|
1895
2057
|
}, { mode: process.env.NODE_ENV === "development" ? "all" : "server" });
|
|
1896
2058
|
}
|
|
1897
2059
|
|
|
1898
|
-
export { HowToId, PrimaryArticleId, PrimaryBookId, PrimaryBreadcrumbId, PrimaryEventId, PrimaryWebPageId, PrimaryWebSiteId, ProductId, RecipeId, SchemaOrgUnheadPlugin, addressResolver, aggregateOfferResolver, aggregateRatingResolver, articleResolver, bookEditionResolver, bookResolver, breadcrumbResolver, commentResolver, courseResolver, createSchemaOrgGraph, dedupeNodes, 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, defineSchemaOrgResolver, defineSearchAction, defineSoftwareApp, defineVideo, defineVirtualLocation, defineWebPage, defineWebSite, eventResolver, howToResolver, howToStepDirectionResolver, howToStepResolver, imageResolver, itemListResolver, jobPostingResolver, listItemResolver, localBusinessResolver, movieResolver, offerResolver, openingHoursResolver, organizationResolver, personResolver, placeResolver, productResolver, questionResolver, ratingResolver, readActionResolver, recipeResolver, resolveMeta, resolveNode, resolveNodeId, resolveRelation, reviewResolver, searchActionResolver, softwareAppResolver, useSchemaOrg, videoResolver, virtualLocationResolver, webPageResolver, webSiteResolver };
|
|
2060
|
+
export { HowToId, PrimaryArticleId, PrimaryBookId, PrimaryBreadcrumbId, PrimaryEventId, PrimaryWebPageId, PrimaryWebSiteId, ProductId, RecipeId, SchemaOrgUnheadPlugin, addressResolver, aggregateOfferResolver, aggregateRatingResolver, articleResolver, bookEditionResolver, bookResolver, breadcrumbResolver, commentResolver, courseResolver, createSchemaOrgGraph, dedupeNodes, 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, defineSchemaOrgResolver, defineSearchAction, defineSoftwareApp, defineVideo, defineVirtualLocation, defineWebPage, defineWebSite, eventResolver, howToResolver, howToStepDirectionResolver, howToStepResolver, imageResolver, itemListResolver, jobPostingResolver, listItemResolver, localBusinessResolver, movieResolver, normaliseNodes, offerResolver, openingHoursResolver, organizationResolver, personResolver, placeResolver, productResolver, questionResolver, ratingResolver, readActionResolver, recipeResolver, resolveMeta, resolveNode, resolveNodeId, resolveRelation, reviewResolver, searchActionResolver, softwareAppResolver, useSchemaOrg, videoResolver, virtualLocationResolver, webPageResolver, webSiteResolver };
|