@unhead/schema-org 1.11.9 → 1.11.11

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.
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const ufo = require('ufo');
4
+ const ohash = require('ohash');
4
5
 
5
6
  function defineSchemaOrgResolver(schema) {
6
7
  return schema;
@@ -993,632 +994,6 @@ const movieResolver = defineSchemaOrgResolver({
993
994
  }
994
995
  });
995
996
 
996
- const defaults = Object.freeze({
997
- ignoreUnknown: false,
998
- respectType: false,
999
- respectFunctionNames: false,
1000
- respectFunctionProperties: false,
1001
- unorderedObjects: true,
1002
- unorderedArrays: false,
1003
- unorderedSets: false,
1004
- excludeKeys: void 0,
1005
- excludeValues: void 0,
1006
- replacer: void 0
1007
- });
1008
- function objectHash(object, options) {
1009
- if (options) {
1010
- options = { ...defaults, ...options };
1011
- } else {
1012
- options = defaults;
1013
- }
1014
- const hasher = createHasher(options);
1015
- hasher.dispatch(object);
1016
- return hasher.toString();
1017
- }
1018
- const defaultPrototypesKeys = Object.freeze([
1019
- "prototype",
1020
- "__proto__",
1021
- "constructor"
1022
- ]);
1023
- function createHasher(options) {
1024
- let buff = "";
1025
- let context = /* @__PURE__ */ new Map();
1026
- const write = (str) => {
1027
- buff += str;
1028
- };
1029
- return {
1030
- toString() {
1031
- return buff;
1032
- },
1033
- getContext() {
1034
- return context;
1035
- },
1036
- dispatch(value) {
1037
- if (options.replacer) {
1038
- value = options.replacer(value);
1039
- }
1040
- const type = value === null ? "null" : typeof value;
1041
- return this[type](value);
1042
- },
1043
- object(object) {
1044
- if (object && typeof object.toJSON === "function") {
1045
- return this.object(object.toJSON());
1046
- }
1047
- const objString = Object.prototype.toString.call(object);
1048
- let objType = "";
1049
- const objectLength = objString.length;
1050
- if (objectLength < 10) {
1051
- objType = "unknown:[" + objString + "]";
1052
- } else {
1053
- objType = objString.slice(8, objectLength - 1);
1054
- }
1055
- objType = objType.toLowerCase();
1056
- let objectNumber = null;
1057
- if ((objectNumber = context.get(object)) === void 0) {
1058
- context.set(object, context.size);
1059
- } else {
1060
- return this.dispatch("[CIRCULAR:" + objectNumber + "]");
1061
- }
1062
- if (typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(object)) {
1063
- write("buffer:");
1064
- return write(object.toString("utf8"));
1065
- }
1066
- if (objType !== "object" && objType !== "function" && objType !== "asyncfunction") {
1067
- if (this[objType]) {
1068
- this[objType](object);
1069
- } else if (!options.ignoreUnknown) {
1070
- this.unkown(object, objType);
1071
- }
1072
- } else {
1073
- let keys = Object.keys(object);
1074
- if (options.unorderedObjects) {
1075
- keys = keys.sort();
1076
- }
1077
- let extraKeys = [];
1078
- if (options.respectType !== false && !isNativeFunction(object)) {
1079
- extraKeys = defaultPrototypesKeys;
1080
- }
1081
- if (options.excludeKeys) {
1082
- keys = keys.filter((key) => {
1083
- return !options.excludeKeys(key);
1084
- });
1085
- extraKeys = extraKeys.filter((key) => {
1086
- return !options.excludeKeys(key);
1087
- });
1088
- }
1089
- write("object:" + (keys.length + extraKeys.length) + ":");
1090
- const dispatchForKey = (key) => {
1091
- this.dispatch(key);
1092
- write(":");
1093
- if (!options.excludeValues) {
1094
- this.dispatch(object[key]);
1095
- }
1096
- write(",");
1097
- };
1098
- for (const key of keys) {
1099
- dispatchForKey(key);
1100
- }
1101
- for (const key of extraKeys) {
1102
- dispatchForKey(key);
1103
- }
1104
- }
1105
- },
1106
- array(arr, unordered) {
1107
- unordered = unordered === void 0 ? options.unorderedArrays !== false : unordered;
1108
- write("array:" + arr.length + ":");
1109
- if (!unordered || arr.length <= 1) {
1110
- for (const entry of arr) {
1111
- this.dispatch(entry);
1112
- }
1113
- return;
1114
- }
1115
- const contextAdditions = /* @__PURE__ */ new Map();
1116
- const entries = arr.map((entry) => {
1117
- const hasher = createHasher(options);
1118
- hasher.dispatch(entry);
1119
- for (const [key, value] of hasher.getContext()) {
1120
- contextAdditions.set(key, value);
1121
- }
1122
- return hasher.toString();
1123
- });
1124
- context = contextAdditions;
1125
- entries.sort();
1126
- return this.array(entries, false);
1127
- },
1128
- date(date) {
1129
- return write("date:" + date.toJSON());
1130
- },
1131
- symbol(sym) {
1132
- return write("symbol:" + sym.toString());
1133
- },
1134
- unkown(value, type) {
1135
- write(type);
1136
- if (!value) {
1137
- return;
1138
- }
1139
- write(":");
1140
- if (value && typeof value.entries === "function") {
1141
- return this.array(
1142
- Array.from(value.entries()),
1143
- true
1144
- /* ordered */
1145
- );
1146
- }
1147
- },
1148
- error(err) {
1149
- return write("error:" + err.toString());
1150
- },
1151
- boolean(bool) {
1152
- return write("bool:" + bool);
1153
- },
1154
- string(string) {
1155
- write("string:" + string.length + ":");
1156
- write(string);
1157
- },
1158
- function(fn) {
1159
- write("fn:");
1160
- if (isNativeFunction(fn)) {
1161
- this.dispatch("[native]");
1162
- } else {
1163
- this.dispatch(fn.toString());
1164
- }
1165
- if (options.respectFunctionNames !== false) {
1166
- this.dispatch("function-name:" + String(fn.name));
1167
- }
1168
- if (options.respectFunctionProperties) {
1169
- this.object(fn);
1170
- }
1171
- },
1172
- number(number) {
1173
- return write("number:" + number);
1174
- },
1175
- xml(xml) {
1176
- return write("xml:" + xml.toString());
1177
- },
1178
- null() {
1179
- return write("Null");
1180
- },
1181
- undefined() {
1182
- return write("Undefined");
1183
- },
1184
- regexp(regex) {
1185
- return write("regex:" + regex.toString());
1186
- },
1187
- uint8array(arr) {
1188
- write("uint8array:");
1189
- return this.dispatch(Array.prototype.slice.call(arr));
1190
- },
1191
- uint8clampedarray(arr) {
1192
- write("uint8clampedarray:");
1193
- return this.dispatch(Array.prototype.slice.call(arr));
1194
- },
1195
- int8array(arr) {
1196
- write("int8array:");
1197
- return this.dispatch(Array.prototype.slice.call(arr));
1198
- },
1199
- uint16array(arr) {
1200
- write("uint16array:");
1201
- return this.dispatch(Array.prototype.slice.call(arr));
1202
- },
1203
- int16array(arr) {
1204
- write("int16array:");
1205
- return this.dispatch(Array.prototype.slice.call(arr));
1206
- },
1207
- uint32array(arr) {
1208
- write("uint32array:");
1209
- return this.dispatch(Array.prototype.slice.call(arr));
1210
- },
1211
- int32array(arr) {
1212
- write("int32array:");
1213
- return this.dispatch(Array.prototype.slice.call(arr));
1214
- },
1215
- float32array(arr) {
1216
- write("float32array:");
1217
- return this.dispatch(Array.prototype.slice.call(arr));
1218
- },
1219
- float64array(arr) {
1220
- write("float64array:");
1221
- return this.dispatch(Array.prototype.slice.call(arr));
1222
- },
1223
- arraybuffer(arr) {
1224
- write("arraybuffer:");
1225
- return this.dispatch(new Uint8Array(arr));
1226
- },
1227
- url(url) {
1228
- return write("url:" + url.toString());
1229
- },
1230
- map(map) {
1231
- write("map:");
1232
- const arr = [...map];
1233
- return this.array(arr, options.unorderedSets !== false);
1234
- },
1235
- set(set) {
1236
- write("set:");
1237
- const arr = [...set];
1238
- return this.array(arr, options.unorderedSets !== false);
1239
- },
1240
- file(file) {
1241
- write("file:");
1242
- return this.dispatch([file.name, file.size, file.type, file.lastModfied]);
1243
- },
1244
- blob() {
1245
- if (options.ignoreUnknown) {
1246
- return write("[blob]");
1247
- }
1248
- throw new Error(
1249
- 'Hashing Blob objects is currently not supported\nUse "options.replacer" or "options.ignoreUnknown"\n'
1250
- );
1251
- },
1252
- domwindow() {
1253
- return write("domwindow");
1254
- },
1255
- bigint(number) {
1256
- return write("bigint:" + number.toString());
1257
- },
1258
- /* Node.js standard native objects */
1259
- process() {
1260
- return write("process");
1261
- },
1262
- timer() {
1263
- return write("timer");
1264
- },
1265
- pipe() {
1266
- return write("pipe");
1267
- },
1268
- tcp() {
1269
- return write("tcp");
1270
- },
1271
- udp() {
1272
- return write("udp");
1273
- },
1274
- tty() {
1275
- return write("tty");
1276
- },
1277
- statwatcher() {
1278
- return write("statwatcher");
1279
- },
1280
- securecontext() {
1281
- return write("securecontext");
1282
- },
1283
- connection() {
1284
- return write("connection");
1285
- },
1286
- zlib() {
1287
- return write("zlib");
1288
- },
1289
- context() {
1290
- return write("context");
1291
- },
1292
- nodescript() {
1293
- return write("nodescript");
1294
- },
1295
- httpparser() {
1296
- return write("httpparser");
1297
- },
1298
- dataview() {
1299
- return write("dataview");
1300
- },
1301
- signal() {
1302
- return write("signal");
1303
- },
1304
- fsevent() {
1305
- return write("fsevent");
1306
- },
1307
- tlswrap() {
1308
- return write("tlswrap");
1309
- }
1310
- };
1311
- }
1312
- const nativeFunc = "[native code] }";
1313
- const nativeFuncLength = nativeFunc.length;
1314
- function isNativeFunction(f) {
1315
- if (typeof f !== "function") {
1316
- return false;
1317
- }
1318
- return Function.prototype.toString.call(f).slice(-nativeFuncLength) === nativeFunc;
1319
- }
1320
-
1321
- var __defProp$1 = Object.defineProperty;
1322
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1323
- var __publicField$1 = (obj, key, value) => {
1324
- __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
1325
- return value;
1326
- };
1327
- class WordArray {
1328
- constructor(words, sigBytes) {
1329
- __publicField$1(this, "words");
1330
- __publicField$1(this, "sigBytes");
1331
- words = this.words = words || [];
1332
- this.sigBytes = sigBytes === void 0 ? words.length * 4 : sigBytes;
1333
- }
1334
- toString(encoder) {
1335
- return (encoder || Hex).stringify(this);
1336
- }
1337
- concat(wordArray) {
1338
- this.clamp();
1339
- if (this.sigBytes % 4) {
1340
- for (let i = 0; i < wordArray.sigBytes; i++) {
1341
- const thatByte = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
1342
- this.words[this.sigBytes + i >>> 2] |= thatByte << 24 - (this.sigBytes + i) % 4 * 8;
1343
- }
1344
- } else {
1345
- for (let j = 0; j < wordArray.sigBytes; j += 4) {
1346
- this.words[this.sigBytes + j >>> 2] = wordArray.words[j >>> 2];
1347
- }
1348
- }
1349
- this.sigBytes += wordArray.sigBytes;
1350
- return this;
1351
- }
1352
- clamp() {
1353
- this.words[this.sigBytes >>> 2] &= 4294967295 << 32 - this.sigBytes % 4 * 8;
1354
- this.words.length = Math.ceil(this.sigBytes / 4);
1355
- }
1356
- clone() {
1357
- return new WordArray([...this.words]);
1358
- }
1359
- }
1360
- const Hex = {
1361
- stringify(wordArray) {
1362
- const hexChars = [];
1363
- for (let i = 0; i < wordArray.sigBytes; i++) {
1364
- const bite = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
1365
- hexChars.push((bite >>> 4).toString(16), (bite & 15).toString(16));
1366
- }
1367
- return hexChars.join("");
1368
- }
1369
- };
1370
- const Base64 = {
1371
- stringify(wordArray) {
1372
- const keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
1373
- const base64Chars = [];
1374
- for (let i = 0; i < wordArray.sigBytes; i += 3) {
1375
- const byte1 = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
1376
- const byte2 = wordArray.words[i + 1 >>> 2] >>> 24 - (i + 1) % 4 * 8 & 255;
1377
- const byte3 = wordArray.words[i + 2 >>> 2] >>> 24 - (i + 2) % 4 * 8 & 255;
1378
- const triplet = byte1 << 16 | byte2 << 8 | byte3;
1379
- for (let j = 0; j < 4 && i * 8 + j * 6 < wordArray.sigBytes * 8; j++) {
1380
- base64Chars.push(keyStr.charAt(triplet >>> 6 * (3 - j) & 63));
1381
- }
1382
- }
1383
- return base64Chars.join("");
1384
- }
1385
- };
1386
- const Latin1 = {
1387
- parse(latin1Str) {
1388
- const latin1StrLength = latin1Str.length;
1389
- const words = [];
1390
- for (let i = 0; i < latin1StrLength; i++) {
1391
- words[i >>> 2] |= (latin1Str.charCodeAt(i) & 255) << 24 - i % 4 * 8;
1392
- }
1393
- return new WordArray(words, latin1StrLength);
1394
- }
1395
- };
1396
- const Utf8 = {
1397
- parse(utf8Str) {
1398
- return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
1399
- }
1400
- };
1401
- class BufferedBlockAlgorithm {
1402
- constructor() {
1403
- __publicField$1(this, "_data", new WordArray());
1404
- __publicField$1(this, "_nDataBytes", 0);
1405
- __publicField$1(this, "_minBufferSize", 0);
1406
- __publicField$1(this, "blockSize", 512 / 32);
1407
- }
1408
- reset() {
1409
- this._data = new WordArray();
1410
- this._nDataBytes = 0;
1411
- }
1412
- _append(data) {
1413
- if (typeof data === "string") {
1414
- data = Utf8.parse(data);
1415
- }
1416
- this._data.concat(data);
1417
- this._nDataBytes += data.sigBytes;
1418
- }
1419
- _doProcessBlock(_dataWords, _offset) {
1420
- }
1421
- _process(doFlush) {
1422
- let processedWords;
1423
- let nBlocksReady = this._data.sigBytes / (this.blockSize * 4);
1424
- if (doFlush) {
1425
- nBlocksReady = Math.ceil(nBlocksReady);
1426
- } else {
1427
- nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
1428
- }
1429
- const nWordsReady = nBlocksReady * this.blockSize;
1430
- const nBytesReady = Math.min(nWordsReady * 4, this._data.sigBytes);
1431
- if (nWordsReady) {
1432
- for (let offset = 0; offset < nWordsReady; offset += this.blockSize) {
1433
- this._doProcessBlock(this._data.words, offset);
1434
- }
1435
- processedWords = this._data.words.splice(0, nWordsReady);
1436
- this._data.sigBytes -= nBytesReady;
1437
- }
1438
- return new WordArray(processedWords, nBytesReady);
1439
- }
1440
- }
1441
- class Hasher extends BufferedBlockAlgorithm {
1442
- update(messageUpdate) {
1443
- this._append(messageUpdate);
1444
- this._process();
1445
- return this;
1446
- }
1447
- finalize(messageUpdate) {
1448
- if (messageUpdate) {
1449
- this._append(messageUpdate);
1450
- }
1451
- }
1452
- }
1453
-
1454
- var __defProp = Object.defineProperty;
1455
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1456
- var __publicField = (obj, key, value) => {
1457
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1458
- return value;
1459
- };
1460
- const H = [
1461
- 1779033703,
1462
- -1150833019,
1463
- 1013904242,
1464
- -1521486534,
1465
- 1359893119,
1466
- -1694144372,
1467
- 528734635,
1468
- 1541459225
1469
- ];
1470
- const K = [
1471
- 1116352408,
1472
- 1899447441,
1473
- -1245643825,
1474
- -373957723,
1475
- 961987163,
1476
- 1508970993,
1477
- -1841331548,
1478
- -1424204075,
1479
- -670586216,
1480
- 310598401,
1481
- 607225278,
1482
- 1426881987,
1483
- 1925078388,
1484
- -2132889090,
1485
- -1680079193,
1486
- -1046744716,
1487
- -459576895,
1488
- -272742522,
1489
- 264347078,
1490
- 604807628,
1491
- 770255983,
1492
- 1249150122,
1493
- 1555081692,
1494
- 1996064986,
1495
- -1740746414,
1496
- -1473132947,
1497
- -1341970488,
1498
- -1084653625,
1499
- -958395405,
1500
- -710438585,
1501
- 113926993,
1502
- 338241895,
1503
- 666307205,
1504
- 773529912,
1505
- 1294757372,
1506
- 1396182291,
1507
- 1695183700,
1508
- 1986661051,
1509
- -2117940946,
1510
- -1838011259,
1511
- -1564481375,
1512
- -1474664885,
1513
- -1035236496,
1514
- -949202525,
1515
- -778901479,
1516
- -694614492,
1517
- -200395387,
1518
- 275423344,
1519
- 430227734,
1520
- 506948616,
1521
- 659060556,
1522
- 883997877,
1523
- 958139571,
1524
- 1322822218,
1525
- 1537002063,
1526
- 1747873779,
1527
- 1955562222,
1528
- 2024104815,
1529
- -2067236844,
1530
- -1933114872,
1531
- -1866530822,
1532
- -1538233109,
1533
- -1090935817,
1534
- -965641998
1535
- ];
1536
- const W = [];
1537
- class SHA256 extends Hasher {
1538
- constructor() {
1539
- super(...arguments);
1540
- __publicField(this, "_hash", new WordArray([...H]));
1541
- }
1542
- /**
1543
- * Resets the internal state of the hash object to initial values.
1544
- */
1545
- reset() {
1546
- super.reset();
1547
- this._hash = new WordArray([...H]);
1548
- }
1549
- _doProcessBlock(M, offset) {
1550
- const H2 = this._hash.words;
1551
- let a = H2[0];
1552
- let b = H2[1];
1553
- let c = H2[2];
1554
- let d = H2[3];
1555
- let e = H2[4];
1556
- let f = H2[5];
1557
- let g = H2[6];
1558
- let h = H2[7];
1559
- for (let i = 0; i < 64; i++) {
1560
- if (i < 16) {
1561
- W[i] = M[offset + i] | 0;
1562
- } else {
1563
- const gamma0x = W[i - 15];
1564
- const gamma0 = (gamma0x << 25 | gamma0x >>> 7) ^ (gamma0x << 14 | gamma0x >>> 18) ^ gamma0x >>> 3;
1565
- const gamma1x = W[i - 2];
1566
- const gamma1 = (gamma1x << 15 | gamma1x >>> 17) ^ (gamma1x << 13 | gamma1x >>> 19) ^ gamma1x >>> 10;
1567
- W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
1568
- }
1569
- const ch = e & f ^ ~e & g;
1570
- const maj = a & b ^ a & c ^ b & c;
1571
- const sigma0 = (a << 30 | a >>> 2) ^ (a << 19 | a >>> 13) ^ (a << 10 | a >>> 22);
1572
- const sigma1 = (e << 26 | e >>> 6) ^ (e << 21 | e >>> 11) ^ (e << 7 | e >>> 25);
1573
- const t1 = h + sigma1 + ch + K[i] + W[i];
1574
- const t2 = sigma0 + maj;
1575
- h = g;
1576
- g = f;
1577
- f = e;
1578
- e = d + t1 | 0;
1579
- d = c;
1580
- c = b;
1581
- b = a;
1582
- a = t1 + t2 | 0;
1583
- }
1584
- H2[0] = H2[0] + a | 0;
1585
- H2[1] = H2[1] + b | 0;
1586
- H2[2] = H2[2] + c | 0;
1587
- H2[3] = H2[3] + d | 0;
1588
- H2[4] = H2[4] + e | 0;
1589
- H2[5] = H2[5] + f | 0;
1590
- H2[6] = H2[6] + g | 0;
1591
- H2[7] = H2[7] + h | 0;
1592
- }
1593
- /**
1594
- * Finishes the hash calculation and returns the hash as a WordArray.
1595
- *
1596
- * @param {string} messageUpdate - Additional message content to include in the hash.
1597
- * @returns {WordArray} The finalised hash as a WordArray.
1598
- */
1599
- finalize(messageUpdate) {
1600
- super.finalize(messageUpdate);
1601
- const nBitsTotal = this._nDataBytes * 8;
1602
- const nBitsLeft = this._data.sigBytes * 8;
1603
- this._data.words[nBitsLeft >>> 5] |= 128 << 24 - nBitsLeft % 32;
1604
- this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 14] = Math.floor(
1605
- nBitsTotal / 4294967296
1606
- );
1607
- this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 15] = nBitsTotal;
1608
- this._data.sigBytes = this._data.words.length * 4;
1609
- this._process();
1610
- return this._hash;
1611
- }
1612
- }
1613
- function sha256base64(message) {
1614
- return new SHA256().finalize(message).toString(Base64);
1615
- }
1616
-
1617
- function hash(object, options = {}) {
1618
- const hashed = typeof object === "string" ? object : objectHash(object, options);
1619
- return sha256base64(hashed).slice(0, 10);
1620
- }
1621
-
1622
997
  const ProductId = "#product";
