@dogsbay/site-files 0.2.0-beta.179 → 0.2.0-beta.181

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.
@@ -25,8 +25,11 @@ export interface LinkSummary {
25
25
  label?: string;
26
26
  /** About `EXCERPT_LENGTH` characters of the first paragraph, cut on a word; may be empty. */
27
27
  excerpt: string;
28
- /** What the link names: the page, a heading on it, or another target (a figure, a table). */
29
- kind: "page" | "heading" | "target";
28
+ /**
29
+ * What the link names: the page, a heading on it, another target (a figure, a table), or a
30
+ * footnote (its text is the excerpt, and the title is empty: the card shows the note alone).
31
+ */
32
+ kind: "page" | "heading" | "target" | "footnote";
30
33
  }
31
34
  /** An excerpt is cut near this many characters, on a word. */
32
35
  export declare const EXCERPT_LENGTH = 200;
@@ -204,7 +204,7 @@ function* elements(root) {
204
204
  }
205
205
  const hidden = (e) => e.attrs["aria-hidden"] === "true" || "hidden" in e.attrs || e.tag === "template";
206
206
  /** An element's text as a reader sees it: entities decoded, hidden parts left out, spaces collapsed. */
207
- function textOf(el) {
207
+ function textOf(el, skip) {
208
208
  let out = "";
209
209
  const stack = [el];
210
210
  while (stack.length) {
@@ -213,7 +213,7 @@ function textOf(el) {
213
213
  out += decode(n);
214
214
  continue;
215
215
  }
216
- if (n !== el && (hidden(n) || NO_TEXT.has(n.tag) || n.tag === "script" || n.tag === "style"))
216
+ if (n !== el && (hidden(n) || NO_TEXT.has(n.tag) || n.tag === "script" || n.tag === "style" || skip?.(n)))
217
217
  continue;
218
218
  if (n.tag === "br")
219
219
  out += " ";
@@ -222,6 +222,20 @@ function textOf(el) {
222
222
  }
223
223
  return out.replace(/[\s ]+/g, " ").trim();
224
224
  }
225
+ /** A footnote is cut near this many characters (a note is read whole where it is short enough). */
226
+ const FOOTNOTE_LENGTH = 600;
227
+ /** Whether `li` is an item of a footnotes list (its list in a section marked as the page's notes). */
228
+ function inFootnotes(li) {
229
+ for (let e = li.parent, depth = 0; e && depth < 4; e = e.parent, depth++) {
230
+ if (e.attrs.role === "doc-endnotes" || "data-footnotes" in e.attrs || /(?:^|\s)footnotes(?:\s|$)/.test(e.attrs.class ?? ""))
231
+ return true;
232
+ }
233
+ return false;
234
+ }
235
+ /** A footnote's text without its back-link (`role="doc-backlink"`, or a link that is only `↩`). */
236
+ function footnoteText(li) {
237
+ return textOf(li, (e) => e.tag === "a" && (e.attrs.role === "doc-backlink" || (e.children.length === 1 && typeof e.children[0] === "string" && /^\s*↩\uFE0E?\s*$/.test(decode(e.children[0])))));
238
+ }
225
239
  /** Whether `a` is `b` or holds it. */
226
240
  const holds = (a, b) => a.start <= b.start && b.end <= a.end;
227
241
  /** Whether nothing between `el` and `top` (an aside, a figure, chrome, hidden) makes its text not the page's prose. */
@@ -343,6 +357,13 @@ export function linkSummary(html, id) {
343
357
  kind: "heading",
344
358
  };
345
359
  }
360
+ // A footnote (an item of a footnotes list: render-html's `role="doc-endnotes"`, format-astro's
361
+ // `data-footnotes`): its whole text, without its `↩` back-link, as the card. GitBook's
362
+ // annotations are footnotes in its `.md`, and a popover on GitBook's site (2026-11-19)
363
+ if (target.tag === "li" && inFootnotes(target)) {
364
+ const text = footnoteText(target);
365
+ return text ? { title: "", excerpt: cut(text, FOOTNOTE_LENGTH), kind: "footnote" } : undefined;
366
+ }
346
367
  const inside = firstParagraph(elements(target), target);
347
368
  const own = !inside && TEXT_BLOCK.has(target.tag) ? cut(textOf(target)) : "";
348
369
  return { title, label: targetLabel(target), excerpt: inside || own, kind: "target" };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dogsbay/site-files",
3
- "version": "0.2.0-beta.179",
3
+ "version": "0.2.0-beta.181",
4
4
  "description": "robots.txt, _headers, llms.txt, sitemaps, redirects and JSON-LD for docs sites; shared by the dogsbay Astro pipeline and dogsbay-ssg, Worker-safe",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",