maisongr-sitemap 1.8.2 → 1.8.4

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Maison GR
3
+ Copyright (c) 2026 Maison GR Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  ![Runtime dependencies: 0](https://img.shields.io/badge/runtime_dependencies-0-1b1a17)
9
9
  ![Node 20.9+](https://img.shields.io/badge/node-%E2%89%A520.9-1b1a17)
10
10
 
11
- ![One address, two answers: at https://your.site/sitemap.xml, Google and Bing get the standard XML sitemap, and a person opening the same address in a browser gets a page in the site's own design.](.github/assets/hero.png)
11
+ ![Maison GR open source, 01: maisongr-sitemap. One sitemap, two readers. Next to it, npx maisongr-sitemap init at work: 8 pages found and dated from Git, the site's theme read, a private page left out, the sitemap route written.](.github/assets/hero.jpg)
12
12
 
13
13
  ```sh
14
14
  npx maisongr-sitemap init
@@ -78,7 +78,7 @@ Each one has been checked on a real production build: Next.js 15 and 16 (App Rou
78
78
  4. **Dates every page** from Git (see [Dates](#dates)).
79
79
  5. **Reads your theme**:
80
80
  - colour tokens, light and dark: shadcn, Tailwind v4 `@theme`, or plain CSS variables, in stylesheets or in a layout's `<style>`;
81
- - fonts: `next/font`, your own `@font-face` files, Fontsource packages, Astro's Fonts API, or the family your CSS names, fetched once from Google Fonts. All are served from your own domain under `/_sitemap/`;
81
+ - fonts: `next/font`, your own `@font-face` files, Fontsource packages, Astro's Fonts API, or the family your CSS names, fetched once from Google Fonts (commit the files: later builds reuse them; delete them to fetch again). All are served from your own domain under `/_sitemap/`;
82
82
  - your site's name and icon.
83
83
  6. **Reads your config**: the site address, and the base path and trailing slash (Next.js `basePath` and `trailingSlash`, Astro `site`, `base` and `trailingSlash`, SvelteKit `paths.base`, Nuxt `app.baseURL` and `site.url`). No address in the sitemap redirects.
84
84
  7. **Writes** the route and its `manifest.json`, then puts `maisongr-sitemap build` at the start of your `build` script, so every build re-reads all of it. It goes in `build` itself, not `prebuild`, because pnpm and Yarn 2+ never run `prebuild`.
@@ -487,7 +487,7 @@ npx skills add maison-gr/maisongr-sitemap
487
487
  {
488
488
  "ok": true,
489
489
  "command": "init",
490
- "version": "1.8.2",
490
+ "version": "1.8.4",
491
491
  "subject": "Next.js 16 · App Router",
492
492
  "sections": [{ "heading": "Wrote", "items": [{ "status": "ok", "text": "app/sitemap.xml/route.ts" }] }],
493
493
  "warnings": 0
@@ -518,6 +518,15 @@ Node 20.9 or later. No runtime dependencies.
518
518
 
519
519
  The package is an ES module. A CommonJS project that calls `require("maisongr-sitemap/node")` itself needs Node 20.19 or 22.12 or later, which load ES modules through `require`; the `sitemap.js` that `init` writes loads it with `import()`, which works on every supported version.
520
520
 
521
+ ## More from Maison GR
522
+
523
+ Open source from [Maison GR](https://www.maisongr.com), a software studio in Québec City:
524
+
525
+ - [Maison GR Sitemap for WordPress](https://github.com/maison-gr/maisongr-sitemap-wordpress): the same sitemap for WordPress, in your theme's colours and type.
526
+ - [maisongr-skills](https://github.com/maison-gr/maisongr-skills): one engineering standard for every AI coding agent: Claude Code, Codex, Cursor, Copilot, Gemini CLI.
527
+ - [maisongr-typo](https://github.com/maison-gr/maisongr-typo): French typography, the Québec way, with a CI check.
528
+ - [maisongr-law25](https://github.com/maison-gr/maisongr-law25): your Law 25 privacy impact assessment, next to your code, checked in CI.
529
+
521
530
  ## License
522
531
 
523
- MIT © [Maison GR](https://www.maisongr.com)
532
+ MIT © [Maison GR Inc.](https://www.maisongr.com)
@@ -1,4 +1,4 @@
1
- import { copyFileSync, existsSync, mkdirSync, writeFileSync } from "node:fs";
1
+ import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
2
2
  import { basename, join, resolve as resolvePath } from "node:path";
3
3
  /** Where the page's fonts are written, under the site's public directory. */
4
4
  export const FONT_DIR = "_sitemap";
@@ -66,6 +66,29 @@ export function nextFonts(layoutSource, layoutDir) {
66
66
  export const isWoff2 = (bytes) => bytes.length > 4 && bytes[0] === 0x77 && bytes[1] === 0x4f && bytes[2] === 0x46 && bytes[3] === 0x32;
67
67
  const UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0 Safari/537.36";
68
68
  const slug = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
69
+ /**
70
+ * A Google font a previous build already wrote to public/_sitemap/, read from its file names
71
+ * ("newsreader-400-600-italic.woff2" → weight "400 600", italic). Reusing it keeps every build
72
+ * byte-for-byte the same and safe from a failed download (#18); delete the files to fetch them again.
73
+ */
74
+ function committed(family, role, publicDir) {
75
+ const dir = join(publicDir, FONT_DIR);
76
+ if (!existsSync(dir))
77
+ return null;
78
+ const prefix = `${slug(family)}-`;
79
+ const files = [];
80
+ for (const name of readdirSync(dir).sort()) {
81
+ if (!name.startsWith(prefix))
82
+ continue;
83
+ const m = name.slice(prefix.length).match(/^(\d+)(?:-(\d+))?(-italic)?\.woff2$/);
84
+ if (!m || !isWoff2(readFileSync(join(dir, name))))
85
+ continue;
86
+ files.push({ url: `/${FONT_DIR}/${name}`, weight: m[2] ? `${m[1]} ${m[2]}` : m[1], style: m[3] ? "italic" : "normal" });
87
+ }
88
+ // Upright before italic, then by weight: the order a download lists them in.
89
+ files.sort((a, b) => Number(a.style === "italic") - Number(b.style === "italic") || parseInt(a.weight) - parseInt(b.weight));
90
+ return files.length ? { role, family, files } : null;
91
+ }
69
92
  /** Downloads a Google font's Latin files once, at build time, so the page serves them from the site itself. */
70
93
  async function google(family, role, publicDir) {
71
94
  const name = encodeURIComponent(family).replace(/%20/g, "+");
@@ -143,7 +166,9 @@ export async function materialize(sources, publicDir, offline = false) {
143
166
  for (const s of sources) {
144
167
  if (fonts.some((f) => f.role === s.role))
145
168
  continue; // one font per role
146
- const font = s.kind === "local" ? local(s, publicDir) : offline ? null : await google(s.family, s.role, publicDir);
169
+ const font = s.kind === "local"
170
+ ? local(s, publicDir)
171
+ : (committed(s.family, s.role, publicDir) ?? (offline ? null : await google(s.family, s.role, publicDir)));
147
172
  if (font)
148
173
  fonts.push(font);
149
174
  else
@@ -8,17 +8,25 @@ import { cssFiles, findHreflang, findIcon, findLocales, findName, findSite, sour
8
8
  const MIDDLEWARE = ["middleware.ts", "middleware.js", "proxy.ts", "proxy.js", "src/middleware.ts", "src/middleware.js", "src/proxy.ts", "src/proxy.js"];
9
9
  /**
10
10
  * The site's languages: for routes under a [locale] folder, or, with no such
11
- * folder, when the middleware puts every page under /{language}/.
11
+ * folder, when the middleware puts every page under /{language}/. A middleware
12
+ * that names locales doesn't do that when the pages already sit in a
13
+ * language's folder (app/fr/about as its own route): it may only tell the 404
14
+ * page which language was asked for, and prefixing every route would list
15
+ * /en/about and /fr/fr/about, which don't exist.
12
16
  */
13
17
  function localesOf(root, routes, files) {
14
18
  const segmented = routes.some((r) => /^\/\[(locale|lang)\]/.test(r.pattern));
15
19
  const middleware = MIDDLEWARE.map((f) => join(root, f)).find(existsSync);
16
- const prefixed = !segmented && !!middleware && /locale/i.test(read(middleware));
17
- if (!segmented && !prefixed)
20
+ const namesLocales = !segmented && !!middleware && /locale/i.test(read(middleware));
21
+ if (!segmented && !namesLocales)
18
22
  return undefined;
19
23
  const found = findLocales(files);
20
24
  if (!found)
21
25
  return undefined;
26
+ const inFolders = routes.some((r) => found.list.includes(r.pattern.split("/")[1] ?? ""));
27
+ const prefixed = namesLocales && !inFolders;
28
+ if (!segmented && !prefixed)
29
+ return undefined;
22
30
  const hreflang = findHreflang(files, found.list);
23
31
  return { ...found, ...(prefixed ? { prefix: true } : {}), ...(hreflang ? { hreflang } : {}) };
24
32
  }
@@ -1,8 +1,15 @@
1
1
  import type { Palette } from "../types.js";
2
2
  export declare const DEFAULT_PALETTE: Palette;
3
- /** sRGB of hex, rgb() and hsl() colours; null for formats this does not compute (oklch…). */
3
+ type Rgba = [number, number, number, number];
4
+ /** sRGB and alpha of hex (#rgb, #rgba, #rrggbb, #rrggbbaa), rgb() and hsl() colours; null for formats this does not compute (oklch…). */
5
+ export declare function rgbaOf(color: string): Rgba | null;
6
+ /** sRGB of a colour, its alpha left out. */
4
7
  export declare function rgbOf(color: string): [number, number, number] | null;
5
- /** WCAG contrast ratio, or null when either colour is in a format not computed here. */
8
+ /**
9
+ * WCAG contrast ratio of the first colour shown on the second, so a translucent one counts as it looks; null when
10
+ * either colour is in a format not computed here.
11
+ */
6
12
  export declare function contrast(a: string, b: string): number | null;
7
13
  /** The palette for one scheme, or null when the site defines no background and text colour for it. */
8
14
  export declare function palette(...maps: Map<string, string>[]): Palette | null;
15
+ export {};
@@ -29,26 +29,42 @@ function pick(role, ...maps) {
29
29
  }
30
30
  return null;
31
31
  }
32
- /** sRGB of hex, rgb() and hsl() colours; null for formats this does not compute (oklch…). */
33
- export function rgbOf(color) {
34
- const hex = color.match(/^#([\da-f]{3,8})$/i)?.[1];
32
+ /** An alpha written 0.3 or 30%, clamped to 0–1; 1 when none is written. */
33
+ const alphaOf = (value, percent) => value === undefined ? 1 : Math.min(1, Math.max(0, Number(value) / (percent ? 100 : 1)));
34
+ /** sRGB and alpha of hex (#rgb, #rgba, #rrggbb, #rrggbbaa), rgb() and hsl() colours; null for formats this does not compute (oklch…). */
35
+ export function rgbaOf(color) {
36
+ const hex = color.match(/^#([\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i)?.[1];
35
37
  if (hex) {
36
- const full = hex.length <= 4 ? [...hex.slice(0, 3)].map((c) => c + c).join("") : hex.slice(0, 6);
37
- return [0, 2, 4].map((i) => parseInt(full.slice(i, i + 2), 16));
38
+ const full = hex.length <= 4 ? [...hex].map((c) => c + c).join("") : hex;
39
+ const [r, g, b] = [0, 2, 4].map((i) => parseInt(full.slice(i, i + 2), 16));
40
+ return [r, g, b, full.length === 8 ? parseInt(full.slice(6, 8), 16) / 255 : 1];
38
41
  }
39
- const rgb = color.match(/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/i);
42
+ // The alpha after a comma (rgba(0, 0, 0, 0.3)) or a slash (rgb(0 0 0 / 30%)).
43
+ const rgb = color.match(/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:[\s,/]+([\d.]+)(%?))?/i);
40
44
  if (rgb)
41
- return [Number(rgb[1]), Number(rgb[2]), Number(rgb[3])];
42
- const hsl = color.match(/^hsla?\(\s*(-?[\d.]+)(?:deg)?[\s,]+([\d.]+)%[\s,]+([\d.]+)%/i);
45
+ return [Number(rgb[1]), Number(rgb[2]), Number(rgb[3]), alphaOf(rgb[4], rgb[5])];
46
+ const hsl = color.match(/^hsla?\(\s*(-?[\d.]+)(?:deg)?[\s,]+([\d.]+)%[\s,]+([\d.]+)%(?:[\s,/]+([\d.]+)(%?))?/i);
43
47
  if (hsl) {
44
48
  const h = ((Number(hsl[1]) % 360) + 360) % 360, s = Number(hsl[2]) / 100, l = Number(hsl[3]) / 100;
45
49
  const k = (n) => (n + h / 30) % 12;
46
50
  const a = s * Math.min(l, 1 - l);
47
51
  const f = (n) => l - a * Math.max(-1, Math.min(k(n) - 3, 9 - k(n), 1));
48
- return [f(0), f(8), f(4)].map((v) => Math.round(v * 255));
52
+ const [r, g, b] = [f(0), f(8), f(4)].map((v) => Math.round(v * 255));
53
+ return [r, g, b, alphaOf(hsl[4], hsl[5])];
49
54
  }
50
55
  return null;
51
56
  }
57
+ /** sRGB of a colour, its alpha left out. */
58
+ export function rgbOf(color) {
59
+ const c = rgbaOf(color);
60
+ return c ? [c[0], c[1], c[2]] : null;
61
+ }
62
+ /** A colour as it shows over another (alpha compositing); the lower one over white when it is translucent too. */
63
+ const over = (top, under) => {
64
+ const base = under[3] < 1 ? over(under, [255, 255, 255, 1]) : under;
65
+ const a = top[3];
66
+ return [0, 1, 2].map((i) => top[i] * a + base[i] * (1 - a)).concat(1);
67
+ };
52
68
  const luminance = ([r, g, b]) => {
53
69
  const c = [r, g, b].map((v) => {
54
70
  const s = v / 255;
@@ -56,11 +72,16 @@ const luminance = ([r, g, b]) => {
56
72
  });
57
73
  return 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];
58
74
  };
59
- /** WCAG contrast ratio, or null when either colour is in a format not computed here. */
75
+ /**
76
+ * WCAG contrast ratio of the first colour shown on the second, so a translucent one counts as it looks; null when
77
+ * either colour is in a format not computed here.
78
+ */
60
79
  export function contrast(a, b) {
61
- const x = rgbOf(a), y = rgbOf(b);
62
- if (!x || !y)
80
+ const top = rgbaOf(a), under = rgbaOf(b);
81
+ if (!top || !under)
63
82
  return null;
83
+ const y = over([0, 0, 0, 0], under);
84
+ const x = over(top, y);
64
85
  const [hi, lo] = [luminance(x), luminance(y)].sort((p, q) => q - p);
65
86
  return (hi + 0.05) / (lo + 0.05);
66
87
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "maisongr-sitemap",
3
- "version": "1.8.2",
3
+ "version": "1.8.4",
4
4
  "description": "One sitemap, two readers: the XML search engines need, and a page in your site's own design for people. Detects your stack, finds your pages, dates them from Git.",
5
5
  "license": "MIT",
6
- "author": "Maison GR (https://www.maisongr.com)",
6
+ "author": "Maison GR Inc. (https://www.maisongr.com)",
7
7
  "homepage": "https://github.com/maison-gr/maisongr-sitemap#readme",
8
8
  "mcpName": "io.github.maison-gr/sitemap",
9
9
  "repository": {
package/server.json CHANGED
@@ -6,12 +6,12 @@
6
6
  "url": "https://github.com/maison-gr/maisongr-sitemap",
7
7
  "source": "github"
8
8
  },
9
- "version": "1.8.2",
9
+ "version": "1.8.4",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "maisongr-sitemap",
14
- "version": "1.8.2",
14
+ "version": "1.8.4",
15
15
  "runtimeHint": "npx",
16
16
  "transport": { "type": "stdio" },
17
17
  "packageArguments": [{ "type": "positional", "value": "mcp" }]