maisongr-sitemap 1.8.2 → 1.8.3

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/README.md CHANGED
@@ -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.3",
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
@@ -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maisongr-sitemap",
3
- "version": "1.8.2",
3
+ "version": "1.8.3",
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
6
  "author": "Maison GR (https://www.maisongr.com)",
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.3",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "maisongr-sitemap",
14
- "version": "1.8.2",
14
+ "version": "1.8.3",
15
15
  "runtimeHint": "npx",
16
16
  "transport": { "type": "stdio" },
17
17
  "packageArguments": [{ "type": "positional", "value": "mcp" }]