1623
998
  const productResolver = defineSchemaOrgResolver({
1624
999
  defaults: {
@@ -1631,7 +1006,7 @@ const productResolver = defineSchemaOrgResolver({
1631
1006
  ],
1632
1007
  idPrefix: ["url", ProductId],
1633
1008
  resolve(node, ctx) {
1634
- setIfEmpty(node, "sku", hash(node.name));
1009
+ setIfEmpty(node, "sku", ohash.hash(node.name));
1635
1010
  node.aggregateOffer = resolveRelation(node.aggregateOffer, ctx, aggregateOfferResolver);
1636
1011
  node.aggregateRating = resolveRelation(node.aggregateRating, ctx, aggregateRatingResolver);
1637
1012
  node.offers = resolveRelation(node.offers, ctx, offerResolver);
@@ -1744,7 +1119,7 @@ function hashCode(s) {
1744
1119
  }
1745
1120
 
1746
1121
  const sepSub = "%separator";
1747
- function sub(p, token) {
1122
+ function sub(p, token, isJson = false) {
1748
1123
  let val;
1749
1124
  if (token === "s" || token === "pageTitle") {
1750
1125
  val = p.pageTitle;
@@ -1754,10 +1129,13 @@ function sub(p, token) {
1754
1129
  } else {
1755
1130
  val = p[token];
1756
1131
  }
1757
- return val !== void 0 ? (val || "").replace(/"/g, '\\"') : void 0;
1132
+ if (val !== void 0) {
1133
+ return isJson ? (val || "").replace(/"/g, '\\"') : val || "";
1134
+ }
1135
+ return void 0;
1758
1136
  }
1759
1137
  const sepSubRe = new RegExp(`${sepSub}(?:\\s*${sepSub})*`, "g");
1760
- function processTemplateParams(s, p, sep) {
1138
+ function processTemplateParams(s, p, sep, isJson = false) {
1761
1139
  if (typeof s !== "string" || !s.includes("%"))
1762
1140
  return s;
1763
1141
  let decoded = s;
@@ -1774,7 +1152,7 @@ function processTemplateParams(s, p, sep) {
1774
1152
  if (token === sepSub || !tokens.includes(token)) {
1775
1153
  return token;
1776
1154
  }
1777
- const re = sub(p, token.slice(1));
1155
+ const re = sub(p, token.slice(1), isJson);
1778
1156
  return re !== void 0 ? re : token;
1779
1157
  }).trim();
1780
1158
  if (hasSepSub) {
@@ -2070,7 +1448,10 @@ function uniqueBy(array, predicate) {
2070
1448
  const merge = createDefu((object, key, value) => {
2071
1449
  if (Array.isArray(object[key])) {
2072
1450
  if (Array.isArray(value)) {
2073
- object[key] = [.../* @__PURE__ */ new Set([...object[key], ...value])];
1451
+ const map = {};
1452
+ for (const item of [...object[key], ...value])
1453
+ map[ohash.hash(item)] = item;
1454
+ object[key] = Object.values(map);
2074
1455
  if (key === "itemListElement") {
2075
1456
  object[key] = [...uniqueBy(object[key], (item) => item.position)];
2076
1457
  }
@@ -2084,7 +1465,7 @@ function dedupeNodes(nodes) {
2084
1465
  const dedupedNodes = {};
2085
1466
  for (const key of nodes.keys()) {
2086
1467
  const n = nodes[key];
2087
- const nodeKey = resolveAsGraphKey(n["@id"] || hash(n));
1468
+ const nodeKey = resolveAsGraphKey(n["@id"] || ohash.hash(n));
2088
1469
  if (dedupedNodes[nodeKey] && n._dedupeStrategy !== "replace")
2089
1470
  dedupedNodes[nodeKey] = merge(nodes[key], dedupedNodes[nodeKey]);
2090
1471
  else
@@ -2097,7 +1478,7 @@ function normaliseNodes(nodes) {
2097
1478
  const dedupedNodes = {};
2098
1479
  for (const key of sortedNodeKeys) {
2099
1480
  const n = nodes[key];
2100
- const nodeKey = resolveAsGraphKey(n["@id"] || hash(n));
1481
+ const nodeKey = resolveAsGraphKey(n["@id"] || ohash.hash(n));
2101
1482
  const groupedKeys = groupBy(Object.keys(n), (key2) => {
2102
1483
  const val = n[key2];
2103
1484
  if (key2[0] === "_")
@@ -2196,6 +1577,9 @@ function SchemaOrgUnheadPlugin(config, meta, options) {
2196
1577
  const { loadResolver } = await Promise.resolve().then(function () { return resolver; });
2197
1578
  const nodes = await tag.props.nodes;
2198
1579
  for (const node of Array.isArray(nodes) ? nodes : [nodes]) {
1580
+ if (typeof node !== "object" || Object.keys(node).length === 0) {
1581
+ continue;
1582
+ }
2199
1583
  const newNode = {
2200
1584
  ...node,
2201
1585
  _dedupeStrategy: tag.tagDuplicateStrategy,
@@ -2231,12 +1615,18 @@ function SchemaOrgUnheadPlugin(config, meta, options) {
2231
1615
  }
2232
1616
  },
2233
1617
  "tags:resolve": async (ctx) => {
2234
- for (const tag of ctx.tags) {
1618
+ for (const k in ctx.tags) {
1619
+ const tag = ctx.tags[k];
2235
1620
  if (tag.tag === "script" && tag.props.type === "application/ld+json" && tag.props.nodes) {
1621
+ const resolvedGraph = graph.resolveGraph({ ...await meta?.() || {}, ...config, ...resolvedMeta });
1622
+ if (!resolvedGraph.length) {
1623
+ tag.props = {};
1624
+ return;
1625
+ }
2236
1626
  const minify = options?.minify || process.env.NODE_ENV === "production";
2237
1627
  tag.innerHTML = JSON.stringify({
2238
1628
  "@context": "https://schema.org",
2239
- "@graph": graph.resolveGraph({ ...await meta?.() || {}, ...config, ...resolvedMeta })
1629
+ "@graph": resolvedGraph
2240
1630
  }, (_, value) => {
2241
1631
  if (typeof value !== "object")
2242
1632
  return processTemplateParams(value, head._templateParams, head._separator);