@iyulab/canopy-page 0.13.0 → 0.14.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 CHANGED
@@ -7,6 +7,35 @@ Notable changes to canopy-page. The format follows
7
7
  The `settings.json` contract is what consuming projects plan their upgrades around, so changes
8
8
  to it — its fields, its validation, and what the checks reject — are what this file is about.
9
9
 
10
+ ## [0.14.0] — 2026-09-17
11
+
12
+ ### Added
13
+
14
+ - **`siteUrl` now reaches the pages, not just the sitemap.** It is passed to canopy as
15
+ `--site-url`, so every page carries `<link rel="canonical">` and `og:url` naming its one
16
+ address — by exactly the string the sitemap lists it under, since both now come from canopy's
17
+ own `pageUrl()` rule rather than two copies of it. A page's frontmatter `description:` fills
18
+ its own `<meta name="description">` (the site's stays the fallback), and the Open Graph basics
19
+ ride on every page with or without `siteUrl`. Body links stay relative either way.
20
+ - **`previewImage`** — the image link previews show (`og:image`) for any page whose frontmatter
21
+ has no `image:` of its own. Validated like `icon`/`logo` (a published file), and rejected
22
+ without `siteUrl`, since the tag has to be absolute.
23
+ - **`alternates`** — the site's other language editions, `hreflang` → that edition's own site
24
+ URL (`x-default` allowed). Each page lists its counterpart at the same path under every
25
+ edition, its own first, as `hreflang` links in `<head>` and as `xhtml:link` entries in
26
+ `sitemap.xml`. Rejected without `siteUrl`.
27
+ - **`check` warns about pages with no `description:` of their own once `siteUrl` is set** — one
28
+ warning naming them all, never an error. A public site's pages otherwise present one
29
+ identical summary in every search result, and `siteUrl` is the setting that says the site is
30
+ public.
31
+
32
+ ### Changed
33
+
34
+ - **Sidebar redesign, via canopy 0.13.0** — rows with padding, a hover surface and a focus
35
+ ring; the group chevron moves to the row's trailing edge so labels at one depth share a left
36
+ edge; nested lists carry a guide line. Two new tokens, `--sidebar-hover-bg` and `--sp-1`. A
37
+ `tokens` file that styled `.canopy-nav-group > summary::before` should target `::after`.
38
+
10
39
  ## [0.13.0] — 2026-08-22
11
40
 
12
41
  ### Added
package/README.md CHANGED
@@ -10,6 +10,10 @@ itself is [canopy](https://github.com/iyulab/canopy)'s job, and canopy-page driv
10
10
  **Live docs**: <https://iyulab.github.io/canopy-page> — built with canopy-page itself, from the
11
11
  [`examples/site`](examples/site) in this repository, republished on every push to `main`.
12
12
 
13
+ **Complete reference**: [`docs/USAGE.md`](docs/USAGE.md) — every command, every
14
+ `settings.json` field, every markdown feature, and everything a published site ships with, in
15
+ one document. This README stays the short version.
16
+
13
17
  ---
14
18
 
15
19
  ## Why
@@ -53,6 +57,11 @@ go away.
53
57
  - **A code block wider than the screen shows a shadow at whichever edge still has more to
54
58
  scroll to**, and nothing once you've scrolled there — a cue for a scrollbar that some
55
59
  OS/browser combinations hide until hovered
60
+ - **Search and link-preview metadata in every page's `<head>`** — a page's own frontmatter
61
+ `description:` (falling back to the site's), the Open Graph basics and a `twitter:card`; once
62
+ `siteUrl` is set, also a canonical URL, `og:url`, `og:image` (`previewImage`, or a page's own
63
+ `image:`), and `hreflang` links to the language editions `alternates` names. Body links stay
64
+ relative regardless, so the same output still opens from a local folder
56
65
  - **Sitemap and `robots.txt`**, once `siteUrl` is set
57
66
 
58
67
  See it live at <https://iyulab.github.io/canopy-page>, or read
package/dist/build.js CHANGED
@@ -22,6 +22,14 @@ export function canopyArgs(site, out, navPath, searchAssets) {
22
22
  out,
23
23
  ...(settings.title === undefined ? [] : ["--site-title", settings.title]),
24
24
  ...(settings.description === undefined ? [] : ["--site-description", settings.description]),
25
+ // The same URL the sitemap below is written against, so canopy's canonical
26
+ // tags and the sitemap's entries name each page by one string.
27
+ ...(settings.siteUrl === undefined ? [] : ["--site-url", settings.siteUrl]),
28
+ ...(settings.previewImage === undefined ? [] : ["--site-image", settings.previewImage]),
29
+ ...Object.entries(settings.alternates ?? {}).flatMap(([hreflang, url]) => [
30
+ "--alternate",
31
+ `${hreflang}=${url}`,
32
+ ]),
25
33
  ...(settings.lang === undefined ? [] : ["--lang", settings.lang]),
26
34
  ...(settings.icon === undefined ? [] : ["--site-icon", settings.icon]),
27
35
  // Always present: canopy-page's own CSS (search, scrollspy) rides here
@@ -88,7 +96,10 @@ export async function buildSite({ dir, out }) {
88
96
  if (code === 0 && site.settings.siteUrl !== undefined) {
89
97
  const outDir = path.resolve(out);
90
98
  const pages = await listHtmlFiles(outDir);
91
- await writeFile(path.join(outDir, "sitemap.xml"), sitemapXml(site.settings.siteUrl, pages), "utf8");
99
+ await writeFile(path.join(outDir, "sitemap.xml"), sitemapXml(site.settings.siteUrl, pages, {
100
+ ...(site.settings.lang === undefined ? {} : { lang: site.settings.lang }),
101
+ ...(site.settings.alternates === undefined ? {} : { alternates: site.settings.alternates }),
102
+ }), "utf8");
92
103
  await writeFile(path.join(outDir, "robots.txt"), robotsTxt(site.settings.siteUrl), "utf8");
93
104
  console.log(`canopy-page: sitemap.xml with ${pages.length} page(s)`);
94
105
  }
package/dist/check.d.ts CHANGED
@@ -18,5 +18,23 @@ export declare function referenceFindings(site: LoadedSite): Promise<Finding[]>;
18
18
  * the settings got wrong first, then what the pages point at.
19
19
  */
20
20
  export declare function siteFindings(site: LoadedSite): Promise<Finding[]>;
21
+ /**
22
+ * Pages with no `description:` of their own, on a site that is going to be
23
+ * found by search.
24
+ *
25
+ * Such a page falls back to the site's one description, which is harmless for
26
+ * a site nobody searches and a duplicate summary on every result for one that
27
+ * is public. `siteUrl` is the setting that says which of the two this is — the
28
+ * same gate the sitemap already uses — so the warning waits for it rather than
29
+ * asking for a field of its own. One warning naming every such page, one per
30
+ * line, for the same reason `navFindings` lists uncovered pages that way: on a
31
+ * real site the list runs to dozens, and a warning per page would be a wall.
32
+ * Never an error: a site published somewhere but not meant to be found that way
33
+ * is entitled to ignore this.
34
+ *
35
+ * Frontmatter is read with canopy's own parser, so what counts as a
36
+ * description here is exactly what canopy will put in the page.
37
+ */
38
+ export declare function descriptionFindings(site: LoadedSite): Promise<Finding[]>;
21
39
  /** Check the site in `dir`, returning the exit code to leave with. */
22
40
  export declare function checkSite(dir: string): Promise<number>;
package/dist/check.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import path from "node:path";
3
+ import { parseFrontmatter } from "@iyulab/canopy";
3
4
  import { decodeTarget, extractReferences, isExternalUrl, resolveFrom, targetPath, } from "./references.js";
4
5
  import { loadSite, navFindings, reportFindings, settingsFindings, } from "./site.js";
5
6
  import { toPageKey } from "./vault.js";
@@ -222,6 +223,45 @@ export async function siteFindings(site) {
222
223
  ...navFindings(site.nav),
223
224
  ...filenameEncodingFindings(site),
224
225
  ...(await referenceFindings(site)),
226
+ ...(await descriptionFindings(site)),
227
+ ];
228
+ }
229
+ /**
230
+ * Pages with no `description:` of their own, on a site that is going to be
231
+ * found by search.
232
+ *
233
+ * Such a page falls back to the site's one description, which is harmless for
234
+ * a site nobody searches and a duplicate summary on every result for one that
235
+ * is public. `siteUrl` is the setting that says which of the two this is — the
236
+ * same gate the sitemap already uses — so the warning waits for it rather than
237
+ * asking for a field of its own. One warning naming every such page, one per
238
+ * line, for the same reason `navFindings` lists uncovered pages that way: on a
239
+ * real site the list runs to dozens, and a warning per page would be a wall.
240
+ * Never an error: a site published somewhere but not meant to be found that way
241
+ * is entitled to ignore this.
242
+ *
243
+ * Frontmatter is read with canopy's own parser, so what counts as a
244
+ * description here is exactly what canopy will put in the page.
245
+ */
246
+ export async function descriptionFindings(site) {
247
+ if (site.settings.siteUrl === undefined)
248
+ return [];
249
+ const missing = [];
250
+ for (const page of site.index.pages) {
251
+ const { data } = parseFrontmatter(await readFile(path.join(site.root, page), "utf8"));
252
+ const description = data.description;
253
+ if (typeof description !== "string" || description.trim() === "")
254
+ missing.push(page);
255
+ }
256
+ if (missing.length === 0)
257
+ return [];
258
+ return [
259
+ {
260
+ level: "warning",
261
+ message: `${missing.length} page(s) have no "description:" in their frontmatter, so search ` +
262
+ "results and link previews show the site's description for each of them:\n" +
263
+ missing.map((page) => ` ${page}`).join("\n"),
264
+ },
225
265
  ];
226
266
  }
227
267
  /** Check the site in `dir`, returning the exit code to leave with. */
@@ -95,10 +95,24 @@ export interface Settings {
95
95
  * Where the built site will stand, as an absolute URL.
96
96
  *
97
97
  * Every link canopy writes is relative, so a site needs this for nothing except
98
- * the things that must be absolute: `sitemap.xml` and the robots file that
99
- * points at it. Absent, neither is written.
98
+ * the things that must be absolute: `sitemap.xml`, the robots file that points
99
+ * at it, and the `<head>` tags a search engine reads as addresses — canonical,
100
+ * `og:url`, `og:image`, `hreflang`. Absent, none of them is written.
100
101
  */
101
102
  siteUrl?: string;
103
+ /**
104
+ * Image a link preview shows (`og:image`) for any page whose frontmatter has
105
+ * no `image` of its own, relative to the settings file. Must be a published
106
+ * file, like `icon` and `logo`. Needs `siteUrl`: the tag has to be absolute.
107
+ */
108
+ previewImage?: string;
109
+ /**
110
+ * The site's other language editions, `hreflang` tag → that edition's own
111
+ * absolute site URL (`x-default` allowed). Each page then names its
112
+ * counterpart at the same path under every edition, in `<head>` and in the
113
+ * sitemap. Needs `siteUrl`, which is the entry for this edition itself.
114
+ */
115
+ alternates?: Record<string, string>;
102
116
  /**
103
117
  * Rehype plugins to run on every page, after canopy's own sanitize step and
104
118
  * before syntax highlighting — canopy's fixed extension point for markdown
package/dist/settings.js CHANGED
@@ -54,6 +54,8 @@ export const SETTINGS_KEYS = new Set([
54
54
  "logo",
55
55
  "home",
56
56
  "siteUrl",
57
+ "previewImage",
58
+ "alternates",
57
59
  "rehypePlugins",
58
60
  "strings",
59
61
  ]);
@@ -244,7 +246,7 @@ export function parseSettings(json) {
244
246
  }
245
247
  const value = asObject(raw, "settings", "expected a JSON object");
246
248
  rejectUnknownKeys(value, SETTINGS_KEYS, "settings");
247
- const { title, description, lang, icon, tokens, exclude, sections, logo, home, siteUrl, rehypePlugins, strings, } = value;
249
+ const { title, description, lang, icon, tokens, exclude, sections, logo, home, siteUrl, previewImage, alternates, rehypePlugins, strings, } = value;
248
250
  if (title !== undefined)
249
251
  asString(title, "settings.title");
250
252
  if (description !== undefined)
@@ -286,6 +288,32 @@ export function parseSettings(json) {
286
288
  fail(`settings.siteUrl: "${url}" must be an absolute http(s) URL`);
287
289
  }
288
290
  }
291
+ // Both turn into absolute URLs, and siteUrl is the only thing they can be
292
+ // absolute against — so naming either without it is rejected here, where the
293
+ // message can say what is missing, rather than passed on for canopy to refuse.
294
+ if (previewImage !== undefined && siteUrl === undefined) {
295
+ fail("settings.previewImage: needs siteUrl, since a preview image has to be an absolute URL");
296
+ }
297
+ let parsedAlternates;
298
+ if (alternates !== undefined) {
299
+ const object = asObject(alternates, "settings.alternates", "expected an object of hreflang → site URL");
300
+ if (siteUrl === undefined) {
301
+ fail("settings.alternates: needs siteUrl, since this edition has to be listed alongside the others");
302
+ }
303
+ parsedAlternates = {};
304
+ for (const key of Object.keys(object)) {
305
+ // The same shape `lang` accepts, plus the one reserved value the
306
+ // protocol defines for "no better match".
307
+ if (key !== "x-default" && !/^[A-Za-z0-9]+(-[A-Za-z0-9]+)*$/.test(key)) {
308
+ fail(`settings.alternates: "${key}" is not a language tag like "en" or "ko-KR", or "x-default"`);
309
+ }
310
+ const url = asString(object[key], `settings.alternates.${key}`);
311
+ if (!/^https?:\/\//i.test(url)) {
312
+ fail(`settings.alternates.${key}: "${url}" must be an absolute http(s) URL`);
313
+ }
314
+ parsedAlternates[key] = url;
315
+ }
316
+ }
289
317
  let parsedStrings;
290
318
  if (strings !== undefined) {
291
319
  const object = asObject(strings, "settings.strings", "expected an object");
@@ -317,6 +345,10 @@ export function parseSettings(json) {
317
345
  ...(logo === undefined ? {} : { logo: asRelativePath(logo, "settings.logo") }),
318
346
  ...(parsedHome === undefined ? {} : { home: parsedHome }),
319
347
  ...(siteUrl === undefined ? {} : { siteUrl: siteUrl }),
348
+ ...(previewImage === undefined
349
+ ? {}
350
+ : { previewImage: asRelativePath(previewImage, "settings.previewImage") }),
351
+ ...(parsedAlternates === undefined ? {} : { alternates: parsedAlternates }),
320
352
  ...(parsedStrings === undefined ? {} : { strings: parsedStrings }),
321
353
  ...(rehypePlugins === undefined
322
354
  ? {}
package/dist/sitemap.d.ts CHANGED
@@ -1,5 +1,19 @@
1
- /** A sitemap naming every published page, newline-terminated. */
2
- export declare function sitemapXml(siteUrl: string, htmlPaths: readonly string[]): string;
1
+ /** The site's other language editions, for the sitemap's `xhtml:link` alternates. */
2
+ export interface SitemapEditions {
3
+ /** This edition's own language tag; defaults to "en", as canopy's shell does. */
4
+ lang?: string;
5
+ /** `hreflang` → that edition's own site URL, `x-default` allowed. */
6
+ alternates?: Record<string, string>;
7
+ }
8
+ /**
9
+ * A sitemap naming every published page, newline-terminated.
10
+ *
11
+ * With an edition map, each entry also lists the page's counterpart in every
12
+ * edition, this one included — the sitemap form of the `hreflang` links the
13
+ * pages themselves carry, and the same rule: this edition leads unless the map
14
+ * already places its language explicitly.
15
+ */
16
+ export declare function sitemapXml(siteUrl: string, htmlPaths: readonly string[], editions?: SitemapEditions): string;
3
17
  /**
4
18
  * A robots file whose only job is to point at the sitemap.
5
19
  *
package/dist/sitemap.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { readdir } from "node:fs/promises";
2
2
  import path from "node:path";
3
+ import { pageUrl } from "@iyulab/canopy";
3
4
  /**
4
5
  * The two files a site is found by.
5
6
  *
@@ -13,6 +14,13 @@ import path from "node:path";
13
14
  * a synthetic `index.html` to a site whose root has no index page, and a sitemap
14
15
  * that omitted it would omit the site's front door. Listing files is not reading
15
16
  * them — nothing here parses the HTML canopy produced.
17
+ *
18
+ * `pageUrl` is canopy's own rule for a page's canonical address (an index page
19
+ * is its directory) — the same function the shell uses for `rel="canonical"`,
20
+ * imported rather than restated so the sitemap's `<loc>` and the page's own
21
+ * canonical can never disagree by a character. canopy-page otherwise drives
22
+ * canopy through its command line (see `canopy.ts`); that stance is about the
23
+ * build, and a pure URL rule is not a second door into it.
16
24
  */
17
25
  function escapeXml(value) {
18
26
  return value
@@ -23,25 +31,33 @@ function escapeXml(value) {
23
31
  .replace(/'/g, "&apos;");
24
32
  }
25
33
  /**
26
- * The URL a page is canonically reached by.
34
+ * A sitemap naming every published page, newline-terminated.
27
35
  *
28
- * A directory's index page is the directory: `guide/index.html` and `guide/` are
29
- * one page, and listing both would ask a crawler to treat it as two.
36
+ * With an edition map, each entry also lists the page's counterpart in every
37
+ * edition, this one included the sitemap form of the `hreflang` links the
38
+ * pages themselves carry, and the same rule: this edition leads unless the map
39
+ * already places its language explicitly.
30
40
  */
31
- function pageUrl(base, htmlPath) {
32
- const canonical = htmlPath.replace(/(^|\/)index\.html$/, "$1");
33
- // encodeURI leaves the separators alone and fixes what a URL cannot carry raw.
34
- return `${base}/${encodeURI(canonical)}`;
35
- }
36
- /** A sitemap naming every published page, newline-terminated. */
37
- export function sitemapXml(siteUrl, htmlPaths) {
38
- const base = siteUrl.replace(/\/+$/, "");
41
+ export function sitemapXml(siteUrl, htmlPaths, editions = {}) {
42
+ const editionList = [];
43
+ if (editions.alternates !== undefined) {
44
+ const lang = editions.lang ?? "en";
45
+ if (!Object.hasOwn(editions.alternates, lang))
46
+ editionList.push([lang, siteUrl]);
47
+ editionList.push(...Object.entries(editions.alternates));
48
+ }
39
49
  const entries = [...htmlPaths]
40
50
  .sort()
41
- .map((htmlPath) => ` <url><loc>${escapeXml(pageUrl(base, htmlPath))}</loc></url>`)
51
+ .map((htmlPath) => {
52
+ const alternates = editionList
53
+ .map(([hreflang, base]) => `<xhtml:link rel="alternate" hreflang="${escapeXml(hreflang)}" href="${escapeXml(pageUrl(base, htmlPath))}"/>`)
54
+ .join("");
55
+ return ` <url><loc>${escapeXml(pageUrl(siteUrl, htmlPath))}</loc>${alternates}</url>`;
56
+ })
42
57
  .join("\n");
58
+ const xhtmlNamespace = editionList.length > 0 ? ' xmlns:xhtml="http://www.w3.org/1999/xhtml"' : "";
43
59
  return `<?xml version="1.0" encoding="UTF-8"?>
44
- <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
60
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"${xhtmlNamespace}>
45
61
  ${entries}
46
62
  </urlset>
47
63
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iyulab/canopy-page",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "Authoring pipeline for documentation sites: one settings file, integrity checks, and a build.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -53,7 +53,7 @@
53
53
  "vitest": "^4.1.9"
54
54
  },
55
55
  "dependencies": {
56
- "@iyulab/canopy": "^0.12.0",
56
+ "@iyulab/canopy": "^0.13.0",
57
57
  "chokidar": "^5.0.0"
58
58
  }
59
59
  }