@rebilder/agent-readability 0.3.0 → 0.5.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/CHANGELOG.md +17 -0
- package/README.md +5 -4
- package/dist/index.cjs +1275 -196
- package/dist/index.d.cts +317 -14
- package/dist/index.d.ts +317 -14
- package/dist/index.js +1259 -197
- package/dist/index.js.map +1 -1
- package/dist/probe/index.cjs +850 -12
- package/dist/probe/index.d.cts +15 -11
- package/dist/probe/index.d.ts +15 -11
- package/dist/probe/index.js +850 -12
- package/dist/probe/index.js.map +1 -1
- package/dist/probe/local.cjs +850 -12
- package/dist/probe/local.d.cts +2 -2
- package/dist/probe/local.d.ts +2 -2
- package/dist/probe/local.js +850 -12
- package/dist/probe/local.js.map +1 -1
- package/dist/{robots-policy-DE8jix-e.d.cts → robots-policy-C7cfPpu2.d.cts} +15 -6
- package/dist/{robots-policy-DE8jix-e.d.ts → robots-policy-C7cfPpu2.d.ts} +15 -6
- package/package.json +9 -4
package/dist/probe/index.js
CHANGED
|
@@ -221,33 +221,61 @@ var ACTION_LEXICON = [
|
|
|
221
221
|
"book now",
|
|
222
222
|
"buy",
|
|
223
223
|
"buy now",
|
|
224
|
+
"call",
|
|
224
225
|
"call now",
|
|
226
|
+
"check availability",
|
|
227
|
+
"check out",
|
|
225
228
|
"checkout",
|
|
226
229
|
"contact",
|
|
227
230
|
"contact us",
|
|
231
|
+
"create account",
|
|
232
|
+
"create an account",
|
|
228
233
|
"donate",
|
|
229
234
|
"download",
|
|
230
235
|
"email us",
|
|
236
|
+
"enquire",
|
|
237
|
+
"enrol",
|
|
231
238
|
"enroll",
|
|
239
|
+
"free trial",
|
|
240
|
+
"get a demo",
|
|
232
241
|
"get a quote",
|
|
242
|
+
"get directions",
|
|
243
|
+
"get in touch",
|
|
233
244
|
"get quote",
|
|
234
245
|
"get started",
|
|
246
|
+
"get the app",
|
|
247
|
+
"get tickets",
|
|
248
|
+
"hire",
|
|
249
|
+
"inquire",
|
|
250
|
+
"install",
|
|
235
251
|
"join",
|
|
236
252
|
"make an appointment",
|
|
253
|
+
"message us",
|
|
237
254
|
"order",
|
|
238
255
|
"order now",
|
|
256
|
+
"order online",
|
|
257
|
+
"pre-order",
|
|
258
|
+
"preorder",
|
|
239
259
|
"purchase",
|
|
240
260
|
"register",
|
|
261
|
+
"rent",
|
|
241
262
|
"request",
|
|
242
263
|
"request a demo",
|
|
243
264
|
"request a quote",
|
|
244
265
|
"reserve",
|
|
245
266
|
"schedule",
|
|
267
|
+
"shop",
|
|
268
|
+
"shop now",
|
|
246
269
|
"sign up",
|
|
247
270
|
"signup",
|
|
248
271
|
"start",
|
|
249
272
|
"start free trial",
|
|
250
|
-
"subscribe"
|
|
273
|
+
"subscribe",
|
|
274
|
+
"talk to sales",
|
|
275
|
+
"talk to us",
|
|
276
|
+
"text us",
|
|
277
|
+
"try",
|
|
278
|
+
"upgrade"
|
|
251
279
|
];
|
|
252
280
|
var BANDS = [
|
|
253
281
|
{
|
|
@@ -287,7 +315,7 @@ var BANDS = [
|
|
|
287
315
|
}
|
|
288
316
|
];
|
|
289
317
|
var DEFAULT_RULESET = deepFreeze({
|
|
290
|
-
version: "0.
|
|
318
|
+
version: "0.3.0",
|
|
291
319
|
weights: WEIGHTS,
|
|
292
320
|
thresholds: THRESHOLDS,
|
|
293
321
|
audienceTokens: AUDIENCE_TOKENS,
|
|
@@ -303,6 +331,495 @@ var DEFAULT_RULESET = deepFreeze({
|
|
|
303
331
|
bands: BANDS
|
|
304
332
|
});
|
|
305
333
|
|
|
334
|
+
// src/html.ts
|
|
335
|
+
var Utf8Cursor = class {
|
|
336
|
+
constructor(source) {
|
|
337
|
+
this.source = source;
|
|
338
|
+
}
|
|
339
|
+
source;
|
|
340
|
+
charIndex = 0;
|
|
341
|
+
byteIndex = 0;
|
|
342
|
+
at(target) {
|
|
343
|
+
if (target < this.charIndex) {
|
|
344
|
+
this.charIndex = 0;
|
|
345
|
+
this.byteIndex = 0;
|
|
346
|
+
}
|
|
347
|
+
const limit = Math.min(target, this.source.length);
|
|
348
|
+
while (this.charIndex < limit) {
|
|
349
|
+
const code = this.source.charCodeAt(this.charIndex);
|
|
350
|
+
if (code < 128) {
|
|
351
|
+
this.byteIndex += 1;
|
|
352
|
+
this.charIndex += 1;
|
|
353
|
+
} else if (code < 2048) {
|
|
354
|
+
this.byteIndex += 2;
|
|
355
|
+
this.charIndex += 1;
|
|
356
|
+
} else if (code >= 55296 && code <= 56319) {
|
|
357
|
+
const next = this.charIndex + 1 < this.source.length ? this.source.charCodeAt(this.charIndex + 1) : 0;
|
|
358
|
+
if (next >= 56320 && next <= 57343 && this.charIndex + 1 < limit) {
|
|
359
|
+
this.byteIndex += 4;
|
|
360
|
+
this.charIndex += 2;
|
|
361
|
+
} else {
|
|
362
|
+
this.byteIndex += 3;
|
|
363
|
+
this.charIndex += 1;
|
|
364
|
+
}
|
|
365
|
+
} else {
|
|
366
|
+
this.byteIndex += 3;
|
|
367
|
+
this.charIndex += 1;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return this.byteIndex;
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
var NAMED_ENTITIES = {
|
|
374
|
+
amp: "&",
|
|
375
|
+
lt: "<",
|
|
376
|
+
gt: ">",
|
|
377
|
+
quot: '"',
|
|
378
|
+
apos: "'",
|
|
379
|
+
nbsp: "\xA0",
|
|
380
|
+
ensp: "\u2002",
|
|
381
|
+
emsp: "\u2003",
|
|
382
|
+
thinsp: "\u2009",
|
|
383
|
+
shy: "\xAD",
|
|
384
|
+
zwnj: "\u200C",
|
|
385
|
+
zwj: "\u200D",
|
|
386
|
+
// Currency
|
|
387
|
+
cent: "\xA2",
|
|
388
|
+
pound: "\xA3",
|
|
389
|
+
curren: "\xA4",
|
|
390
|
+
yen: "\xA5",
|
|
391
|
+
euro: "\u20AC",
|
|
392
|
+
dollar: "$",
|
|
393
|
+
// Typography
|
|
394
|
+
ndash: "\u2013",
|
|
395
|
+
mdash: "\u2014",
|
|
396
|
+
hellip: "\u2026",
|
|
397
|
+
lsquo: "\u2018",
|
|
398
|
+
rsquo: "\u2019",
|
|
399
|
+
sbquo: "\u201A",
|
|
400
|
+
ldquo: "\u201C",
|
|
401
|
+
rdquo: "\u201D",
|
|
402
|
+
bdquo: "\u201E",
|
|
403
|
+
laquo: "\xAB",
|
|
404
|
+
raquo: "\xBB",
|
|
405
|
+
lsaquo: "\u2039",
|
|
406
|
+
rsaquo: "\u203A",
|
|
407
|
+
bull: "\u2022",
|
|
408
|
+
middot: "\xB7",
|
|
409
|
+
dagger: "\u2020",
|
|
410
|
+
Dagger: "\u2021",
|
|
411
|
+
prime: "\u2032",
|
|
412
|
+
Prime: "\u2033",
|
|
413
|
+
// Marks and math
|
|
414
|
+
copy: "\xA9",
|
|
415
|
+
reg: "\xAE",
|
|
416
|
+
trade: "\u2122",
|
|
417
|
+
sect: "\xA7",
|
|
418
|
+
para: "\xB6",
|
|
419
|
+
deg: "\xB0",
|
|
420
|
+
plusmn: "\xB1",
|
|
421
|
+
times: "\xD7",
|
|
422
|
+
divide: "\xF7",
|
|
423
|
+
minus: "\u2212",
|
|
424
|
+
permil: "\u2030",
|
|
425
|
+
frac12: "\xBD",
|
|
426
|
+
frac14: "\xBC",
|
|
427
|
+
frac34: "\xBE",
|
|
428
|
+
sup2: "\xB2",
|
|
429
|
+
sup3: "\xB3",
|
|
430
|
+
le: "\u2264",
|
|
431
|
+
ge: "\u2265",
|
|
432
|
+
ne: "\u2260",
|
|
433
|
+
// Directionality (invisible, but they do occupy bytes)
|
|
434
|
+
lrm: "\u200E",
|
|
435
|
+
rlm: "\u200F"
|
|
436
|
+
};
|
|
437
|
+
var C1_REPLACEMENTS = {
|
|
438
|
+
128: 8364,
|
|
439
|
+
130: 8218,
|
|
440
|
+
131: 402,
|
|
441
|
+
132: 8222,
|
|
442
|
+
133: 8230,
|
|
443
|
+
134: 8224,
|
|
444
|
+
135: 8225,
|
|
445
|
+
136: 710,
|
|
446
|
+
137: 8240,
|
|
447
|
+
138: 352,
|
|
448
|
+
139: 8249,
|
|
449
|
+
140: 338,
|
|
450
|
+
142: 381,
|
|
451
|
+
145: 8216,
|
|
452
|
+
146: 8217,
|
|
453
|
+
147: 8220,
|
|
454
|
+
148: 8221,
|
|
455
|
+
149: 8226,
|
|
456
|
+
150: 8211,
|
|
457
|
+
151: 8212,
|
|
458
|
+
152: 732,
|
|
459
|
+
153: 8482,
|
|
460
|
+
154: 353,
|
|
461
|
+
155: 8250,
|
|
462
|
+
156: 339,
|
|
463
|
+
158: 382,
|
|
464
|
+
159: 376
|
|
465
|
+
};
|
|
466
|
+
var ENTITY_RE = /&(#[xX][0-9a-fA-F]{1,6}|#[0-9]{1,7}|[a-zA-Z][a-zA-Z0-9]{0,31});/g;
|
|
467
|
+
function codePointToString(raw) {
|
|
468
|
+
const mapped = C1_REPLACEMENTS[raw];
|
|
469
|
+
const code = mapped ?? raw;
|
|
470
|
+
if (code === 0 || code > 1114111 || code >= 55296 && code <= 57343) return "\uFFFD";
|
|
471
|
+
return String.fromCodePoint(code);
|
|
472
|
+
}
|
|
473
|
+
function decodeEntities(text) {
|
|
474
|
+
if (!text.includes("&")) return text;
|
|
475
|
+
return text.replace(ENTITY_RE, (match, body) => {
|
|
476
|
+
if (body.startsWith("#")) {
|
|
477
|
+
const isHex = body[1] === "x" || body[1] === "X";
|
|
478
|
+
const digits = isHex ? body.slice(2) : body.slice(1);
|
|
479
|
+
const value = Number.parseInt(digits, isHex ? 16 : 10);
|
|
480
|
+
return Number.isNaN(value) ? match : codePointToString(value);
|
|
481
|
+
}
|
|
482
|
+
return NAMED_ENTITIES[body] ?? match;
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
var VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
486
|
+
"area",
|
|
487
|
+
"base",
|
|
488
|
+
"br",
|
|
489
|
+
"col",
|
|
490
|
+
"embed",
|
|
491
|
+
"hr",
|
|
492
|
+
"img",
|
|
493
|
+
"input",
|
|
494
|
+
"link",
|
|
495
|
+
"meta",
|
|
496
|
+
"param",
|
|
497
|
+
"source",
|
|
498
|
+
"track",
|
|
499
|
+
"wbr"
|
|
500
|
+
]);
|
|
501
|
+
var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set(["script", "style"]);
|
|
502
|
+
var RCDATA_ELEMENTS = /* @__PURE__ */ new Set(["textarea", "title"]);
|
|
503
|
+
var IMPLIED_END_TAGS = {
|
|
504
|
+
li: ["li"],
|
|
505
|
+
dt: ["dt", "dd"],
|
|
506
|
+
dd: ["dt", "dd"],
|
|
507
|
+
option: ["option"],
|
|
508
|
+
optgroup: ["option", "optgroup"],
|
|
509
|
+
tr: ["td", "th", "tr"],
|
|
510
|
+
td: ["td", "th"],
|
|
511
|
+
th: ["td", "th"],
|
|
512
|
+
tbody: ["td", "th", "tr", "thead", "tbody"],
|
|
513
|
+
tfoot: ["td", "th", "tr", "thead", "tbody"]
|
|
514
|
+
};
|
|
515
|
+
var CLOSES_OPEN_P = /* @__PURE__ */ new Set([
|
|
516
|
+
"address",
|
|
517
|
+
"article",
|
|
518
|
+
"aside",
|
|
519
|
+
"blockquote",
|
|
520
|
+
"details",
|
|
521
|
+
"div",
|
|
522
|
+
"dl",
|
|
523
|
+
"fieldset",
|
|
524
|
+
"figcaption",
|
|
525
|
+
"figure",
|
|
526
|
+
"footer",
|
|
527
|
+
"form",
|
|
528
|
+
"h1",
|
|
529
|
+
"h2",
|
|
530
|
+
"h3",
|
|
531
|
+
"h4",
|
|
532
|
+
"h5",
|
|
533
|
+
"h6",
|
|
534
|
+
"header",
|
|
535
|
+
"hr",
|
|
536
|
+
"main",
|
|
537
|
+
"nav",
|
|
538
|
+
"ol",
|
|
539
|
+
"p",
|
|
540
|
+
"pre",
|
|
541
|
+
"section",
|
|
542
|
+
"table",
|
|
543
|
+
"ul"
|
|
544
|
+
]);
|
|
545
|
+
var MAX_DEPTH = 256;
|
|
546
|
+
function isAsciiAlpha(ch) {
|
|
547
|
+
if (ch === void 0) return false;
|
|
548
|
+
return ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z";
|
|
549
|
+
}
|
|
550
|
+
function isHtmlSpace(ch) {
|
|
551
|
+
return ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "\f";
|
|
552
|
+
}
|
|
553
|
+
var DISPLAY_NONE_RE = /(^|;)display:none(!important)?(;|$)/;
|
|
554
|
+
function hasInlineDisplayNone(style) {
|
|
555
|
+
if (style === void 0) return false;
|
|
556
|
+
return DISPLAY_NONE_RE.test(style.toLowerCase().replace(/\s+/g, ""));
|
|
557
|
+
}
|
|
558
|
+
function parseStartTag(html, start) {
|
|
559
|
+
let i = start + 1;
|
|
560
|
+
const nameStart = i;
|
|
561
|
+
while (i < html.length) {
|
|
562
|
+
const ch = html[i] ?? "";
|
|
563
|
+
if (isHtmlSpace(ch) || ch === "/" || ch === ">") break;
|
|
564
|
+
i++;
|
|
565
|
+
}
|
|
566
|
+
const tag = html.slice(nameStart, i).toLowerCase();
|
|
567
|
+
const attrs = {};
|
|
568
|
+
let selfClosing = false;
|
|
569
|
+
while (i < html.length) {
|
|
570
|
+
while (i < html.length && isHtmlSpace(html[i] ?? "")) i++;
|
|
571
|
+
if (i >= html.length) break;
|
|
572
|
+
const ch = html[i] ?? "";
|
|
573
|
+
if (ch === ">") {
|
|
574
|
+
i++;
|
|
575
|
+
return { tag, attrs, selfClosing, end: i };
|
|
576
|
+
}
|
|
577
|
+
if (ch === "/") {
|
|
578
|
+
selfClosing = true;
|
|
579
|
+
i++;
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
const attrNameStart = i;
|
|
583
|
+
while (i < html.length) {
|
|
584
|
+
const c = html[i] ?? "";
|
|
585
|
+
if (isHtmlSpace(c) || c === "=" || c === ">" || c === "/") break;
|
|
586
|
+
i++;
|
|
587
|
+
}
|
|
588
|
+
if (i === attrNameStart) {
|
|
589
|
+
i++;
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
const attrName = html.slice(attrNameStart, i).toLowerCase();
|
|
593
|
+
let value = "";
|
|
594
|
+
while (i < html.length && isHtmlSpace(html[i] ?? "")) i++;
|
|
595
|
+
if (html[i] === "=") {
|
|
596
|
+
i++;
|
|
597
|
+
while (i < html.length && isHtmlSpace(html[i] ?? "")) i++;
|
|
598
|
+
const quote = html[i];
|
|
599
|
+
if (quote === '"' || quote === "'") {
|
|
600
|
+
i++;
|
|
601
|
+
const valueStart = i;
|
|
602
|
+
const close = html.indexOf(quote, i);
|
|
603
|
+
if (close === -1) {
|
|
604
|
+
value = html.slice(valueStart);
|
|
605
|
+
i = html.length;
|
|
606
|
+
} else {
|
|
607
|
+
value = html.slice(valueStart, close);
|
|
608
|
+
i = close + 1;
|
|
609
|
+
}
|
|
610
|
+
} else {
|
|
611
|
+
const valueStart = i;
|
|
612
|
+
while (i < html.length) {
|
|
613
|
+
const c = html[i] ?? "";
|
|
614
|
+
if (isHtmlSpace(c) || c === ">") break;
|
|
615
|
+
i++;
|
|
616
|
+
}
|
|
617
|
+
value = html.slice(valueStart, i);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
if (!(attrName in attrs)) attrs[attrName] = decodeEntities(value);
|
|
621
|
+
}
|
|
622
|
+
return { tag, attrs, selfClosing, end: i };
|
|
623
|
+
}
|
|
624
|
+
function findRawTextEnd(lowerHtml, from, tag) {
|
|
625
|
+
const needle = `</${tag}`;
|
|
626
|
+
const at = lowerHtml.indexOf(needle, from);
|
|
627
|
+
return at === -1 ? -1 : at;
|
|
628
|
+
}
|
|
629
|
+
function ownExclusion(tag, attrs) {
|
|
630
|
+
if (tag === "script") {
|
|
631
|
+
const type = (attrs["type"] ?? "").toLowerCase().split(";")[0]?.trim() ?? "";
|
|
632
|
+
return type === "application/ld+json" ? "script-ld-json" : "script";
|
|
633
|
+
}
|
|
634
|
+
if (tag === "style") return "style";
|
|
635
|
+
if (tag === "template") return "template";
|
|
636
|
+
if ("hidden" in attrs) return "hidden-attribute";
|
|
637
|
+
if (hasInlineDisplayNone(attrs["style"])) return "inline-display-none";
|
|
638
|
+
return null;
|
|
639
|
+
}
|
|
640
|
+
function tokenizeHtml(html) {
|
|
641
|
+
const elements = [];
|
|
642
|
+
const texts = [];
|
|
643
|
+
const jsonLd = [];
|
|
644
|
+
const metas = [];
|
|
645
|
+
const links = [];
|
|
646
|
+
const stack = [];
|
|
647
|
+
const cursor = new Utf8Cursor(html);
|
|
648
|
+
const topIndex = () => stack[stack.length - 1] ?? -1;
|
|
649
|
+
const exclusionAt = (elementIndex) => elementIndex >= 0 ? elements[elementIndex]?.excludedBy ?? null : null;
|
|
650
|
+
const emitText = (from, to, decode, override) => {
|
|
651
|
+
if (to <= from) return;
|
|
652
|
+
const raw = html.slice(from, to);
|
|
653
|
+
const parent = topIndex();
|
|
654
|
+
const offset = cursor.at(from);
|
|
655
|
+
texts.push({
|
|
656
|
+
text: decode ? decodeEntities(raw) : raw,
|
|
657
|
+
offset,
|
|
658
|
+
bytes: cursor.at(to) - offset,
|
|
659
|
+
parent,
|
|
660
|
+
excludedBy: override ?? exclusionAt(parent)
|
|
661
|
+
});
|
|
662
|
+
};
|
|
663
|
+
const popTo = (tag) => {
|
|
664
|
+
for (let depth = stack.length - 1; depth >= 0; depth--) {
|
|
665
|
+
const candidate = stack[depth];
|
|
666
|
+
if (candidate === void 0) continue;
|
|
667
|
+
if (elements[candidate]?.tag === tag) {
|
|
668
|
+
stack.length = depth;
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
const applyImpliedEndTags = (tag) => {
|
|
674
|
+
const closes = IMPLIED_END_TAGS[tag];
|
|
675
|
+
if (closes !== void 0) {
|
|
676
|
+
while (stack.length > 0) {
|
|
677
|
+
const top = stack[stack.length - 1];
|
|
678
|
+
const openTag = top === void 0 ? void 0 : elements[top]?.tag;
|
|
679
|
+
if (openTag === void 0 || !closes.includes(openTag)) break;
|
|
680
|
+
stack.pop();
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
if (CLOSES_OPEN_P.has(tag)) {
|
|
684
|
+
const top = stack[stack.length - 1];
|
|
685
|
+
if (top !== void 0 && elements[top]?.tag === "p") stack.pop();
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
let i = 0;
|
|
689
|
+
let textStart = 0;
|
|
690
|
+
let lowerHtml = null;
|
|
691
|
+
while (i < html.length) {
|
|
692
|
+
const lt = html.indexOf("<", i);
|
|
693
|
+
if (lt === -1) break;
|
|
694
|
+
const next = html[lt + 1];
|
|
695
|
+
if (next !== "!" && next !== "/" && !isAsciiAlpha(next)) {
|
|
696
|
+
i = lt + 1;
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
emitText(textStart, lt, true);
|
|
700
|
+
if (next === "!") {
|
|
701
|
+
if (html.startsWith("<!--", lt)) {
|
|
702
|
+
const close = html.indexOf("-->", lt + 4);
|
|
703
|
+
i = close === -1 ? html.length : close + 3;
|
|
704
|
+
} else {
|
|
705
|
+
const close = html.indexOf(">", lt + 2);
|
|
706
|
+
i = close === -1 ? html.length : close + 1;
|
|
707
|
+
}
|
|
708
|
+
textStart = i;
|
|
709
|
+
continue;
|
|
710
|
+
}
|
|
711
|
+
if (next === "/") {
|
|
712
|
+
const close = html.indexOf(">", lt + 2);
|
|
713
|
+
const end = close === -1 ? html.length : close + 1;
|
|
714
|
+
const rawName = html.slice(lt + 2, close === -1 ? html.length : close).trim();
|
|
715
|
+
const tag = rawName.toLowerCase();
|
|
716
|
+
if (tag.length > 0) popTo(tag);
|
|
717
|
+
i = end;
|
|
718
|
+
textStart = i;
|
|
719
|
+
continue;
|
|
720
|
+
}
|
|
721
|
+
const parsed = parseStartTag(html, lt);
|
|
722
|
+
applyImpliedEndTags(parsed.tag);
|
|
723
|
+
const parent = topIndex();
|
|
724
|
+
const own = ownExclusion(parsed.tag, parsed.attrs);
|
|
725
|
+
const element = {
|
|
726
|
+
index: elements.length,
|
|
727
|
+
tag: parsed.tag,
|
|
728
|
+
attrs: parsed.attrs,
|
|
729
|
+
offset: cursor.at(lt),
|
|
730
|
+
parent,
|
|
731
|
+
depth: stack.length,
|
|
732
|
+
excludedBy: exclusionAt(parent) ?? own
|
|
733
|
+
};
|
|
734
|
+
elements.push(element);
|
|
735
|
+
collectMetaOrLink(element, metas, links);
|
|
736
|
+
i = parsed.end;
|
|
737
|
+
const isVoid = VOID_ELEMENTS.has(parsed.tag);
|
|
738
|
+
const isRawText = RAW_TEXT_ELEMENTS.has(parsed.tag);
|
|
739
|
+
const isRcdata = RCDATA_ELEMENTS.has(parsed.tag);
|
|
740
|
+
if (isRawText || isRcdata) {
|
|
741
|
+
const contentStart = i;
|
|
742
|
+
lowerHtml ??= html.toLowerCase();
|
|
743
|
+
const close = findRawTextEnd(lowerHtml, contentStart, parsed.tag);
|
|
744
|
+
const contentEnd = close === -1 ? html.length : close;
|
|
745
|
+
if (contentEnd > contentStart) {
|
|
746
|
+
const wasTop = stack.length;
|
|
747
|
+
stack.push(element.index);
|
|
748
|
+
emitText(contentStart, contentEnd, isRcdata, element.excludedBy ?? own ?? void 0);
|
|
749
|
+
stack.length = wasTop;
|
|
750
|
+
if (own === "script-ld-json") {
|
|
751
|
+
jsonLd.push({
|
|
752
|
+
text: html.slice(contentStart, contentEnd),
|
|
753
|
+
offset: cursor.at(contentStart),
|
|
754
|
+
element: element.index
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
if (close === -1) {
|
|
759
|
+
i = html.length;
|
|
760
|
+
} else {
|
|
761
|
+
const gt = html.indexOf(">", close);
|
|
762
|
+
i = gt === -1 ? html.length : gt + 1;
|
|
763
|
+
}
|
|
764
|
+
textStart = i;
|
|
765
|
+
continue;
|
|
766
|
+
}
|
|
767
|
+
if (!isVoid && !parsed.selfClosing && stack.length < MAX_DEPTH) stack.push(element.index);
|
|
768
|
+
textStart = i;
|
|
769
|
+
}
|
|
770
|
+
emitText(textStart, html.length, true);
|
|
771
|
+
return {
|
|
772
|
+
elements,
|
|
773
|
+
texts,
|
|
774
|
+
jsonLd,
|
|
775
|
+
metas,
|
|
776
|
+
links,
|
|
777
|
+
bytes: cursor.at(html.length)
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
function collectMetaOrLink(element, metas, links) {
|
|
781
|
+
const lower = (value) => value === void 0 ? null : value.toLowerCase();
|
|
782
|
+
if (element.tag === "meta") {
|
|
783
|
+
metas.push({
|
|
784
|
+
name: lower(element.attrs["name"]),
|
|
785
|
+
property: lower(element.attrs["property"]),
|
|
786
|
+
httpEquiv: lower(element.attrs["http-equiv"]),
|
|
787
|
+
itemprop: lower(element.attrs["itemprop"]),
|
|
788
|
+
charset: lower(element.attrs["charset"]),
|
|
789
|
+
content: element.attrs["content"] ?? null,
|
|
790
|
+
element: element.index,
|
|
791
|
+
offset: element.offset
|
|
792
|
+
});
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
if (element.tag === "link") {
|
|
796
|
+
const rawRel = element.attrs["rel"] ?? "";
|
|
797
|
+
const rel = [];
|
|
798
|
+
for (const token of rawRel.toLowerCase().split(/\s+/)) {
|
|
799
|
+
if (token.length > 0 && !rel.includes(token)) rel.push(token);
|
|
800
|
+
}
|
|
801
|
+
links.push({
|
|
802
|
+
rel,
|
|
803
|
+
href: element.attrs["href"] ?? null,
|
|
804
|
+
type: lower(element.attrs["type"]),
|
|
805
|
+
hreflang: lower(element.attrs["hreflang"]),
|
|
806
|
+
title: element.attrs["title"] ?? null,
|
|
807
|
+
element: element.index,
|
|
808
|
+
offset: element.offset
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
function joinText(parts) {
|
|
813
|
+
return parts.join(" ").replace(/\s+/g, " ").trim();
|
|
814
|
+
}
|
|
815
|
+
function countedText(doc) {
|
|
816
|
+
const parts = [];
|
|
817
|
+
for (const node of doc.texts) {
|
|
818
|
+
if (node.excludedBy === null) parts.push(node.text);
|
|
819
|
+
}
|
|
820
|
+
return joinText(parts);
|
|
821
|
+
}
|
|
822
|
+
|
|
306
823
|
// src/extract.ts
|
|
307
824
|
function utf8Length(text) {
|
|
308
825
|
let bytes = 0;
|
|
@@ -320,6 +837,100 @@ function utf8Length(text) {
|
|
|
320
837
|
}
|
|
321
838
|
return bytes;
|
|
322
839
|
}
|
|
840
|
+
var SCHEMA_PREFIX = /^https?:\/\/schema\.org\//;
|
|
841
|
+
function stripSchemaPrefix(type) {
|
|
842
|
+
return type.replace(SCHEMA_PREFIX, "");
|
|
843
|
+
}
|
|
844
|
+
function typesOf(value) {
|
|
845
|
+
const raw = value["@type"];
|
|
846
|
+
if (typeof raw === "string") return [stripSchemaPrefix(raw)];
|
|
847
|
+
if (Array.isArray(raw)) {
|
|
848
|
+
const out = [];
|
|
849
|
+
for (const entry of raw) if (typeof entry === "string") out.push(stripSchemaPrefix(entry));
|
|
850
|
+
return out;
|
|
851
|
+
}
|
|
852
|
+
return [];
|
|
853
|
+
}
|
|
854
|
+
var JSON_LD_MAX_DEPTH = 12;
|
|
855
|
+
function collectNodes(value, offset, depth, out, seen) {
|
|
856
|
+
if (depth > JSON_LD_MAX_DEPTH || value === null || typeof value !== "object") return;
|
|
857
|
+
if (seen.has(value)) return;
|
|
858
|
+
seen.add(value);
|
|
859
|
+
if (Array.isArray(value)) {
|
|
860
|
+
for (const entry of value) collectNodes(entry, offset, depth + 1, out, seen);
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
863
|
+
const record = value;
|
|
864
|
+
const types = typesOf(record);
|
|
865
|
+
if (types.length > 0) out.push({ types, value: record, offset });
|
|
866
|
+
for (const [key, child] of Object.entries(record)) {
|
|
867
|
+
if (key === "@context") continue;
|
|
868
|
+
collectNodes(child, offset, depth + 1, out, seen);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
function parseJsonLd(blocks) {
|
|
872
|
+
const nodes = [];
|
|
873
|
+
let parsed = 0;
|
|
874
|
+
for (const block of blocks) {
|
|
875
|
+
let value;
|
|
876
|
+
try {
|
|
877
|
+
value = JSON.parse(block.text);
|
|
878
|
+
} catch {
|
|
879
|
+
continue;
|
|
880
|
+
}
|
|
881
|
+
parsed++;
|
|
882
|
+
collectNodes(value, block.offset, 0, nodes, /* @__PURE__ */ new Set());
|
|
883
|
+
}
|
|
884
|
+
return { nodes, blocks: blocks.length, parsed };
|
|
885
|
+
}
|
|
886
|
+
function header(headers, name) {
|
|
887
|
+
const values = headers[name];
|
|
888
|
+
return values !== void 0 && values.length > 0 ? values[0] ?? null : null;
|
|
889
|
+
}
|
|
890
|
+
function headerAll(headers, name) {
|
|
891
|
+
return headers[name] ?? [];
|
|
892
|
+
}
|
|
893
|
+
function mediaType(contentType) {
|
|
894
|
+
if (contentType === null) return null;
|
|
895
|
+
const semi = contentType.indexOf(";");
|
|
896
|
+
const value = (semi === -1 ? contentType : contentType.slice(0, semi)).trim().toLowerCase();
|
|
897
|
+
return value.length > 0 ? value : null;
|
|
898
|
+
}
|
|
899
|
+
function classifyMediaType(type) {
|
|
900
|
+
if (type === null) return "other";
|
|
901
|
+
if (type === "text/html" || type === "application/xhtml+xml") return "html";
|
|
902
|
+
if (type === "text/markdown" || type === "text/x-markdown") return "markdown";
|
|
903
|
+
if (type === "text/plain") return "text";
|
|
904
|
+
if (type === "application/json" || type === "application/ld+json" || type.endsWith("+json")) {
|
|
905
|
+
return "json";
|
|
906
|
+
}
|
|
907
|
+
return "other";
|
|
908
|
+
}
|
|
909
|
+
function bodyLooksLikeHtml(body) {
|
|
910
|
+
const head = body.slice(0, 1024).trimStart().toLowerCase();
|
|
911
|
+
return head.startsWith("<!doctype html") || head.startsWith("<html") || head.startsWith("<?xml") ? true : head.includes("<html") || head.includes("<head>") || head.includes("<body");
|
|
912
|
+
}
|
|
913
|
+
function buildRepresentation(capture) {
|
|
914
|
+
if (typeof capture.body !== "string") return null;
|
|
915
|
+
const contentType = mediaType(header(capture.headers, "content-type"));
|
|
916
|
+
const declared = classifyMediaType(contentType);
|
|
917
|
+
const looksLikeHtml = bodyLooksLikeHtml(capture.body);
|
|
918
|
+
const doc = declared === "html" || looksLikeHtml ? tokenizeHtml(capture.body) : null;
|
|
919
|
+
const jsonLd = doc !== null ? parseJsonLd(doc.jsonLd.map((block) => ({ text: block.text, offset: block.offset }))) : declared === "json" ? parseJsonLd([{ text: capture.body, offset: 0 }]) : { nodes: [], blocks: 0, parsed: 0 };
|
|
920
|
+
return {
|
|
921
|
+
kind: declared,
|
|
922
|
+
contentType,
|
|
923
|
+
body: capture.body,
|
|
924
|
+
bytes: capture.bytes,
|
|
925
|
+
doc,
|
|
926
|
+
jsonLd,
|
|
927
|
+
text: doc !== null ? countedText(doc) : capture.body,
|
|
928
|
+
looksLikeHtml,
|
|
929
|
+
truncated: capture.truncated,
|
|
930
|
+
finalUrl: capture.finalUrl,
|
|
931
|
+
headers: capture.headers
|
|
932
|
+
};
|
|
933
|
+
}
|
|
323
934
|
function parseRobots(text) {
|
|
324
935
|
const groups = [];
|
|
325
936
|
const sitemaps = [];
|
|
@@ -361,7 +972,10 @@ function parseRobots(text) {
|
|
|
361
972
|
else current.disallow.push(value);
|
|
362
973
|
continue;
|
|
363
974
|
}
|
|
364
|
-
if (field === "crawl-delay" || field === "host" || field === "clean-param")
|
|
975
|
+
if (field === "crawl-delay" || field === "host" || field === "clean-param" || field === "content-signal") {
|
|
976
|
+
if (field === "content-signal" && current !== null) openingGroup = false;
|
|
977
|
+
continue;
|
|
978
|
+
}
|
|
365
979
|
malformedLines++;
|
|
366
980
|
}
|
|
367
981
|
return { groups, sitemaps, malformedLines, orphanRules };
|
|
@@ -443,8 +1057,14 @@ deepFreeze2({
|
|
|
443
1057
|
band: [100, 7, 75, 5, 50, 3, 25, 1],
|
|
444
1058
|
noscriptFloor: 1
|
|
445
1059
|
},
|
|
446
|
-
/**
|
|
447
|
-
|
|
1060
|
+
/**
|
|
1061
|
+
* D2.1, 9 for a machine copy served at the page's own address on `Accept`
|
|
1062
|
+
* negotiation: a machine media type AND a body that is not HTML. ARS 0.3: 6
|
|
1063
|
+
* when the page does not negotiate but the Markdown copy it declares as an
|
|
1064
|
+
* alternate was fetched and is real. Less than full because only agents that
|
|
1065
|
+
* look for the link reach it, and they pay a second request to do so.
|
|
1066
|
+
*/
|
|
1067
|
+
negotiatedResponse: { full: 9, linkedCopy: 6 },
|
|
448
1068
|
/** D2.2, 3. All-or-nothing. */
|
|
449
1069
|
declaredAlternates: { full: 3 },
|
|
450
1070
|
/** D2.3, 3. All-or-nothing, and 0 unless D2.1 > 0. */
|
|
@@ -596,7 +1216,183 @@ function sha256Hex(message) {
|
|
|
596
1216
|
for (const word of h) hex += word.toString(16).padStart(8, "0");
|
|
597
1217
|
return hex;
|
|
598
1218
|
}
|
|
599
|
-
sha256Hex("ars-0.
|
|
1219
|
+
sha256Hex("ars-0.3-corpus-unfrozen");
|
|
1220
|
+
function parseLinkHeaders(values) {
|
|
1221
|
+
const out = [];
|
|
1222
|
+
for (const value of values) {
|
|
1223
|
+
for (const entry of splitLinkEntries(value)) {
|
|
1224
|
+
const open = entry.indexOf("<");
|
|
1225
|
+
const close = entry.indexOf(">", open + 1);
|
|
1226
|
+
if (open === -1 || close === -1) continue;
|
|
1227
|
+
const url = entry.slice(open + 1, close).trim();
|
|
1228
|
+
if (url.length === 0) continue;
|
|
1229
|
+
let rel = [];
|
|
1230
|
+
let type = null;
|
|
1231
|
+
for (const param of entry.slice(close + 1).split(";")) {
|
|
1232
|
+
const equals = param.indexOf("=");
|
|
1233
|
+
if (equals === -1) continue;
|
|
1234
|
+
const name = param.slice(0, equals).trim().toLowerCase();
|
|
1235
|
+
const raw = param.slice(equals + 1).trim();
|
|
1236
|
+
const unquoted = raw.startsWith('"') && raw.endsWith('"') ? raw.slice(1, -1) : raw;
|
|
1237
|
+
if (name === "rel")
|
|
1238
|
+
rel = unquoted.toLowerCase().split(/\s+/).filter((t) => t.length > 0);
|
|
1239
|
+
else if (name === "type") type = unquoted.trim().toLowerCase();
|
|
1240
|
+
}
|
|
1241
|
+
out.push({ url, rel, type });
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
return out;
|
|
1245
|
+
}
|
|
1246
|
+
function splitLinkEntries(value) {
|
|
1247
|
+
const entries = [];
|
|
1248
|
+
let depth = 0;
|
|
1249
|
+
let quoted = false;
|
|
1250
|
+
let start = 0;
|
|
1251
|
+
for (let i = 0; i < value.length; i++) {
|
|
1252
|
+
const char = value.charAt(i);
|
|
1253
|
+
if (quoted) {
|
|
1254
|
+
if (char === '"') quoted = false;
|
|
1255
|
+
continue;
|
|
1256
|
+
}
|
|
1257
|
+
if (char === '"') quoted = true;
|
|
1258
|
+
else if (char === "<") depth++;
|
|
1259
|
+
else if (char === ">") depth = depth > 0 ? depth - 1 : 0;
|
|
1260
|
+
else if (char === "," && depth === 0) {
|
|
1261
|
+
entries.push(value.slice(start, i));
|
|
1262
|
+
start = i + 1;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
entries.push(value.slice(start));
|
|
1266
|
+
return entries.map((entry) => entry.trim()).filter((entry) => entry.length > 0);
|
|
1267
|
+
}
|
|
1268
|
+
var MACHINE_KINDS = /* @__PURE__ */ new Set(["markdown", "text", "json"]);
|
|
1269
|
+
function isMachineCopy(capture) {
|
|
1270
|
+
const representation = buildRepresentation(capture);
|
|
1271
|
+
return representation !== null && MACHINE_KINDS.has(representation.kind) && !representation.looksLikeHtml;
|
|
1272
|
+
}
|
|
1273
|
+
var MARKDOWN_MEDIA = /* @__PURE__ */ new Set(["text/markdown", "text/x-markdown"]);
|
|
1274
|
+
function isMarkdownType(type) {
|
|
1275
|
+
return type !== null && MARKDOWN_MEDIA.has((type.split(";")[0] ?? "").trim().toLowerCase());
|
|
1276
|
+
}
|
|
1277
|
+
function declaredMarkdownAlternates(captures) {
|
|
1278
|
+
const out = [];
|
|
1279
|
+
const add = (raw, base) => {
|
|
1280
|
+
try {
|
|
1281
|
+
const url = new URL(raw, base);
|
|
1282
|
+
url.hash = "";
|
|
1283
|
+
const href = url.toString();
|
|
1284
|
+
if (!out.includes(href)) out.push(href);
|
|
1285
|
+
} catch {
|
|
1286
|
+
}
|
|
1287
|
+
};
|
|
1288
|
+
for (const capture of captures) {
|
|
1289
|
+
if (capture === null) continue;
|
|
1290
|
+
for (const link of parseLinkHeaders(headerAll(capture.headers, "link"))) {
|
|
1291
|
+
if (link.rel.includes("alternate") && isMarkdownType(link.type)) add(link.url, capture.finalUrl);
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
for (const capture of captures) {
|
|
1295
|
+
if (capture === null) continue;
|
|
1296
|
+
const representation = buildRepresentation(capture);
|
|
1297
|
+
if (representation === null || representation.doc === null) continue;
|
|
1298
|
+
for (const link of representation.doc.links) {
|
|
1299
|
+
if (!link.rel.includes("alternate") || link.href === null) continue;
|
|
1300
|
+
if (isMarkdownType(link.type)) add(link.href, capture.finalUrl);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
return out;
|
|
1304
|
+
}
|
|
1305
|
+
function markdownAlternateTarget(agent, browser, origin) {
|
|
1306
|
+
if (agent === null || agent.status < 200 || agent.status >= 300) return null;
|
|
1307
|
+
if (isMachineCopy(agent)) return null;
|
|
1308
|
+
const own = /* @__PURE__ */ new Set([agent.finalUrl, agent.requestedUrl]);
|
|
1309
|
+
for (const href of declaredMarkdownAlternates([browser, agent])) {
|
|
1310
|
+
let sameOrigin = false;
|
|
1311
|
+
try {
|
|
1312
|
+
sameOrigin = new URL(href).origin === origin;
|
|
1313
|
+
} catch {
|
|
1314
|
+
sameOrigin = false;
|
|
1315
|
+
}
|
|
1316
|
+
if (sameOrigin && !own.has(href)) return href;
|
|
1317
|
+
}
|
|
1318
|
+
return null;
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
// src/site-signals.ts
|
|
1322
|
+
var BODY_SCAN_CHARS = 256 * 1024;
|
|
1323
|
+
function headerValues(input, name) {
|
|
1324
|
+
const direct = input.headers[name];
|
|
1325
|
+
if (direct !== void 0) return direct.map((value) => value.toLowerCase());
|
|
1326
|
+
const target = name.toLowerCase();
|
|
1327
|
+
const out = [];
|
|
1328
|
+
for (const [key, values] of Object.entries(input.headers)) {
|
|
1329
|
+
if (key.toLowerCase() === target) {
|
|
1330
|
+
for (const value of values) out.push(value.toLowerCase());
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
return out;
|
|
1334
|
+
}
|
|
1335
|
+
function hasToken(values, token) {
|
|
1336
|
+
return values.some(
|
|
1337
|
+
(value) => value.split(",").map((part) => part.trim()).includes(token)
|
|
1338
|
+
);
|
|
1339
|
+
}
|
|
1340
|
+
function isRobotsTxtTarget(input) {
|
|
1341
|
+
for (const raw of [input.requestedUrl, input.finalUrl]) {
|
|
1342
|
+
if (typeof raw !== "string" || raw.length === 0) continue;
|
|
1343
|
+
try {
|
|
1344
|
+
if (new URL(raw).pathname.toLowerCase() === "/robots.txt") return true;
|
|
1345
|
+
} catch {
|
|
1346
|
+
const path = (raw.split("#")[0]?.split("?")[0] ?? "").toLowerCase();
|
|
1347
|
+
if (path === "/robots.txt" || path.endsWith("/robots.txt")) return true;
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
return false;
|
|
1351
|
+
}
|
|
1352
|
+
function detectEdgeChallenge(input) {
|
|
1353
|
+
const status = input.status;
|
|
1354
|
+
const body = typeof input.body === "string" ? input.body.slice(0, BODY_SCAN_CHARS) : "";
|
|
1355
|
+
const server = headerValues(input, "server");
|
|
1356
|
+
const contentTypes = headerValues(input, "content-type");
|
|
1357
|
+
const isHtmlContent = contentTypes.some(
|
|
1358
|
+
(value) => value.includes("text/html") || value.includes("application/xhtml+xml")
|
|
1359
|
+
);
|
|
1360
|
+
const lowerBodyHead = body.slice(0, 4096).toLowerCase();
|
|
1361
|
+
const isPlainTextWithoutMarkup = contentTypes.some((value) => value.includes("text/plain")) && !lowerBodyHead.includes("<html") && !lowerBodyHead.includes("<script") && !lowerBodyHead.includes("<!doctype html");
|
|
1362
|
+
const isRobotsHtmlChallenge = isRobotsTxtTarget(input) && isHtmlContent;
|
|
1363
|
+
if (hasToken(headerValues(input, "cf-mitigated"), "challenge")) {
|
|
1364
|
+
return { vendor: "cloudflare", signal: "cf-mitigated: challenge", status };
|
|
1365
|
+
}
|
|
1366
|
+
if ((status === 403 || status === 429 || status === 503 || isRobotsHtmlChallenge && status === 200) && !isPlainTextWithoutMarkup && server.some((value) => value.includes("cloudflare")) && body.includes("/cdn-cgi/challenge-platform/")) {
|
|
1367
|
+
return { vendor: "cloudflare", signal: "Cloudflare challenge page", status };
|
|
1368
|
+
}
|
|
1369
|
+
if (hasToken(headerValues(input, "x-vercel-mitigated"), "challenge")) {
|
|
1370
|
+
return { vendor: "vercel", signal: "x-vercel-mitigated: challenge", status };
|
|
1371
|
+
}
|
|
1372
|
+
if ((status < 200 || status >= 300 || isRobotsHtmlChallenge && status === 200) && !isPlainTextWithoutMarkup && server.some((value) => value.includes("vercel")) && body.includes("Vercel Security Checkpoint")) {
|
|
1373
|
+
return { vendor: "vercel", signal: "Vercel Security Checkpoint page", status };
|
|
1374
|
+
}
|
|
1375
|
+
if ((status === 401 || status === 403) && headerValues(input, "x-datadome").length > 0) {
|
|
1376
|
+
return { vendor: "datadome", signal: `x-datadome with HTTP ${status}`, status };
|
|
1377
|
+
}
|
|
1378
|
+
if ((status === 403 || status === 429 || isRobotsHtmlChallenge && status === 200) && !isPlainTextWithoutMarkup && body.includes("px-captcha") && body.includes("_pxAppId")) {
|
|
1379
|
+
return { vendor: "human", signal: "HUMAN block page", status };
|
|
1380
|
+
}
|
|
1381
|
+
return null;
|
|
1382
|
+
}
|
|
1383
|
+
var DETAIL_PREFIX = "edge-challenge";
|
|
1384
|
+
function challengeDetail(challenge) {
|
|
1385
|
+
return `${DETAIL_PREFIX}; vendor=${challenge.vendor}; status=${challenge.status}; signal=${challenge.signal.slice(0, 120)}`;
|
|
1386
|
+
}
|
|
1387
|
+
new Set(
|
|
1388
|
+
[
|
|
1389
|
+
...DEFAULT_RULESET.audienceTokens.assistant,
|
|
1390
|
+
...DEFAULT_RULESET.audienceTokens.training,
|
|
1391
|
+
...DEFAULT_RULESET.audienceTokens.search,
|
|
1392
|
+
"googlebot",
|
|
1393
|
+
"bingbot"
|
|
1394
|
+
].map((token) => token.toLowerCase())
|
|
1395
|
+
);
|
|
600
1396
|
var ALLOW_PRIVATE_HOSTS = /* @__PURE__ */ Symbol("rebilder.ars.probe.allow-private-hosts");
|
|
601
1397
|
var allowsPrivateHosts = (policy) => policy === ALLOW_PRIVATE_HOSTS;
|
|
602
1398
|
var NOT_AN_IP = { family: null, reserved: false, label: "hostname" };
|
|
@@ -690,6 +1486,9 @@ function classifyIpv6Groups(groups) {
|
|
|
690
1486
|
const allZeroThrough = (upTo) => groups.slice(0, upTo).every((x) => x === 0);
|
|
691
1487
|
if (groups.every((x) => x === 0)) return v6("unspecified (::)", true);
|
|
692
1488
|
if (allZeroThrough(7) && g(7) === 1) return v6("loopback (::1)", true);
|
|
1489
|
+
if (allZeroThrough(4) && g(4) === 65535 && g(5) === 0) {
|
|
1490
|
+
return v6("IPv4-translated (::ffff:0:0:0/96)", true);
|
|
1491
|
+
}
|
|
693
1492
|
if (allZeroThrough(5) && g(5) === 65535) {
|
|
694
1493
|
const inner = classifyIpv4Octets(embeddedV4(g(6), g(7)));
|
|
695
1494
|
return v6(`IPv4-mapped \u2192 ${inner.label}`, inner.reserved);
|
|
@@ -698,10 +1497,16 @@ function classifyIpv6Groups(groups) {
|
|
|
698
1497
|
const inner = classifyIpv4Octets(embeddedV4(g(6), g(7)));
|
|
699
1498
|
return v6(`IPv4-compatible \u2192 ${inner.label}`, true);
|
|
700
1499
|
}
|
|
1500
|
+
if (g(0) === 100 && g(1) === 65435 && g(2) === 1) {
|
|
1501
|
+
return v6("NAT64 local-use (64:ff9b:1::/48)", true);
|
|
1502
|
+
}
|
|
701
1503
|
if (g(0) === 100 && g(1) === 65435 && g(2) === 0 && g(3) === 0 && g(4) === 0 && g(5) === 0) {
|
|
702
1504
|
const inner = classifyIpv4Octets(embeddedV4(g(6), g(7)));
|
|
703
1505
|
return v6(`NAT64 64:ff9b::/96 \u2192 ${inner.label}`, inner.reserved);
|
|
704
1506
|
}
|
|
1507
|
+
if (g(0) === 8193 && g(1) === 0) {
|
|
1508
|
+
return v6("Teredo (2001::/32)", true);
|
|
1509
|
+
}
|
|
705
1510
|
if (g(0) === 8194) {
|
|
706
1511
|
const inner = classifyIpv4Octets(embeddedV4(g(1), g(2)));
|
|
707
1512
|
return v6(`6to4 2002::/16 \u2192 ${inner.label}`, inner.reserved);
|
|
@@ -711,6 +1516,7 @@ function classifyIpv6Groups(groups) {
|
|
|
711
1516
|
if (g(0) === 8193 && g(1) === 3512) return v6("documentation (2001:db8::/32)", true);
|
|
712
1517
|
if ((g(0) & 65024) === 64512) return v6("unique local (fc00::/7)", true);
|
|
713
1518
|
if ((g(0) & 65472) === 65152) return v6("link-local (fe80::/10)", true);
|
|
1519
|
+
if ((g(0) & 65472) === 65216) return v6("site-local (fec0::/10)", true);
|
|
714
1520
|
if ((g(0) & 65280) === 65280) return v6("multicast (ff00::/8)", true);
|
|
715
1521
|
return v6("public", false);
|
|
716
1522
|
}
|
|
@@ -753,8 +1559,10 @@ function guardUrl(input, policy) {
|
|
|
753
1559
|
if (url.username !== "" || url.password !== "") {
|
|
754
1560
|
return { ok: false, reason: "URLs with embedded credentials cannot be fetched." };
|
|
755
1561
|
}
|
|
756
|
-
|
|
757
|
-
if (hostname
|
|
1562
|
+
const hostname = url.hostname.toLowerCase().replace(/\.+$/, "");
|
|
1563
|
+
if (hostname === "") {
|
|
1564
|
+
return { ok: false, reason: "That URL has no hostname." };
|
|
1565
|
+
}
|
|
758
1566
|
const permissive = allowsPrivateHosts(policy.hostPolicy);
|
|
759
1567
|
if (!permissive && (hostname === "localhost" || hostname.endsWith(".localhost"))) {
|
|
760
1568
|
return { ok: false, reason: "localhost cannot be fetched." };
|
|
@@ -1044,7 +1852,7 @@ function createLimiter(options = {}) {
|
|
|
1044
1852
|
}
|
|
1045
1853
|
|
|
1046
1854
|
// src/probe/index.ts
|
|
1047
|
-
var ARS_USER_AGENT = "rebilder-ars/0.
|
|
1855
|
+
var ARS_USER_AGENT = "rebilder-ars/0.3 (+https://rebilder.com/bots)";
|
|
1048
1856
|
var AGENT_IDENTITY = {
|
|
1049
1857
|
role: "agent",
|
|
1050
1858
|
userAgent: ARS_USER_AGENT,
|
|
@@ -1338,6 +2146,16 @@ async function probeWithHostPolicy(target, policy, hostPolicy, options = {}) {
|
|
|
1338
2146
|
};
|
|
1339
2147
|
}
|
|
1340
2148
|
};
|
|
2149
|
+
const runPage = async (href, headers) => {
|
|
2150
|
+
const record = await run(href, headers);
|
|
2151
|
+
if (!record.result.ok) return record;
|
|
2152
|
+
const challenge = detectEdgeChallenge(record.result.capture);
|
|
2153
|
+
if (challenge === null) return record;
|
|
2154
|
+
return {
|
|
2155
|
+
requestHeaders: headers,
|
|
2156
|
+
result: { ok: false, error: "challenge", detail: challengeDetail(challenge) }
|
|
2157
|
+
};
|
|
2158
|
+
};
|
|
1341
2159
|
const evidenceOf = (probes) => ({
|
|
1342
2160
|
ok: true,
|
|
1343
2161
|
evidence: {
|
|
@@ -1382,8 +2200,18 @@ async function probeWithHostPolicy(target, policy, hostPolicy, options = {}) {
|
|
|
1382
2200
|
wellKnownUcp: null
|
|
1383
2201
|
});
|
|
1384
2202
|
}
|
|
1385
|
-
const agent = await
|
|
1386
|
-
const browser = await
|
|
2203
|
+
const agent = await runPage(url.toString(), agentHeaders);
|
|
2204
|
+
const browser = await runPage(url.toString(), browserHeaders);
|
|
2205
|
+
const linked = markdownAlternateTarget(
|
|
2206
|
+
agent.result.ok ? agent.result.capture : null,
|
|
2207
|
+
browser.result.ok ? browser.result.capture : null,
|
|
2208
|
+
origin
|
|
2209
|
+
);
|
|
2210
|
+
let markdownAlternate = null;
|
|
2211
|
+
if (linked !== null) {
|
|
2212
|
+
const rule = disallowedFor(new URL(linked).pathname);
|
|
2213
|
+
markdownAlternate = rule !== null ? skipped(agentHeaders, `robots.txt disallows ${ARS_ROBOTS_TOKEN} for ${linked}`) : await runPage(linked, agentHeaders);
|
|
2214
|
+
}
|
|
1387
2215
|
const fetchAsset = async (path) => {
|
|
1388
2216
|
const rule = disallowedFor(path);
|
|
1389
2217
|
if (rule !== null)
|
|
@@ -1392,7 +2220,17 @@ async function probeWithHostPolicy(target, policy, hostPolicy, options = {}) {
|
|
|
1392
2220
|
};
|
|
1393
2221
|
const llmsTxt = await fetchAsset("/llms.txt");
|
|
1394
2222
|
const wellKnownUcp = await fetchAsset("/.well-known/ucp");
|
|
1395
|
-
return evidenceOf({
|
|
2223
|
+
return evidenceOf({
|
|
2224
|
+
agent,
|
|
2225
|
+
browser,
|
|
2226
|
+
parityConfirm: null,
|
|
2227
|
+
// Omitted when not taken, so a page with no linked copy produces exactly
|
|
2228
|
+
// the bundle (and the evidence hash) it produced under 0.2.
|
|
2229
|
+
...markdownAlternate === null ? {} : { markdownAlternate },
|
|
2230
|
+
robotsTxt,
|
|
2231
|
+
llmsTxt,
|
|
2232
|
+
wellKnownUcp
|
|
2233
|
+
});
|
|
1396
2234
|
} catch (error) {
|
|
1397
2235
|
if (error instanceof ProbeBudgetExceededError) {
|
|
1398
2236
|
return { ok: false, rejection: "budget-exceeded", detail: error.message };
|