@unhead/schema-org 0.5.0 → 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 +330 -174
- package/dist/index.d.ts +41 -40
- package/dist/index.mjs +315 -160
- package/package.json +5 -4
package/dist/index.mjs
CHANGED
|
@@ -1,90 +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
|
-
if (typeof opts === "boolean") {
|
|
12
|
-
opts = { acceptRelative: opts };
|
|
13
|
-
}
|
|
14
|
-
if (opts.strict) {
|
|
15
|
-
return PROTOCOL_STRICT_REGEX.test(inputString);
|
|
16
|
-
}
|
|
17
|
-
return PROTOCOL_REGEX.test(inputString) || (opts.acceptRelative ? PROTOCOL_RELATIVE_REGEX.test(inputString) : false);
|
|
18
|
-
}
|
|
19
|
-
const TRAILING_SLASH_RE = /\/$|\/\?/;
|
|
20
|
-
function hasTrailingSlash(input = "", queryParameters = false) {
|
|
21
|
-
if (!queryParameters) {
|
|
22
|
-
return input.endsWith("/");
|
|
23
|
-
}
|
|
24
|
-
return TRAILING_SLASH_RE.test(input);
|
|
25
|
-
}
|
|
26
|
-
function withoutTrailingSlash(input = "", queryParameters = false) {
|
|
27
|
-
if (!queryParameters) {
|
|
28
|
-
return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
|
|
29
|
-
}
|
|
30
|
-
if (!hasTrailingSlash(input, true)) {
|
|
31
|
-
return input || "/";
|
|
32
|
-
}
|
|
33
|
-
const [s0, ...s] = input.split("?");
|
|
34
|
-
return (s0.slice(0, -1) || "/") + (s.length > 0 ? `?${s.join("?")}` : "");
|
|
35
|
-
}
|
|
36
|
-
function withTrailingSlash(input = "", queryParameters = false) {
|
|
37
|
-
if (!queryParameters) {
|
|
38
|
-
return input.endsWith("/") ? input : input + "/";
|
|
39
|
-
}
|
|
40
|
-
if (hasTrailingSlash(input, true)) {
|
|
41
|
-
return input || "/";
|
|
42
|
-
}
|
|
43
|
-
const [s0, ...s] = input.split("?");
|
|
44
|
-
return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "");
|
|
45
|
-
}
|
|
46
|
-
function hasLeadingSlash(input = "") {
|
|
47
|
-
return input.startsWith("/");
|
|
48
|
-
}
|
|
49
|
-
function withoutLeadingSlash(input = "") {
|
|
50
|
-
return (hasLeadingSlash(input) ? input.slice(1) : input) || "/";
|
|
51
|
-
}
|
|
52
|
-
function withBase(input, base) {
|
|
53
|
-
if (isEmptyURL(base) || hasProtocol(input)) {
|
|
54
|
-
return input;
|
|
55
|
-
}
|
|
56
|
-
const _base = withoutTrailingSlash(base);
|
|
57
|
-
if (input.startsWith(_base)) {
|
|
58
|
-
return input;
|
|
59
|
-
}
|
|
60
|
-
return joinURL(_base, input);
|
|
61
|
-
}
|
|
62
|
-
function isEmptyURL(url) {
|
|
63
|
-
return !url || url === "/";
|
|
64
|
-
}
|
|
65
|
-
function isNonEmptyURL(url) {
|
|
66
|
-
return url && url !== "/";
|
|
67
|
-
}
|
|
68
|
-
function joinURL(base, ...input) {
|
|
69
|
-
let url = base || "";
|
|
70
|
-
for (const index of input.filter((url2) => isNonEmptyURL(url2))) {
|
|
71
|
-
url = url ? withTrailingSlash(url) + withoutLeadingSlash(index) : index;
|
|
72
|
-
}
|
|
73
|
-
return url;
|
|
8
|
+
function idReference(node) {
|
|
9
|
+
return {
|
|
10
|
+
"@id": typeof node !== "string" ? node["@id"] : node
|
|
11
|
+
};
|
|
74
12
|
}
|
|
75
|
-
|
|
76
|
-
const idReference = (node) => ({
|
|
77
|
-
"@id": typeof node !== "string" ? node["@id"] : node
|
|
78
|
-
});
|
|
79
|
-
const resolvableDateToDate = (val) => {
|
|
13
|
+
function resolvableDateToDate(val) {
|
|
80
14
|
try {
|
|
81
15
|
const date = val instanceof Date ? val : new Date(Date.parse(val));
|
|
82
16
|
return `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`;
|
|
83
17
|
} catch (e) {
|
|
84
18
|
}
|
|
85
19
|
return typeof val === "string" ? val : val.toString();
|
|
86
|
-
}
|
|
87
|
-
|
|
20
|
+
}
|
|
21
|
+
function resolvableDateToIso(val) {
|
|
88
22
|
if (!val)
|
|
89
23
|
return val;
|
|
90
24
|
try {
|
|
@@ -95,29 +29,31 @@ const resolvableDateToIso = (val) => {
|
|
|
95
29
|
} catch (e) {
|
|
96
30
|
}
|
|
97
31
|
return typeof val === "string" ? val : val.toString();
|
|
98
|
-
}
|
|
32
|
+
}
|
|
99
33
|
const IdentityId = "#identity";
|
|
100
|
-
|
|
34
|
+
function setIfEmpty(node, field, value) {
|
|
101
35
|
if (!node?.[field] && value)
|
|
102
36
|
node[field] = value;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
37
|
+
}
|
|
38
|
+
function asArray(input) {
|
|
39
|
+
return Array.isArray(input) ? input : [input];
|
|
40
|
+
}
|
|
41
|
+
function dedupeMerge(node, field, value) {
|
|
106
42
|
const dedupeMerge2 = [];
|
|
107
43
|
const input = asArray(node[field]);
|
|
108
44
|
dedupeMerge2.push(...input);
|
|
109
45
|
const data = new Set(dedupeMerge2);
|
|
110
46
|
data.add(value);
|
|
111
47
|
node[field] = [...data.values()].filter(Boolean);
|
|
112
|
-
}
|
|
113
|
-
|
|
48
|
+
}
|
|
49
|
+
function prefixId(url, id) {
|
|
114
50
|
if (hasProtocol(id))
|
|
115
51
|
return url;
|
|
116
52
|
if (!id.startsWith("#"))
|
|
117
53
|
id = `#${id}`;
|
|
118
54
|
return joinURL(url, id);
|
|
119
|
-
}
|
|
120
|
-
|
|
55
|
+
}
|
|
56
|
+
function trimLength(val, length) {
|
|
121
57
|
if (!val)
|
|
122
58
|
return val;
|
|
123
59
|
if (val.length > length) {
|
|
@@ -125,8 +61,8 @@ const trimLength = (val, length) => {
|
|
|
125
61
|
return trimmedString.substring(0, Math.min(trimmedString.length, trimmedString.lastIndexOf(" ")));
|
|
126
62
|
}
|
|
127
63
|
return val;
|
|
128
|
-
}
|
|
129
|
-
|
|
64
|
+
}
|
|
65
|
+
function resolveDefaultType(node, defaultType) {
|
|
130
66
|
const val = node["@type"];
|
|
131
67
|
if (val === defaultType)
|
|
132
68
|
return;
|
|
@@ -135,18 +71,18 @@ const resolveDefaultType = (node, defaultType) => {
|
|
|
135
71
|
...asArray(val)
|
|
136
72
|
]);
|
|
137
73
|
node["@type"] = types.size === 1 ? val : [...types.values()];
|
|
138
|
-
}
|
|
139
|
-
|
|
74
|
+
}
|
|
75
|
+
function resolveWithBase(base, urlOrPath) {
|
|
140
76
|
if (!urlOrPath || hasProtocol(urlOrPath) || !urlOrPath.startsWith("/") && !urlOrPath.startsWith("#"))
|
|
141
77
|
return urlOrPath;
|
|
142
78
|
return withBase(urlOrPath, base);
|
|
143
|
-
}
|
|
144
|
-
|
|
79
|
+
}
|
|
80
|
+
function resolveAsGraphKey(key) {
|
|
145
81
|
if (!key)
|
|
146
82
|
return key;
|
|
147
83
|
return key.substring(key.lastIndexOf("#"));
|
|
148
|
-
}
|
|
149
|
-
|
|
84
|
+
}
|
|
85
|
+
function stripEmptyProperties(obj) {
|
|
150
86
|
Object.keys(obj).forEach((k) => {
|
|
151
87
|
if (obj[k] && typeof obj[k] === "object") {
|
|
152
88
|
if (obj[k].__v_isReadonly || obj[k].__v_isRef)
|
|
@@ -158,7 +94,7 @@ const stripEmptyProperties = (obj) => {
|
|
|
158
94
|
delete obj[k];
|
|
159
95
|
});
|
|
160
96
|
return obj;
|
|
161
|
-
}
|
|
97
|
+
}
|
|
162
98
|
function hashCode(s) {
|
|
163
99
|
let h = 9;
|
|
164
100
|
for (let i = 0; i < s.length; )
|
|
@@ -975,6 +911,9 @@ function createHasher(options) {
|
|
|
975
911
|
return this["_" + type](value);
|
|
976
912
|
},
|
|
977
913
|
_object(object) {
|
|
914
|
+
if (object && typeof object.toJSON === "function") {
|
|
915
|
+
return this._object(object.toJSON());
|
|
916
|
+
}
|
|
978
917
|
const pattern = /\[object (.*)]/i;
|
|
979
918
|
const objString = Object.prototype.toString.call(object);
|
|
980
919
|
const _objType = pattern.exec(objString);
|
|
@@ -992,10 +931,8 @@ function createHasher(options) {
|
|
|
992
931
|
if (objType !== "object" && objType !== "function" && objType !== "asyncfunction") {
|
|
993
932
|
if (this["_" + objType]) {
|
|
994
933
|
this["_" + objType](object);
|
|
995
|
-
} else if (options.ignoreUnknown) {
|
|
996
|
-
|
|
997
|
-
} else {
|
|
998
|
-
throw new Error('Unknown object type "' + objType + '"');
|
|
934
|
+
} else if (!options.ignoreUnknown) {
|
|
935
|
+
this._unkown(object, objType);
|
|
999
936
|
}
|
|
1000
937
|
} else {
|
|
1001
938
|
let keys = Object.keys(object);
|
|
@@ -1047,6 +984,20 @@ function createHasher(options) {
|
|
|
1047
984
|
_symbol(sym) {
|
|
1048
985
|
return write("symbol:" + sym.toString());
|
|
1049
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
|
+
},
|
|
1050
1001
|
_error(err) {
|
|
1051
1002
|
return write("error:" + err.toString());
|
|
1052
1003
|
},
|
|
@@ -1147,7 +1098,9 @@ function createHasher(options) {
|
|
|
1147
1098
|
if (options.ignoreUnknown) {
|
|
1148
1099
|
return write("[blob]");
|
|
1149
1100
|
}
|
|
1150
|
-
throw new Error(
|
|
1101
|
+
throw new Error(
|
|
1102
|
+
'Hashing Blob objects is currently not supported\nUse "options.replacer" or "options.ignoreUnknown"\n'
|
|
1103
|
+
);
|
|
1151
1104
|
},
|
|
1152
1105
|
_domwindow() {
|
|
1153
1106
|
return write("domwindow");
|
|
@@ -1155,6 +1108,7 @@ function createHasher(options) {
|
|
|
1155
1108
|
_bigint(number) {
|
|
1156
1109
|
return write("bigint:" + number.toString());
|
|
1157
1110
|
},
|
|
1111
|
+
/* Node.js standard native objects */
|
|
1158
1112
|
_process() {
|
|
1159
1113
|
return write("process");
|
|
1160
1114
|
},
|
|
@@ -1252,10 +1206,7 @@ const Hex = {
|
|
|
1252
1206
|
const hexChars = [];
|
|
1253
1207
|
for (let i = 0; i < wordArray.sigBytes; i++) {
|
|
1254
1208
|
const bite = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
|
1255
|
-
hexChars.push(
|
|
1256
|
-
(bite >>> 4).toString(16),
|
|
1257
|
-
(bite & 15).toString(16)
|
|
1258
|
-
);
|
|
1209
|
+
hexChars.push((bite >>> 4).toString(16), (bite & 15).toString(16));
|
|
1259
1210
|
}
|
|
1260
1211
|
return hexChars.join("");
|
|
1261
1212
|
}
|
|
@@ -1308,6 +1259,7 @@ class BufferedBlockAlgorithm {
|
|
|
1308
1259
|
this._data.concat(data);
|
|
1309
1260
|
this._nDataBytes += data.sigBytes;
|
|
1310
1261
|
}
|
|
1262
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1311
1263
|
_doProcessBlock(_dataWords, _offset) {
|
|
1312
1264
|
}
|
|
1313
1265
|
_process(doFlush) {
|
|
@@ -1343,8 +1295,82 @@ class Hasher extends BufferedBlockAlgorithm {
|
|
|
1343
1295
|
}
|
|
1344
1296
|
}
|
|
1345
1297
|
|
|
1346
|
-
const H = [
|
|
1347
|
-
|
|
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
|
+
];
|
|
1348
1374
|
const W = [];
|
|
1349
1375
|
class SHA256 extends Hasher {
|
|
1350
1376
|
constructor() {
|
|
@@ -1404,7 +1430,9 @@ class SHA256 extends Hasher {
|
|
|
1404
1430
|
const nBitsTotal = this._nDataBytes * 8;
|
|
1405
1431
|
const nBitsLeft = this._data.sigBytes * 8;
|
|
1406
1432
|
this._data.words[nBitsLeft >>> 5] |= 128 << 24 - nBitsLeft % 32;
|
|
1407
|
-
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
|
+
);
|
|
1408
1436
|
this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 15] = nBitsTotal;
|
|
1409
1437
|
this._data.sigBytes = this._data.words.length * 4;
|
|
1410
1438
|
this._process();
|
|
@@ -1608,7 +1636,7 @@ const resolver = {
|
|
|
1608
1636
|
loadResolver: loadResolver
|
|
1609
1637
|
};
|
|
1610
1638
|
|
|
1611
|
-
|
|
1639
|
+
function resolveMeta(meta) {
|
|
1612
1640
|
if (!meta.host && meta.canonicalHost)
|
|
1613
1641
|
meta.host = meta.canonicalHost;
|
|
1614
1642
|
if (!meta.tagPosition && meta.position)
|
|
@@ -1642,8 +1670,8 @@ const resolveMeta = (meta) => {
|
|
|
1642
1670
|
datePublished: meta.datePublished,
|
|
1643
1671
|
dateModified: meta.dateModified
|
|
1644
1672
|
};
|
|
1645
|
-
}
|
|
1646
|
-
|
|
1673
|
+
}
|
|
1674
|
+
function resolveNode(node, ctx, resolver) {
|
|
1647
1675
|
if (resolver?.cast)
|
|
1648
1676
|
node = resolver.cast(node, ctx);
|
|
1649
1677
|
if (resolver?.defaults) {
|
|
@@ -1670,8 +1698,8 @@ const resolveNode = (node, ctx, resolver) => {
|
|
|
1670
1698
|
}
|
|
1671
1699
|
stripEmptyProperties(node);
|
|
1672
1700
|
return node;
|
|
1673
|
-
}
|
|
1674
|
-
|
|
1701
|
+
}
|
|
1702
|
+
function resolveNodeId(node, ctx, resolver, resolveAsRoot = false) {
|
|
1675
1703
|
const prefix = Array.isArray(resolver.idPrefix) ? resolver.idPrefix[0] : resolver.idPrefix;
|
|
1676
1704
|
if (!prefix)
|
|
1677
1705
|
return node;
|
|
@@ -1697,7 +1725,7 @@ const resolveNodeId = (node, ctx, resolver, resolveAsRoot = false) => {
|
|
|
1697
1725
|
node["@id"] = prefixId(ctx.meta[prefix], `#/schema/${alias}/${hashCode(JSON.stringify(hashNodeData))}`);
|
|
1698
1726
|
}
|
|
1699
1727
|
return node;
|
|
1700
|
-
}
|
|
1728
|
+
}
|
|
1701
1729
|
function resolveRelation(input, ctx, fallbackResolver, options = {}) {
|
|
1702
1730
|
if (!input)
|
|
1703
1731
|
return input;
|
|
@@ -1731,14 +1759,70 @@ function resolveRelation(input, ctx, fallbackResolver, options = {}) {
|
|
|
1731
1759
|
return ids;
|
|
1732
1760
|
}
|
|
1733
1761
|
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
}
|
|
1741
|
-
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) {
|
|
1742
1826
|
const sortedNodeKeys = nodes.keys();
|
|
1743
1827
|
const dedupedNodes = {};
|
|
1744
1828
|
for (const key of sortedNodeKeys) {
|
|
@@ -1756,15 +1840,17 @@ const dedupeNodes = (nodes) => {
|
|
|
1756
1840
|
...(groupedKeys.primitives || []).sort(),
|
|
1757
1841
|
...(groupedKeys.relations || []).sort()
|
|
1758
1842
|
];
|
|
1759
|
-
|
|
1843
|
+
let newNode = {};
|
|
1760
1844
|
for (const key2 of keys)
|
|
1761
1845
|
newNode[key2] = n[key2];
|
|
1846
|
+
if (dedupedNodes[nodeKey])
|
|
1847
|
+
newNode = defu(newNode, dedupedNodes[nodeKey]);
|
|
1762
1848
|
dedupedNodes[nodeKey] = newNode;
|
|
1763
1849
|
}
|
|
1764
1850
|
return Object.values(dedupedNodes);
|
|
1765
|
-
}
|
|
1851
|
+
}
|
|
1766
1852
|
|
|
1767
|
-
|
|
1853
|
+
function createSchemaOrgGraph() {
|
|
1768
1854
|
const ctx = {
|
|
1769
1855
|
find(id) {
|
|
1770
1856
|
const key = resolveAsGraphKey(id);
|
|
@@ -1786,6 +1872,7 @@ const createSchemaOrgGraph = () => {
|
|
|
1786
1872
|
}
|
|
1787
1873
|
ctx.nodes[key] = node;
|
|
1788
1874
|
});
|
|
1875
|
+
ctx.nodes = dedupeNodes(ctx.nodes);
|
|
1789
1876
|
ctx.nodes.forEach((node) => {
|
|
1790
1877
|
if (node.image && typeof node.image === "string") {
|
|
1791
1878
|
node.image = resolveRelation(node.image, ctx, imageResolver, {
|
|
@@ -1796,13 +1883,13 @@ const createSchemaOrgGraph = () => {
|
|
|
1796
1883
|
node._resolver.resolveRootNode(node, ctx);
|
|
1797
1884
|
delete node._resolver;
|
|
1798
1885
|
});
|
|
1799
|
-
return
|
|
1886
|
+
return normaliseNodes(ctx.nodes);
|
|
1800
1887
|
},
|
|
1801
1888
|
nodes: [],
|
|
1802
1889
|
meta: {}
|
|
1803
1890
|
};
|
|
1804
1891
|
return ctx;
|
|
1805
|
-
}
|
|
1892
|
+
}
|
|
1806
1893
|
|
|
1807
1894
|
function SchemaOrgUnheadPlugin(config, meta) {
|
|
1808
1895
|
config = resolveMeta({ ...config });
|
|
@@ -1850,46 +1937,114 @@ function SchemaOrgUnheadPlugin(config, meta) {
|
|
|
1850
1937
|
};
|
|
1851
1938
|
}
|
|
1852
1939
|
|
|
1853
|
-
|
|
1940
|
+
function provideResolver(input, resolver) {
|
|
1854
1941
|
if (!input)
|
|
1855
1942
|
input = {};
|
|
1856
1943
|
input._resolver = resolver;
|
|
1857
1944
|
return input;
|
|
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
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
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
|
+
}
|
|
1893
2048
|
function useSchemaOrg(input) {
|
|
1894
2049
|
return useHead({
|
|
1895
2050
|
script: [
|
|
@@ -1902,4 +2057,4 @@ function useSchemaOrg(input) {
|
|
|
1902
2057
|
}, { mode: process.env.NODE_ENV === "development" ? "all" : "server" });
|
|
1903
2058
|
}
|
|
1904
2059
|
|
|
1905
|
-
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 };
|