@dogsbay/format-astro 0.2.0-beta.8 → 0.2.0-beta.81
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/dist/base-path.d.ts +105 -7
- package/dist/base-path.d.ts.map +1 -1
- package/dist/base-path.js +136 -7
- package/dist/base-path.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1 -0
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/lead.d.ts +19 -0
- package/dist/lead.d.ts.map +1 -1
- package/dist/lead.js +71 -0
- package/dist/lead.js.map +1 -1
- package/dist/llms-txt.d.ts +13 -2
- package/dist/llms-txt.d.ts.map +1 -1
- package/dist/llms-txt.js +79 -12
- package/dist/llms-txt.js.map +1 -1
- package/dist/project.d.ts +160 -5
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +973 -108
- package/dist/project.js.map +1 -1
- package/dist/serialize.d.ts +22 -0
- package/dist/serialize.d.ts.map +1 -1
- package/dist/serialize.js +159 -17
- package/dist/serialize.js.map +1 -1
- package/dist/sitemap.d.ts +57 -0
- package/dist/sitemap.d.ts.map +1 -0
- package/dist/sitemap.js +136 -0
- package/dist/sitemap.js.map +1 -0
- package/dist/taxonomy.d.ts +37 -0
- package/dist/taxonomy.d.ts.map +1 -1
- package/dist/taxonomy.js +60 -19
- package/dist/taxonomy.js.map +1 -1
- package/package.json +4 -4
package/dist/project.js
CHANGED
|
@@ -4,14 +4,29 @@
|
|
|
4
4
|
* Takes ExportPage[] + NavItem[] and generates a complete Astro project
|
|
5
5
|
* with static .astro pages using real Dogsbay components.
|
|
6
6
|
*/
|
|
7
|
-
import { existsSync, mkdirSync, writeFileSync, readFileSync, cpSync, readdirSync, statSync, } from "node:fs";
|
|
7
|
+
import { existsSync, mkdirSync, writeFileSync, readFileSync, copyFileSync, cpSync, readdirSync, statSync, } from "node:fs";
|
|
8
8
|
import { join, dirname, relative, resolve } from "node:path";
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
10
|
import { treeToDogsbayMd } from "@dogsbay/format-dogsbay-md";
|
|
11
|
-
import { treeToAstro } from "./serialize.js";
|
|
11
|
+
import { treeToAstro, TONE_CLASSES } from "./serialize.js";
|
|
12
12
|
import { buildLlmsTxt, buildSectionLlmsTxt, buildLlmsFullTxt } from "./llms-txt.js";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
13
|
+
import { buildSitemap, buildSitemapIndex } from "./sitemap.js";
|
|
14
|
+
import { normalizeBasePath, basePathSegments, buildCurrentPath, withBasePath, parseSiteUrl, combinePrefix, } from "./base-path.js";
|
|
15
|
+
/**
|
|
16
|
+
* Combined URL prefix = urlBase (Astro `base` from site.url path) +
|
|
17
|
+
* basePath (filesystem layout prefix). Every URL emitter (nav,
|
|
18
|
+
* sitemap, llms.txt, .md mirror, _headers, taxonomy) uses this for
|
|
19
|
+
* href output. Filesystem-layout consumers (mkdir, page output
|
|
20
|
+
* paths) keep using basePath alone — Astro's `base` config adds the
|
|
21
|
+
* urlBase prefix at route time.
|
|
22
|
+
*
|
|
23
|
+
* See plans/astro-base-from-site-url.md.
|
|
24
|
+
*/
|
|
25
|
+
function combinedPrefix(options) {
|
|
26
|
+
const { urlBase } = parseSiteUrl(options.siteUrl);
|
|
27
|
+
return combinePrefix(urlBase, normalizeBasePath(options.basePath));
|
|
28
|
+
}
|
|
29
|
+
import { detectLeadingNodes, deriveDescription } from "./lead.js";
|
|
15
30
|
/**
|
|
16
31
|
* Recursively prefix all hrefs in a nav tree.
|
|
17
32
|
* Turns `<basePath>/foo` into `<basePath>/{section}/foo`. The
|
|
@@ -49,6 +64,39 @@ function prefixNavHrefs(items, section, basePath) {
|
|
|
49
64
|
function escapeRegex(s) {
|
|
50
65
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
51
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Prefix the combined URL base onto root-absolute nav hrefs.
|
|
69
|
+
*
|
|
70
|
+
* Most importers emit nav hrefs already carrying the combined prefix —
|
|
71
|
+
* the dogsbay-md importer walks source paths through
|
|
72
|
+
* `fileToHref(file, hrefPrefix=combined)`, so OpenShift's `nav.yml`
|
|
73
|
+
* (`welcome/foo.md`) resolves straight to `/<base>/welcome/foo`. But an
|
|
74
|
+
* importer that produces a nav.json of *pre-resolved* hrefs at a
|
|
75
|
+
* different base — e.g. `dogsbay convert --from docusaurus --to
|
|
76
|
+
* dogsbay-md`, whose hrefs are root-absolute (`/about/foo`) — would
|
|
77
|
+
* otherwise emit unprefixed nav links that 404 under a site base, and
|
|
78
|
+
* break prev/next (pagination matches against the combined-prefixed
|
|
79
|
+
* `currentPath`).
|
|
80
|
+
*
|
|
81
|
+
* Running every nav href through `rewriteHref` here is the single
|
|
82
|
+
* chokepoint that makes nav base-correct for ALL importers. It's
|
|
83
|
+
* idempotent — hrefs already starting with the prefix (or external /
|
|
84
|
+
* anchor / protocol-relative) are left untouched — so importer-side
|
|
85
|
+
* prefixing keeps working unchanged, and an empty prefix is a no-op.
|
|
86
|
+
*/
|
|
87
|
+
function prefixNavBaseHrefs(items, prefix) {
|
|
88
|
+
if (!prefix)
|
|
89
|
+
return items;
|
|
90
|
+
return items.map((item) => {
|
|
91
|
+
const result = { ...item };
|
|
92
|
+
if (result.href)
|
|
93
|
+
result.href = rewriteHref(result.href, prefix);
|
|
94
|
+
if (result.children) {
|
|
95
|
+
result.children = prefixNavBaseHrefs(result.children, prefix);
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
52
100
|
/**
|
|
53
101
|
* Rewrite internal hrefs in a page's tree nodes.
|
|
54
102
|
* Prepends `prefix` to root-relative links (e.g. `/workers/...` → `/docs/workers/...`).
|
|
@@ -97,6 +145,55 @@ function rewriteHref(href, prefix) {
|
|
|
97
145
|
return href;
|
|
98
146
|
return prefix + href;
|
|
99
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Rewrite image srcs in inline nodes + raw HTML to include the
|
|
150
|
+
* combined URL prefix.
|
|
151
|
+
*
|
|
152
|
+
* Astro auto-prefixes `<a href>` and image imports going through
|
|
153
|
+
* `<AstroImage>`, but raw `<img src="...">` HTML in template
|
|
154
|
+
* output is left untouched. The serializer emits raw `<img>` for
|
|
155
|
+
* inline images and falls back to it for non-optimized block
|
|
156
|
+
* images, so we have to prefix manually before serialization to
|
|
157
|
+
* make `/_assets/...` paths resolve under subpath-mounted deploys
|
|
158
|
+
* (GH Pages project pages, multi-mount Cloudflare).
|
|
159
|
+
*
|
|
160
|
+
* Symmetric with rewriteTreeHrefs — same skip-rules (external,
|
|
161
|
+
* anchors, already-prefixed). Block images keep their prefix
|
|
162
|
+
* stripped back off for the `imageMap[...]` lookup key (see
|
|
163
|
+
* paragraphToAstro in serialize.ts) so Astro's image optimization
|
|
164
|
+
* still finds the source.
|
|
165
|
+
*/
|
|
166
|
+
function rewriteTreeImageSrcs(nodes, prefix) {
|
|
167
|
+
for (const node of nodes) {
|
|
168
|
+
if (node.inline) {
|
|
169
|
+
rewriteInlineImageSrcs(node.inline, prefix);
|
|
170
|
+
}
|
|
171
|
+
if (node.html) {
|
|
172
|
+
node.html = rewriteHtmlImageSrcs(node.html, prefix);
|
|
173
|
+
}
|
|
174
|
+
if (node.children) {
|
|
175
|
+
rewriteTreeImageSrcs(node.children, prefix);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function rewriteInlineImageSrcs(nodes, prefix) {
|
|
180
|
+
for (const node of nodes) {
|
|
181
|
+
if (node.type === "image" && typeof node.src === "string") {
|
|
182
|
+
node.src = rewriteHref(node.src, prefix);
|
|
183
|
+
}
|
|
184
|
+
else if (node.type === "link") {
|
|
185
|
+
// Links wrap inline children (which may include images) — same
|
|
186
|
+
// recursion shape as rewriteInlineHrefs.
|
|
187
|
+
rewriteInlineImageSrcs(node.children, prefix);
|
|
188
|
+
}
|
|
189
|
+
else if (node.type === "highlight" && node.children) {
|
|
190
|
+
rewriteInlineImageSrcs(node.children, prefix);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function rewriteHtmlImageSrcs(html, prefix) {
|
|
195
|
+
return html.replace(/(<img\b[^>]*\ssrc=")(\/[^"]+)"/g, (_match, before, src) => `${before}${rewriteHref(src, prefix)}"`);
|
|
196
|
+
}
|
|
100
197
|
/**
|
|
101
198
|
* Build a `wrangler.jsonc` for Cloudflare Workers Static Assets.
|
|
102
199
|
*
|
|
@@ -147,6 +244,125 @@ function buildWranglerConfig(siteName, options) {
|
|
|
147
244
|
lines.push(`}`);
|
|
148
245
|
return lines.join("\n") + "\n";
|
|
149
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* Build the GitHub Actions workflow YAML for `actions/deploy-pages`.
|
|
249
|
+
*
|
|
250
|
+
* The workflow:
|
|
251
|
+
* 1. Checks out the repo on every push to the default branch.
|
|
252
|
+
* 2. Installs node + pnpm at the Astro project directory, runs
|
|
253
|
+
* `dogsbay site build` (via `pnpm dlx` since Dogsbay is a
|
|
254
|
+
* global CLI, not a project dep), then `pnpm run build`
|
|
255
|
+
* (which runs `astro build && pagefind`).
|
|
256
|
+
* 3. Uploads `<astroDirRel>/dist` as a Pages artifact via
|
|
257
|
+
* `actions/upload-pages-artifact`.
|
|
258
|
+
* 4. Deploys via `actions/deploy-pages`.
|
|
259
|
+
*
|
|
260
|
+
* `astroDirRel` is the path of the Astro output relative to the
|
|
261
|
+
* repo root (typically "astro" — the default config has
|
|
262
|
+
* `output: ./astro`). Empty string is allowed when the project is
|
|
263
|
+
* flat (outputDir === projectDir); the workflow degrades naturally
|
|
264
|
+
* by omitting the `defaults: working-directory` block.
|
|
265
|
+
*
|
|
266
|
+
* Author edits — extra build steps, secrets, deploy gating — survive
|
|
267
|
+
* subsequent `dogsbay site build` runs because the file is written
|
|
268
|
+
* write-if-missing (see emitDeployArtifacts). To start over, delete
|
|
269
|
+
* the workflow file and rebuild.
|
|
270
|
+
*
|
|
271
|
+
* Note on basePath: GitHub Pages serves project sites at
|
|
272
|
+
* `https://<user>.github.io/<repo>/`. Authors who want their docs at
|
|
273
|
+
* the repo root should set `site.basePath: /<repo-name>` (or empty
|
|
274
|
+
* for user/org pages). The platform's basePath plumbing handles all
|
|
275
|
+
* URL rewriting; this workflow doesn't need to know about it.
|
|
276
|
+
*/
|
|
277
|
+
function buildGitHubPagesWorkflow(astroDirRel) {
|
|
278
|
+
// When the Astro output IS the project root, drop the working-
|
|
279
|
+
// directory block and reference cache + artifact paths without a
|
|
280
|
+
// prefix. This is the flat-layout case (rare for site-init flows;
|
|
281
|
+
// common for `dogsbay convert` outputs that get manually wired up).
|
|
282
|
+
const isFlat = astroDirRel === "" || astroDirRel === ".";
|
|
283
|
+
const workingDirBlock = isFlat
|
|
284
|
+
? ""
|
|
285
|
+
: `
|
|
286
|
+
defaults:
|
|
287
|
+
run:
|
|
288
|
+
working-directory: ${astroDirRel}`;
|
|
289
|
+
const cacheDep = isFlat
|
|
290
|
+
? "pnpm-lock.yaml"
|
|
291
|
+
: `${astroDirRel}/pnpm-lock.yaml`;
|
|
292
|
+
const artifactPath = isFlat ? "dist" : `${astroDirRel}/dist`;
|
|
293
|
+
return `# Deploy to GitHub Pages.
|
|
294
|
+
# Generated by \`dogsbay site init --deploy=github-pages\` (or by
|
|
295
|
+
# adding \`deploy: { target: github-pages }\` to dogsbay.config.yml
|
|
296
|
+
# and running \`dogsbay site build\`). Author edits survive every
|
|
297
|
+
# subsequent build — the file is never overwritten. To regenerate
|
|
298
|
+
# from template, delete the file and rebuild.
|
|
299
|
+
#
|
|
300
|
+
# Repo settings: Settings → Pages → Source = "GitHub Actions".
|
|
301
|
+
name: Deploy to GitHub Pages
|
|
302
|
+
|
|
303
|
+
on:
|
|
304
|
+
push:
|
|
305
|
+
branches: [main]
|
|
306
|
+
workflow_dispatch:
|
|
307
|
+
|
|
308
|
+
permissions:
|
|
309
|
+
contents: read
|
|
310
|
+
pages: write
|
|
311
|
+
id-token: write
|
|
312
|
+
|
|
313
|
+
# Allow only one concurrent deployment, skipping queued runs.
|
|
314
|
+
concurrency:
|
|
315
|
+
group: pages
|
|
316
|
+
cancel-in-progress: false
|
|
317
|
+
|
|
318
|
+
jobs:
|
|
319
|
+
build:
|
|
320
|
+
runs-on: ubuntu-latest${workingDirBlock}
|
|
321
|
+
steps:
|
|
322
|
+
- uses: actions/checkout@v4
|
|
323
|
+
|
|
324
|
+
- uses: pnpm/action-setup@v4
|
|
325
|
+
with:
|
|
326
|
+
version: 10
|
|
327
|
+
|
|
328
|
+
- uses: actions/setup-node@v4
|
|
329
|
+
with:
|
|
330
|
+
# Astro 6 requires Node ^20.19.5 || >=22.12.0; pin 22 for
|
|
331
|
+
# forward-compat (Node 20 LTS is fine for Astro 5 sites
|
|
332
|
+
# but the Dogsbay scaffold targets Astro 6).
|
|
333
|
+
node-version: 22
|
|
334
|
+
cache: pnpm
|
|
335
|
+
cache-dependency-path: ${cacheDep}
|
|
336
|
+
|
|
337
|
+
- name: Install dependencies
|
|
338
|
+
run: pnpm install --frozen-lockfile
|
|
339
|
+
|
|
340
|
+
# \`dogsbay\` is a global CLI, not a project dep — pnpm dlx
|
|
341
|
+
# fetches it on demand. To pin a version, replace with e.g.
|
|
342
|
+
# \`pnpm dlx dogsbay@0.2.0-beta.18 site build\`.
|
|
343
|
+
- name: Build with Dogsbay
|
|
344
|
+
run: pnpm dlx dogsbay@beta site build
|
|
345
|
+
|
|
346
|
+
- name: Build Astro site
|
|
347
|
+
run: pnpm run build
|
|
348
|
+
|
|
349
|
+
- name: Upload Pages artifact
|
|
350
|
+
uses: actions/upload-pages-artifact@v3
|
|
351
|
+
with:
|
|
352
|
+
path: ${artifactPath}
|
|
353
|
+
|
|
354
|
+
deploy:
|
|
355
|
+
needs: build
|
|
356
|
+
runs-on: ubuntu-latest
|
|
357
|
+
environment:
|
|
358
|
+
name: github-pages
|
|
359
|
+
url: \${{ steps.deployment.outputs.page_url }}
|
|
360
|
+
steps:
|
|
361
|
+
- name: Deploy to GitHub Pages
|
|
362
|
+
id: deployment
|
|
363
|
+
uses: actions/deploy-pages@v4
|
|
364
|
+
`;
|
|
365
|
+
}
|
|
150
366
|
/**
|
|
151
367
|
* Construct the SiteConfig object that gets serialized to
|
|
152
368
|
* `src/data/site.json`. Backward-compatible: existing fields keep their
|
|
@@ -156,8 +372,6 @@ function buildSiteConfig(siteName, options) {
|
|
|
156
372
|
const cfg = {
|
|
157
373
|
siteName,
|
|
158
374
|
repoUrl: options.repoUrl || "",
|
|
159
|
-
editUri: options.editUri || "blob/main/docs/",
|
|
160
|
-
copyright: options.copyright || "",
|
|
161
375
|
};
|
|
162
376
|
if (options.siteUrl)
|
|
163
377
|
cfg.siteUrl = options.siteUrl;
|
|
@@ -169,6 +383,15 @@ function buildSiteConfig(siteName, options) {
|
|
|
169
383
|
cfg.twitterHandle = options.twitterHandle;
|
|
170
384
|
if (options.themeColor)
|
|
171
385
|
cfg.themeColor = options.themeColor;
|
|
386
|
+
// editUri + copyright follow the same omit-on-empty pattern as the
|
|
387
|
+
// optional fields above; previously they were always written
|
|
388
|
+
// (editUri defaulted to "blob/main/docs/", copyright to ""), which
|
|
389
|
+
// left zombie config in src/data/site.json. Downstream guards already
|
|
390
|
+
// treat empty / undefined as "don't render" so this is purely a tidy.
|
|
391
|
+
if (options.editUri)
|
|
392
|
+
cfg.editUri = options.editUri;
|
|
393
|
+
if (options.copyright)
|
|
394
|
+
cfg.copyright = options.copyright;
|
|
172
395
|
if (options.brandKeywords && options.brandKeywords.length > 0) {
|
|
173
396
|
cfg.brandKeywords = options.brandKeywords;
|
|
174
397
|
}
|
|
@@ -187,11 +410,58 @@ function buildSiteConfig(siteName, options) {
|
|
|
187
410
|
}
|
|
188
411
|
if (options.taxonomyIndexPaths &&
|
|
189
412
|
Object.keys(options.taxonomyIndexPaths).length > 0) {
|
|
190
|
-
|
|
413
|
+
// Bake basePath into every emitted indexPath so consumers
|
|
414
|
+
// (TypeBadge / StatusBadge / future components) compose hrefs
|
|
415
|
+
// like `${indexPath}/<value>/` and resolve under the configured
|
|
416
|
+
// site base. Without the prefix, `/by-type/tutorial/` 404s on
|
|
417
|
+
// any site with `site.basePath` set. Caller passes raw config
|
|
418
|
+
// values (`/by-type`, `/tags`, etc.) — basePath threading is
|
|
419
|
+
// this emitter's responsibility, matching how `page.url` is
|
|
420
|
+
// already prefixed in the taxonomy data file.
|
|
421
|
+
// Taxonomy index paths are baked into site.json so components
|
|
422
|
+
// (TagList, TaxonomyIndex, TypeBadge) emit correct hrefs at
|
|
423
|
+
// runtime. Use combined so these resolve under the host's
|
|
424
|
+
// served subpath.
|
|
425
|
+
const taxoPrefix = combinedPrefix(options);
|
|
426
|
+
cfg.taxonomyIndexPaths = Object.fromEntries(Object.entries(options.taxonomyIndexPaths).map(([name, raw]) => [
|
|
427
|
+
name,
|
|
428
|
+
withBasePath(taxoPrefix, raw),
|
|
429
|
+
]));
|
|
191
430
|
}
|
|
192
431
|
if (options.taxonomyDisplay &&
|
|
193
432
|
Object.keys(options.taxonomyDisplay).length > 0) {
|
|
194
|
-
|
|
433
|
+
// Flatten prefix labels into top-level entries so the
|
|
434
|
+
// search-facets resolver finds them after DocsLayout splits
|
|
435
|
+
// slash-nested tags into per-prefix Pagefind filter divs.
|
|
436
|
+
//
|
|
437
|
+
// Input:
|
|
438
|
+
// tags.prefixes = { difficulty: { label, color }, ... }
|
|
439
|
+
// tags.labels = { "difficulty/1": "Beginner", "difficulty/2": ... }
|
|
440
|
+
// Output additions (kept alongside the original `tags` entry):
|
|
441
|
+
// difficulty.labels = { "1": "Beginner", "2": ... }
|
|
442
|
+
//
|
|
443
|
+
// Resolver does `display[facetName].labels[value]` — facet name
|
|
444
|
+
// is now `difficulty`, value is `1`, → "Beginner". See
|
|
445
|
+
// plans/per-prefix-search-facets.md.
|
|
446
|
+
const flat = { ...options.taxonomyDisplay };
|
|
447
|
+
const tagsDisplay = options.taxonomyDisplay.tags;
|
|
448
|
+
if (tagsDisplay?.prefixes) {
|
|
449
|
+
for (const prefix of Object.keys(tagsDisplay.prefixes)) {
|
|
450
|
+
if (flat[prefix])
|
|
451
|
+
continue; // top-level entry wins
|
|
452
|
+
const leafLabels = {};
|
|
453
|
+
if (tagsDisplay.labels) {
|
|
454
|
+
const needle = `${prefix}/`;
|
|
455
|
+
for (const [slug, label] of Object.entries(tagsDisplay.labels)) {
|
|
456
|
+
if (slug.startsWith(needle)) {
|
|
457
|
+
leafLabels[slug.slice(needle.length)] = label;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
flat[prefix] = { labels: leafLabels };
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
cfg.taxonomyDisplay = flat;
|
|
195
465
|
}
|
|
196
466
|
return cfg;
|
|
197
467
|
}
|
|
@@ -257,6 +527,74 @@ function ensureDirectoryStructure(outputDir, basePath) {
|
|
|
257
527
|
export function emitSiteConfig(outputDir, siteName, options) {
|
|
258
528
|
mkdirSync(join(outputDir, "src", "data"), { recursive: true });
|
|
259
529
|
writeFileSync(join(outputDir, "src", "data", "site.json"), JSON.stringify(buildSiteConfig(siteName, options), null, 2));
|
|
530
|
+
// Auto-generated companion to astro.config.mjs. Carries the
|
|
531
|
+
// site/base values derived from dogsbay.config.yml's site.url so
|
|
532
|
+
// changes propagate without --force-rescaffolding the main
|
|
533
|
+
// astro.config.mjs (which is scaffold-once and may have author
|
|
534
|
+
// edits — custom integrations, build hooks, etc.). The main
|
|
535
|
+
// config imports `dogsbaySite` + `dogsbayBase` from here.
|
|
536
|
+
// See plans/astro-base-from-site-url.md.
|
|
537
|
+
const { origin, urlBase: astroBase } = parseSiteUrl(options.siteUrl);
|
|
538
|
+
const hasSiteUrl = Boolean(options.siteUrl && /^https?:\/\//.test(options.siteUrl));
|
|
539
|
+
const dogsbaySiteJson = hasSiteUrl
|
|
540
|
+
? JSON.stringify(origin ?? options.siteUrl)
|
|
541
|
+
: "undefined";
|
|
542
|
+
const dogsbayBaseJson = astroBase ? JSON.stringify(astroBase) : "undefined";
|
|
543
|
+
// build.inlineStylesheets — defaults to "auto" (Astro's own
|
|
544
|
+
// default; matches our docs-first bias since theme.css is ~120KB
|
|
545
|
+
// and externalizing it lets the file cache cross-page). Authors
|
|
546
|
+
// wanting "always" / "never" set it via dogsbay.config.yml's
|
|
547
|
+
// build.inlineStylesheets. See docs/perf-tuning.md.
|
|
548
|
+
const dogsbayInline = options.inlineStylesheets ?? "auto";
|
|
549
|
+
writeFileSync(join(outputDir, "astro.config.dogsbay.mjs"), [
|
|
550
|
+
"// Auto-generated by `dogsbay site build` — DO NOT EDIT.",
|
|
551
|
+
"// Tracks site.url + derived Astro base + build behaviour from",
|
|
552
|
+
"// dogsbay.config.yml. Edit dogsbay.config.yml and rebuild;",
|
|
553
|
+
"// edits to this file will be overwritten on the next build.",
|
|
554
|
+
`export const dogsbaySite = ${dogsbaySiteJson};`,
|
|
555
|
+
`export const dogsbayBase = ${dogsbayBaseJson};`,
|
|
556
|
+
`export const dogsbayInlineStylesheets = ${JSON.stringify(dogsbayInline)};`,
|
|
557
|
+
"",
|
|
558
|
+
].join("\n"));
|
|
559
|
+
// Migration check: pre-beta.20 sites have an astro.config.mjs that
|
|
560
|
+
// doesn't import the companion. Without the import, the values
|
|
561
|
+
// emitted above are unused and Astro's `base` stays unset — the
|
|
562
|
+
// exact bug this work was meant to close. Warn loudly, with the
|
|
563
|
+
// patch the user needs to apply, until astro.config.mjs is
|
|
564
|
+
// updated. We don't auto-patch because the file may have author
|
|
565
|
+
// edits (custom integrations, build hooks).
|
|
566
|
+
const astroConfigPath = join(outputDir, "astro.config.mjs");
|
|
567
|
+
if (existsSync(astroConfigPath)) {
|
|
568
|
+
const astroConfigSrc = readFileSync(astroConfigPath, "utf-8");
|
|
569
|
+
if (!astroConfigSrc.includes("astro.config.dogsbay.mjs")) {
|
|
570
|
+
console.warn([
|
|
571
|
+
"",
|
|
572
|
+
" ⚠ astro.config.mjs is missing the dogsbay companion import.",
|
|
573
|
+
" Without it, Astro's `base` config stays unset and assets",
|
|
574
|
+
" served from a host subpath (GH Pages project pages,",
|
|
575
|
+
" multi-mount Cloudflare) will 404.",
|
|
576
|
+
"",
|
|
577
|
+
" Add these two lines to astro.config.mjs:",
|
|
578
|
+
"",
|
|
579
|
+
' import {',
|
|
580
|
+
' dogsbaySite,',
|
|
581
|
+
' dogsbayBase,',
|
|
582
|
+
' dogsbayInlineStylesheets,',
|
|
583
|
+
' } from "./astro.config.dogsbay.mjs";',
|
|
584
|
+
"",
|
|
585
|
+
" export default defineConfig({",
|
|
586
|
+
" ...(dogsbaySite ? { site: dogsbaySite } : {}),",
|
|
587
|
+
" ...(dogsbayBase ? { base: dogsbayBase } : {}),",
|
|
588
|
+
" build: { inlineStylesheets: dogsbayInlineStylesheets },",
|
|
589
|
+
" // ...your existing config...",
|
|
590
|
+
" });",
|
|
591
|
+
"",
|
|
592
|
+
" OR regenerate from template (overwrites your edits):",
|
|
593
|
+
" dogsbay site init . --scaffold-only --force",
|
|
594
|
+
"",
|
|
595
|
+
].join("\n"));
|
|
596
|
+
}
|
|
597
|
+
}
|
|
260
598
|
}
|
|
261
599
|
export function emitSiteScaffold(outputDir, siteName, options, writeScaffold) {
|
|
262
600
|
let scaffoldFilesSkipped = 0;
|
|
@@ -300,6 +638,7 @@ export function emitSiteScaffold(outputDir, siteName, options, writeScaffold) {
|
|
|
300
638
|
};
|
|
301
639
|
// Per-deploy-target additions to package.json
|
|
302
640
|
const isCloudflare = options.deploy === "cloudflare-workers";
|
|
641
|
+
const isGitHubPages = options.deploy === "github-pages";
|
|
303
642
|
const deployScripts = isCloudflare
|
|
304
643
|
? { deploy: "pnpm build && wrangler deploy" }
|
|
305
644
|
: {};
|
|
@@ -325,14 +664,25 @@ export function emitSiteScaffold(outputDir, siteName, options, writeScaffold) {
|
|
|
325
664
|
},
|
|
326
665
|
dependencies: {
|
|
327
666
|
astro: "^6.0.0",
|
|
328
|
-
|
|
667
|
+
// Sitemap is emitted directly by Dogsbay into
|
|
668
|
+
// public/<basePath>/sitemap-{index,0}.xml so multi-mount
|
|
669
|
+
// deploys don't collide at the host root. We deliberately
|
|
670
|
+
// do NOT depend on @astrojs/sitemap (it hardcodes output to
|
|
671
|
+
// dist/ root, which is what we're moving away from).
|
|
329
672
|
// Pagefind is invoked from the build script (see scripts.build above).
|
|
330
673
|
// Lives in dependencies (not devDependencies) so production builds
|
|
331
674
|
// include it; the produced search index is shipped statically and
|
|
332
675
|
// doesn't load this dep at runtime.
|
|
333
676
|
pagefind: "^1.4.0",
|
|
334
677
|
tailwindcss: "^4.0.0",
|
|
335
|
-
|
|
678
|
+
// Pinned to 4.2.x — `@tailwindcss/vite` 4.3.x ships an
|
|
679
|
+
// oxcResolvePlugin shape that breaks Astro 6's
|
|
680
|
+
// rolldown-vite ("Missing field tsconfigPaths in
|
|
681
|
+
// oxcResolvePlugin"). Surfaced during the FastAPI import
|
|
682
|
+
// (~150-page MkDocs site) on a fresh `dogsbay site init`.
|
|
683
|
+
// Drop the ~ when Astro 6 picks up a compatible rolldown
|
|
684
|
+
// build OR @tailwindcss/vite restores the prior shape.
|
|
685
|
+
"@tailwindcss/vite": "~4.2.2",
|
|
336
686
|
"tailwind-variants": "^0.3.0",
|
|
337
687
|
shiki: "^4.0.0",
|
|
338
688
|
"@shikijs/transformers": "^4.0.0",
|
|
@@ -348,6 +698,15 @@ export function emitSiteScaffold(outputDir, siteName, options, writeScaffold) {
|
|
|
348
698
|
"@dogsbay/primitives": dogsbayDep("primitives"),
|
|
349
699
|
"@dogsbay/icons": dogsbayDep("icons"),
|
|
350
700
|
"@dogsbay/elements": dogsbayDep("elements"),
|
|
701
|
+
// Transitive of `@dogsbay/primitives` (via
|
|
702
|
+
// `@floating-ui/dom`). Listed at the top level because
|
|
703
|
+
// npm doesn't hoist the second-level transitive when
|
|
704
|
+
// `@dogsbay/primitives` is linked via `file:` (the
|
|
705
|
+
// `--local` monorepo mode + the canary publish flow on
|
|
706
|
+
// GH Pages CI both hit this). Surfaced during the
|
|
707
|
+
// FastAPI import: Rollup failed with "Cannot resolve
|
|
708
|
+
// @floating-ui/core" at astro build time.
|
|
709
|
+
"@floating-ui/core": "^1.7.0",
|
|
351
710
|
},
|
|
352
711
|
// Pin transitive Vite to 7. Vite 8 just released; Astro 6
|
|
353
712
|
// peer-deps Vite 7 and prints a warning when 8 is hoisted.
|
|
@@ -374,6 +733,18 @@ export function emitSiteScaffold(outputDir, siteName, options, writeScaffold) {
|
|
|
374
733
|
scaffoldFilesSkipped++;
|
|
375
734
|
}
|
|
376
735
|
}
|
|
736
|
+
// GitHub Pages deploy artifacts — workflow + .nojekyll. The actual
|
|
737
|
+
// emission lives in `emitDeployArtifacts` so site-build can also
|
|
738
|
+
// call it on existing sites without going through scaffold (a user
|
|
739
|
+
// adds `deploy: github-pages` to dogsbay.config.yml and reruns
|
|
740
|
+
// `site build` to get the workflow). At scaffold-time we pass
|
|
741
|
+
// forceOverwrite=writeScaffold so `--force` regenerates from
|
|
742
|
+
// template; on regular builds it stays write-if-missing.
|
|
743
|
+
if (isGitHubPages) {
|
|
744
|
+
emitDeployArtifacts(outputDir, options, {
|
|
745
|
+
forceOverwrite: writeScaffold,
|
|
746
|
+
});
|
|
747
|
+
}
|
|
377
748
|
// Generate astro.config.mjs
|
|
378
749
|
// `preserveSymlinks: true` is used with --local to pin local file: deps to
|
|
379
750
|
// their on-disk paths. Inside a pnpm workspace this breaks Astro's internal
|
|
@@ -385,52 +756,50 @@ export function emitSiteScaffold(outputDir, siteName, options, writeScaffold) {
|
|
|
385
756
|
preserveSymlinks: true,
|
|
386
757
|
},`
|
|
387
758
|
: "";
|
|
388
|
-
//
|
|
389
|
-
//
|
|
390
|
-
//
|
|
391
|
-
// the generated config). Sitemap also filters out frontmatter-noindex pages.
|
|
392
|
-
const hasSiteUrl = Boolean(options.siteUrl && /^https?:\/\//.test(options.siteUrl));
|
|
393
|
-
const sitemapImport = hasSiteUrl ? `import sitemap from "@astrojs/sitemap";\n` : "";
|
|
394
|
-
// Strip any path component from site.url before emitting. The
|
|
395
|
-
// config validator already rejects `site.url` containing a path
|
|
396
|
-
// when `basePath` is non-empty (canonical URLs would double-count
|
|
397
|
-
// the prefix); this is a defensive normalisation for the case
|
|
398
|
-
// where the validator is bypassed or basePath is empty.
|
|
759
|
+
// siteUrl gates absolute-URL emission (sitemap <loc> entries,
|
|
760
|
+
// canonical tags). Without one, both are skipped — relative URLs
|
|
761
|
+
// are still correct, the sitemap is just not generated.
|
|
399
762
|
//
|
|
400
|
-
//
|
|
401
|
-
//
|
|
402
|
-
//
|
|
403
|
-
// to
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
//
|
|
419
|
-
//
|
|
420
|
-
//
|
|
421
|
-
//
|
|
422
|
-
//
|
|
423
|
-
// spread is a no-op. See plans/plugin-api.md.
|
|
763
|
+
// Sitemap is emitted directly by Dogsbay (see emitSitemapFiles)
|
|
764
|
+
// into public/<basePath>/sitemap-*.xml. We deliberately do NOT
|
|
765
|
+
// wire @astrojs/sitemap here; that integration hardcodes output
|
|
766
|
+
// to dist/ root, breaking multi-mount deploys.
|
|
767
|
+
const hasSiteUrl = Boolean(options.siteUrl && /^https?:\/\//.test(options.siteUrl));
|
|
768
|
+
// site.url's path component (if any) becomes Astro's `base`. The
|
|
769
|
+
// origin alone goes into `site`. This split lets dogsbay model
|
|
770
|
+
// both axes independently:
|
|
771
|
+
// - Astro's `base` (= urlBase) controls the URL prefix Astro
|
|
772
|
+
// bakes into HTML asset references (`<basePath>/_astro/...`)
|
|
773
|
+
// and the routes Astro generates from src/pages.
|
|
774
|
+
// - dogsbay's basePath controls the filesystem layout
|
|
775
|
+
// (`src/pages/<basePath>/...`).
|
|
776
|
+
// The two compose at emit time — combining for nav hrefs,
|
|
777
|
+
// sitemap, llms.txt, etc. See plans/astro-base-from-site-url.md.
|
|
778
|
+
const { origin, urlBase: astroBase } = parseSiteUrl(options.siteUrl);
|
|
779
|
+
// astro.config.mjs — scaffold-once, but the site/base values flow
|
|
780
|
+
// through a separate auto-generated file (`astro.config.dogsbay.mjs`,
|
|
781
|
+
// emitted unconditionally below) so dogsbay-derived values stay in
|
|
782
|
+
// sync with `dogsbay.config.yml` even on existing sites where the
|
|
783
|
+
// main config is preserved. Same pattern as
|
|
784
|
+
// `astro.config.plugins.mjs` — the import line is the load-bearing
|
|
785
|
+
// bit; the auto-file is what changes.
|
|
424
786
|
if (writeScaffold) {
|
|
425
787
|
writeFileSync(join(outputDir, "astro.config.mjs"), `import { defineConfig } from "astro/config";
|
|
426
788
|
import tailwindcss from "@tailwindcss/vite";
|
|
427
|
-
|
|
789
|
+
import { pluginAliases, pluginFsAllow } from "./astro.config.plugins.mjs";
|
|
790
|
+
import {
|
|
791
|
+
dogsbaySite,
|
|
792
|
+
dogsbayBase,
|
|
793
|
+
dogsbayInlineStylesheets,
|
|
794
|
+
} from "./astro.config.dogsbay.mjs";
|
|
428
795
|
|
|
429
|
-
export default defineConfig({
|
|
796
|
+
export default defineConfig({
|
|
797
|
+
...(dogsbaySite ? { site: dogsbaySite } : {}),
|
|
798
|
+
...(dogsbayBase ? { base: dogsbayBase } : {}),
|
|
430
799
|
output: "static",
|
|
431
800
|
build: {
|
|
432
|
-
inlineStylesheets:
|
|
433
|
-
}
|
|
801
|
+
inlineStylesheets: dogsbayInlineStylesheets,
|
|
802
|
+
},
|
|
434
803
|
vite: {
|
|
435
804
|
plugins: [tailwindcss()],
|
|
436
805
|
resolve: {
|
|
@@ -452,6 +821,9 @@ export default defineConfig({${siteField}
|
|
|
452
821
|
else {
|
|
453
822
|
scaffoldFilesSkipped++;
|
|
454
823
|
}
|
|
824
|
+
// astro.config.dogsbay.mjs is emitted by emitSiteConfig (called
|
|
825
|
+
// above and on every site build) so site/base values stay in
|
|
826
|
+
// sync without a re-scaffold. See its definition for rationale.
|
|
455
827
|
// Always seed an empty astro.config.plugins.mjs so the import in
|
|
456
828
|
// astro.config.mjs resolves before the first plugin-emitting
|
|
457
829
|
// build. Subsequent builds replace it via emitPluginRuntime.
|
|
@@ -522,7 +894,12 @@ export default defineConfig({${siteField}
|
|
|
522
894
|
*/
|
|
523
895
|
export async function emitAstroPages(pages, nav, outputDir, options) {
|
|
524
896
|
const siteName = options.siteName || "Documentation";
|
|
897
|
+
// basePath = filesystem layout prefix (where pages live under
|
|
898
|
+
// src/pages/...). combined = the URL prefix HTML hrefs need
|
|
899
|
+
// (urlBase + basePath). The two diverge whenever site.url has a
|
|
900
|
+
// path component (GH Pages project pages, multi-mount Cloudflare).
|
|
525
901
|
const basePath = normalizeBasePath(options.basePath);
|
|
902
|
+
const combined = combinedPrefix(options);
|
|
526
903
|
const baseSegments = basePathSegments(basePath);
|
|
527
904
|
// Ensure dirs exist (callers may invoke us without going through the
|
|
528
905
|
// full exportAstroProject orchestrator, e.g. dogsbay convert at Step 7).
|
|
@@ -543,13 +920,36 @@ export async function emitAstroPages(pages, nav, outputDir, options) {
|
|
|
543
920
|
// Remove existing entry for this section (full replace)
|
|
544
921
|
existingNav = existingNav.filter((item) => item.label?.toLowerCase() !== siteName.toLowerCase()
|
|
545
922
|
&& item.label?.toLowerCase() !== section.toLowerCase());
|
|
546
|
-
|
|
923
|
+
// Nav hrefs already carry the `combined` prefix (the importer
|
|
924
|
+
// emits them via fileToHref(file, hrefPrefix=combined)).
|
|
925
|
+
// prefixNavHrefs takes the existing prefix and weaves a section
|
|
926
|
+
// segment into it.
|
|
927
|
+
const prefixedNav = prefixNavHrefs(nav, section, combined);
|
|
547
928
|
const sectionLabel = siteName
|
|
548
929
|
|| section.split("-").map(w => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
549
930
|
existingNav.push({ label: sectionLabel, children: prefixedNav });
|
|
550
931
|
outputNav = existingNav;
|
|
551
932
|
}
|
|
933
|
+
// Safety net: ensure every nav href carries the combined URL base,
|
|
934
|
+
// regardless of which importer produced the nav. Idempotent — a nav
|
|
935
|
+
// already prefixed at import time (dogsbay-md walking source paths) is
|
|
936
|
+
// left untouched; a nav of pre-baked root-absolute hrefs (docusaurus
|
|
937
|
+
// convert) gets the base it was missing. Keeps nav hrefs aligned with
|
|
938
|
+
// the combined-prefixed `currentPath` so prev/next still matches.
|
|
939
|
+
outputNav = prefixNavBaseHrefs(outputNav, combined);
|
|
552
940
|
writeFileSync(join(outputDir, "src", "data", "nav.json"), JSON.stringify(outputNav, null, 2));
|
|
941
|
+
// Also publish nav.json under public/_dogsbay/ so the
|
|
942
|
+
// client-mode <DocsNavClient /> can fetch it at runtime
|
|
943
|
+
// (Astro copies public/ to dist/ as-is at build). The src/data
|
|
944
|
+
// copy stays for build-time imports (pagination, prev/next
|
|
945
|
+
// calculation in each page) — the public copy is the on-the-wire
|
|
946
|
+
// copy that the browser ever sees. Kept identical (same bytes,
|
|
947
|
+
// same shape); the duplicate is cheap (one file) and keeps the
|
|
948
|
+
// build-time and runtime worlds cleanly separated. See
|
|
949
|
+
// plans/client-rendered-nav.md.
|
|
950
|
+
const publicNavDir = join(outputDir, "public", "_dogsbay");
|
|
951
|
+
mkdirSync(publicNavDir, { recursive: true });
|
|
952
|
+
writeFileSync(join(publicNavDir, "nav.json"), JSON.stringify(outputNav));
|
|
553
953
|
// Static assets (images etc.) — content-tier; always copy from the
|
|
554
954
|
// user's source dir. If they removed an asset, we want it gone here
|
|
555
955
|
// too. Skipped when sourceDir isn't supplied (programmatic callers
|
|
@@ -557,21 +957,93 @@ export async function emitAstroPages(pages, nav, outputDir, options) {
|
|
|
557
957
|
if (options.sourceDir) {
|
|
558
958
|
copyAssets(options.sourceDir, outputDir, options.imageOptimization);
|
|
559
959
|
}
|
|
960
|
+
// External asset mounts (e.g. a Docusaurus `static/` dir) → public/_assets/,
|
|
961
|
+
// preserving internal structure so the importer's `/_assets/...` image refs
|
|
962
|
+
// resolve. Used by the convert --to astro path; the dogsbay-md → site build
|
|
963
|
+
// path instead lands these under content/_assets and copyAssets picks them up.
|
|
964
|
+
if (options.assetMounts) {
|
|
965
|
+
for (const mount of options.assetMounts) {
|
|
966
|
+
if (existsSync(mount.dir)) {
|
|
967
|
+
cpSync(mount.dir, join(outputDir, "public", "_assets"), { recursive: true });
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
}
|
|
560
971
|
let generated = 0;
|
|
972
|
+
// Tracks whether a real root home page (`content/index.md` → slug
|
|
973
|
+
// "index") was emitted. Drives the root-served-site redirect fallback
|
|
974
|
+
// below: a corpus whose nav root is e.g. `welcome/index` (OpenShift)
|
|
975
|
+
// has no `/` page, so without a redirect `/` 404s. See
|
|
976
|
+
// plans/dir-index-slug-nav-drop.md.
|
|
977
|
+
let rootIndexEmitted = false;
|
|
978
|
+
const generatedPaths = new Set();
|
|
561
979
|
const pagesDir = join(outputDir, "src", "pages", ...baseSegments);
|
|
562
980
|
const useImageOpt = options.imageOptimization ?? false;
|
|
563
|
-
// hrefPrefix is the
|
|
564
|
-
//
|
|
565
|
-
//
|
|
566
|
-
//
|
|
567
|
-
|
|
981
|
+
// hrefPrefix is the COMBINED prefix (urlBase + basePath) — what
|
|
982
|
+
// rendered HTML hrefs need so internal links resolve under the
|
|
983
|
+
// host's served subpath AND under the dogsbay basePath. For
|
|
984
|
+
// simple host-apex deploys with basePath, urlBase is empty so
|
|
985
|
+
// combined === basePath (back-compat). For GH Pages project pages
|
|
986
|
+
// and multi-mount Cloudflare, combined adds the urlBase layer.
|
|
987
|
+
const hrefPrefix = combined;
|
|
988
|
+
// Route-exclusion gate. Two signals, either is enough:
|
|
989
|
+
// - frontmatter `_fragment: true` (loader-stamped — the importer
|
|
990
|
+
// knew this .md was include-only, not a navigable page)
|
|
991
|
+
// - excludeFromRoutes match against the slug (project-declared,
|
|
992
|
+
// in dogsbay.config.yml — for content under conventional
|
|
993
|
+
// fragment dirs like `modules/`, `_attributes/`, `snippets/`)
|
|
994
|
+
// Excluded pages stay on disk under content/ (so includes resolve)
|
|
995
|
+
// but don't produce .astro / .md.ts routes. See plans/build-at-scale.md.
|
|
996
|
+
//
|
|
997
|
+
// Match semantics:
|
|
998
|
+
// - A single-segment pattern (no `/`) matches ANY occurrence of
|
|
999
|
+
// that segment in the slug path. So `modules` excludes both
|
|
1000
|
+
// `modules/foo` AND `welcome/modules/foo` AND
|
|
1001
|
+
// `drupal-build/openshift-enterprise/ai/includes/x`. This is
|
|
1002
|
+
// what AsciiBinder corpora want — fragment dirs symlink into
|
|
1003
|
+
// section dirs so the same `includes/` etc. appears at many
|
|
1004
|
+
// depths.
|
|
1005
|
+
// - A multi-segment pattern (contains `/`) matches as a leading
|
|
1006
|
+
// prefix (exact path-prefix). `welcome/_internal` excludes
|
|
1007
|
+
// only that specific path tree, not arbitrary `_internal/`
|
|
1008
|
+
// elsewhere.
|
|
1009
|
+
const excludePatterns = (options.excludeFromRoutes ?? []).map((p) => p.replace(/^\/+/, "").replace(/\/+$/, ""));
|
|
1010
|
+
function isExcludedSlug(slug) {
|
|
1011
|
+
if (excludePatterns.length === 0)
|
|
1012
|
+
return false;
|
|
1013
|
+
const segments = slug.split("/");
|
|
1014
|
+
for (const pattern of excludePatterns) {
|
|
1015
|
+
if (pattern.includes("/")) {
|
|
1016
|
+
// Multi-segment → leading-prefix match.
|
|
1017
|
+
if (slug === pattern || slug.startsWith(pattern + "/"))
|
|
1018
|
+
return true;
|
|
1019
|
+
}
|
|
1020
|
+
else {
|
|
1021
|
+
// Single-segment → any-segment match.
|
|
1022
|
+
if (segments.includes(pattern))
|
|
1023
|
+
return true;
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
return false;
|
|
1027
|
+
}
|
|
568
1028
|
for (const page of pages) {
|
|
569
1029
|
try {
|
|
1030
|
+
// Skip excluded pages before any expensive work (tree rewrite,
|
|
1031
|
+
// serialize, IO).
|
|
1032
|
+
const isFragment = page.frontmatter && page.frontmatter._fragment === true;
|
|
1033
|
+
if (isFragment || isExcludedSlug(page.slug)) {
|
|
1034
|
+
continue;
|
|
1035
|
+
}
|
|
570
1036
|
// Rewrite internal hrefs to match the output URL structure
|
|
571
1037
|
rewriteTreeHrefs(page.tree, hrefPrefix);
|
|
1038
|
+
// Same for raw image srcs — Astro doesn't auto-prefix
|
|
1039
|
+
// `<img src="/_assets/...">` so we do it here. Block images
|
|
1040
|
+
// strip the prefix back off for the `imageMap[...]` lookup
|
|
1041
|
+
// (see paragraphToAstro in serialize.ts).
|
|
1042
|
+
rewriteTreeImageSrcs(page.tree, hrefPrefix);
|
|
572
1043
|
const result = treeToAstro(page.tree, {
|
|
573
1044
|
imageOptimization: useImageOpt,
|
|
574
1045
|
codeBlockTitle: options.codeBlockTitle ?? true,
|
|
1046
|
+
combinedPrefix: hrefPrefix,
|
|
575
1047
|
});
|
|
576
1048
|
const imageSetup = useImageOpt ? [
|
|
577
1049
|
'',
|
|
@@ -585,11 +1057,32 @@ export async function emitAstroPages(pages, nav, outputDir, options) {
|
|
|
585
1057
|
' imageMap[publicPath] = mod.default;',
|
|
586
1058
|
'}',
|
|
587
1059
|
] : [];
|
|
588
|
-
// Per-page meta from frontmatter
|
|
1060
|
+
// Per-page meta from frontmatter. When no description is authored,
|
|
1061
|
+
// derive one from the first prose paragraph so every page emits a
|
|
1062
|
+
// <meta name="description"> (Lighthouse flags pages without one).
|
|
1063
|
+
// See plans/auto-meta-description.md.
|
|
589
1064
|
const fm = (page.frontmatter ?? {});
|
|
590
|
-
|
|
1065
|
+
// A writer-authored frontmatter description is meta-only (not in the body),
|
|
1066
|
+
// so it's safe to also render as a visible lede. A DERIVED description is
|
|
1067
|
+
// pulled FROM the body, so rendering it as a lede always duplicates content
|
|
1068
|
+
// (e.g. a page whose first paragraph sits under "## Big picture"). Keep the
|
|
1069
|
+
// two separate: derive for the <meta> tag, but only lede the authored one.
|
|
1070
|
+
const fmDescription = typeof fm.description === "string" && fm.description.trim().length > 0
|
|
1071
|
+
? fm.description
|
|
1072
|
+
: undefined;
|
|
1073
|
+
const pageDescription = fmDescription || deriveDescription(page.tree) || "";
|
|
591
1074
|
const pageOgImage = fm.ogImage ?? "";
|
|
592
|
-
|
|
1075
|
+
// Noindex / nofollow are independent meta directives. Site-level
|
|
1076
|
+
// forces both bits site-wide (staging / compliance lockdown);
|
|
1077
|
+
// page frontmatter can ESCALATE either bit independently but
|
|
1078
|
+
// cannot opt out of a site-level lockdown. `draft: true` keeps
|
|
1079
|
+
// its existing role as a noindex shorthand. See
|
|
1080
|
+
// plans/site-level-robots-meta.md.
|
|
1081
|
+
const pageNoindex = options.noindex === true ||
|
|
1082
|
+
fm.noindex === true ||
|
|
1083
|
+
fm.draft === true;
|
|
1084
|
+
const pageNofollow = options.nofollow === true ||
|
|
1085
|
+
fm.nofollow === true;
|
|
593
1086
|
// Independent of noindex: pages can be excluded from in-site
|
|
594
1087
|
// Pagefind search even when external SEs should index them
|
|
595
1088
|
// (or vice versa). See DocsLayout's prop docs for the
|
|
@@ -608,7 +1101,28 @@ export async function emitAstroPages(pages, nav, outputDir, options) {
|
|
|
608
1101
|
const pageCategory = Array.isArray(pageMeta?.category)
|
|
609
1102
|
? pageMeta.category
|
|
610
1103
|
: undefined;
|
|
611
|
-
|
|
1104
|
+
// Custom-taxonomy values lifted from frontmatter into
|
|
1105
|
+
// `meta.taxonomies` by the importer (see `parseMeta` in
|
|
1106
|
+
// `@dogsbay/types`). Surfaced to DocsLayout so it can emit one
|
|
1107
|
+
// `<div data-pagefind-filter="<name>:<value>">` per entry — this
|
|
1108
|
+
// is what makes user-declared taxonomies (`difficulty`, `team`,
|
|
1109
|
+
// anything not in the five built-ins) appear as visible facet
|
|
1110
|
+
// checkboxes in the search dialog. Without this passthrough
|
|
1111
|
+
// they're silently dropped after the importer.
|
|
1112
|
+
const pageTaxonomies = pageMeta?.taxonomies && Object.keys(pageMeta.taxonomies).length > 0
|
|
1113
|
+
? pageMeta.taxonomies
|
|
1114
|
+
: undefined;
|
|
1115
|
+
// `tagsIndexPath` flows to `<TagList>` for chip hrefs
|
|
1116
|
+
// (`${indexPath}/${tag}/`). Caller passes the raw config value
|
|
1117
|
+
// (e.g. `/tags`); we bake the COMBINED prefix (urlBase from
|
|
1118
|
+
// site.url's path + basePath) here so chips resolve under both
|
|
1119
|
+
// the host's served subpath AND the dogsbay basePath. With
|
|
1120
|
+
// basePath alone, chips 404 on GH Pages project deploys
|
|
1121
|
+
// (basePath="" + non-empty urlBase) — same shape as the
|
|
1122
|
+
// typeBadgeHref / statusBadgeHref composition in DocsLayout,
|
|
1123
|
+
// which already reads combined-prefixed values out of
|
|
1124
|
+
// siteConfig.taxonomyIndexPaths (baked in buildSiteConfig).
|
|
1125
|
+
const tagsIndexPath = withBasePath(combined, options.tagsIndexPath ?? "/tags");
|
|
612
1126
|
// Auto-lede detection. If the markdown body doesn't already
|
|
613
1127
|
// start with an H1 / leading paragraph, we ask DocsLayout to
|
|
614
1128
|
// render the frontmatter title / description at the top of
|
|
@@ -622,7 +1136,7 @@ export async function emitAstroPages(pages, nav, outputDir, options) {
|
|
|
622
1136
|
page.title.length > 0;
|
|
623
1137
|
const autoLede = !isRedirect &&
|
|
624
1138
|
!bodyHasLede &&
|
|
625
|
-
|
|
1139
|
+
fmDescription !== undefined;
|
|
626
1140
|
// Per-page LLM action UI. Site-wide config in
|
|
627
1141
|
// `options.llmActions`; per-page opt-out via frontmatter
|
|
628
1142
|
// `llmActions: false`. Skipped on redirect pages (no real
|
|
@@ -640,12 +1154,20 @@ export async function emitAstroPages(pages, nav, outputDir, options) {
|
|
|
640
1154
|
// available via other means. The "Open in" deep links work
|
|
641
1155
|
// regardless of mirror availability — agents that can't fetch
|
|
642
1156
|
// the page just see the URL in their chat.
|
|
1157
|
+
// pageHrefBase uses combined (urlBase + basePath) so the URL
|
|
1158
|
+
// resolves correctly when the host serves dist/ at a subpath
|
|
1159
|
+
// (GH Pages project page, multi-mount Cloudflare).
|
|
643
1160
|
const pageHrefBase = section
|
|
644
|
-
? (
|
|
645
|
-
: (
|
|
1161
|
+
? (combined ? `${combined}/${section}/${page.slug}` : `/${section}/${page.slug}`)
|
|
1162
|
+
: (combined ? `${combined}/${page.slug}` : `/${page.slug}`);
|
|
646
1163
|
const pageMdHref = `${pageHrefBase}.md`;
|
|
647
|
-
|
|
648
|
-
|
|
1164
|
+
// For absolute URLs (the "Copy as MD" deep link), use the
|
|
1165
|
+
// origin (no path) + the full combined path; siteUrl alone
|
|
1166
|
+
// would double-include the urlBase since pageHrefBase already
|
|
1167
|
+
// contains it.
|
|
1168
|
+
const { origin } = parseSiteUrl(options.siteUrl);
|
|
1169
|
+
const pageMdAbsoluteUrl = origin
|
|
1170
|
+
? origin + pageMdHref
|
|
649
1171
|
: pageMdHref;
|
|
650
1172
|
// Markdown body for the Copy button. Reuse the same serializer
|
|
651
1173
|
// that produces the .md mirror so what the user copies matches
|
|
@@ -687,7 +1209,10 @@ export async function emitAstroPages(pages, nav, outputDir, options) {
|
|
|
687
1209
|
"",
|
|
688
1210
|
`const headings = ${JSON.stringify(page.headings || [])};`,
|
|
689
1211
|
`const nav = navData;`,
|
|
690
|
-
|
|
1212
|
+
// currentPath uses combined so it matches nav.json hrefs
|
|
1213
|
+
// (which are also combined-prefixed). getPagination compares
|
|
1214
|
+
// them as strings; mismatched prefixes break prev/next.
|
|
1215
|
+
`const currentPath = "${buildCurrentPath(combined, section, page.slug)}";`,
|
|
691
1216
|
// Filter nav to the current (locale, version) bucket
|
|
692
1217
|
// before computing prev/next — without this, pagination
|
|
693
1218
|
// walks the global nav and a "Next" link can leak from
|
|
@@ -705,12 +1230,14 @@ export async function emitAstroPages(pages, nav, outputDir, options) {
|
|
|
705
1230
|
`const description = ${JSON.stringify(pageDescription)} || undefined;`,
|
|
706
1231
|
`const ogImage = ${JSON.stringify(pageOgImage)} || undefined;`,
|
|
707
1232
|
`const noindex = ${JSON.stringify(pageNoindex)};`,
|
|
1233
|
+
`const nofollow = ${JSON.stringify(pageNofollow)};`,
|
|
708
1234
|
`const excludeFromSearch = ${JSON.stringify(pageExcludeFromSearch)};`,
|
|
709
1235
|
`const pageTags = ${JSON.stringify(pageTags ?? null)};`,
|
|
710
1236
|
`const pageStatus = ${JSON.stringify(pageStatus ?? null)};`,
|
|
711
1237
|
`const pageType = ${JSON.stringify(pageTypeStr ?? null)};`,
|
|
712
1238
|
`const pageAudience = ${JSON.stringify(pageAudience ?? null)};`,
|
|
713
1239
|
`const pageCategory = ${JSON.stringify(pageCategory ?? null)};`,
|
|
1240
|
+
`const pageTaxonomies = ${JSON.stringify(pageTaxonomies ?? null)};`,
|
|
714
1241
|
`const tagsIndexPath = ${JSON.stringify(tagsIndexPath)};`,
|
|
715
1242
|
`const llmActionsProps = ${JSON.stringify(llmActionsEnabled
|
|
716
1243
|
? {
|
|
@@ -741,6 +1268,7 @@ export async function emitAstroPages(pages, nav, outputDir, options) {
|
|
|
741
1268
|
` twitterHandle={siteConfig.twitterHandle || undefined}`,
|
|
742
1269
|
` themeColor={siteConfig.themeColor || undefined}`,
|
|
743
1270
|
` noindex={noindex}`,
|
|
1271
|
+
` nofollow={nofollow}`,
|
|
744
1272
|
` excludeFromSearch={excludeFromSearch}`,
|
|
745
1273
|
` plausibleDomain={siteConfig.plausible?.domain}`,
|
|
746
1274
|
` plausibleScriptUrl={siteConfig.plausible?.scriptUrl}`,
|
|
@@ -756,12 +1284,39 @@ export async function emitAstroPages(pages, nav, outputDir, options) {
|
|
|
756
1284
|
` pageType={pageType ?? undefined}`,
|
|
757
1285
|
` audience={pageAudience ?? undefined}`,
|
|
758
1286
|
` category={pageCategory ?? undefined}`,
|
|
1287
|
+
` taxonomies={pageTaxonomies ?? undefined}`,
|
|
759
1288
|
` autoH1={${autoH1}}`,
|
|
760
1289
|
` autoLede={${autoLede}}`,
|
|
761
1290
|
` llmActions={llmActionsProps}`,
|
|
762
1291
|
` multiSource={${JSON.stringify(page.multiSource ?? null)} ?? undefined}`,
|
|
763
1292
|
` switcherMap={switcherMapData}`,
|
|
764
|
-
|
|
1293
|
+
// basePath here is the COMBINED URL prefix (urlBase from
|
|
1294
|
+
// site.url's path + dogsbay basePath). DocsLayout uses it
|
|
1295
|
+
// for switcher links, the footer llms.txt link, and the
|
|
1296
|
+
// <head> alternate link — all three need the full URL
|
|
1297
|
+
// prefix the host actually serves under. Empty string is
|
|
1298
|
+
// valid (root-served sites with no urlBase or basePath);
|
|
1299
|
+
// don't fall back to "/docs" — that would 404 for those.
|
|
1300
|
+
` basePath={${JSON.stringify(combined)}}`,
|
|
1301
|
+
// navMode — controls whether DocsLayout server-renders the
|
|
1302
|
+
// full sidebar nav tree per page (`ssr-full`) or emits a
|
|
1303
|
+
// client-hydrated placeholder (`client`, default). The
|
|
1304
|
+
// client mode shrinks per-page HTML dramatically at scale.
|
|
1305
|
+
// See plans/client-rendered-nav.md.
|
|
1306
|
+
` navMode={${JSON.stringify(options.navMode ?? "client")}}`,
|
|
1307
|
+
// Pagefind index URL — must include the combined prefix or
|
|
1308
|
+
// the loader 404s on subpath-mounted deploys. The pagefind
|
|
1309
|
+
// CLI writes to <astroOutput>/dist/pagefind/ which Astro
|
|
1310
|
+
// serves under its `base` (= urlBase); dogsbay's basePath
|
|
1311
|
+
// adds the second prefix layer. Empty combined → `/pagefind/`.
|
|
1312
|
+
` pagefindUrl={${JSON.stringify(combined ? `${combined}/pagefind/` : "/pagefind/")}}`,
|
|
1313
|
+
// Favicon — composed with combined prefix so the
|
|
1314
|
+
// <link rel="icon"> resolves on subpath-mounted deploys.
|
|
1315
|
+
// Authors who want a different favicon override via the
|
|
1316
|
+
// `favicon` slot on DocsLayout, or drop the file at
|
|
1317
|
+
// `public/favicon.ico` in their Astro project (which is
|
|
1318
|
+
// what the default points at).
|
|
1319
|
+
` favicon={${JSON.stringify(combined ? `${combined}/favicon.ico` : "/favicon.ico")}}`,
|
|
765
1320
|
` wideLayout={${wideLayout}}`,
|
|
766
1321
|
`>`,
|
|
767
1322
|
` <MarkdownContentStack>`,
|
|
@@ -798,6 +1353,9 @@ export async function emitAstroPages(pages, nav, outputDir, options) {
|
|
|
798
1353
|
mkdirSync(dirname(pagePath), { recursive: true });
|
|
799
1354
|
writeFileSync(pagePath, pageLines.join("\n") + "\n");
|
|
800
1355
|
generated++;
|
|
1356
|
+
if (!section && page.slug === "index")
|
|
1357
|
+
rootIndexEmitted = true;
|
|
1358
|
+
generatedPaths.add(relative(outputDir, pagePath));
|
|
801
1359
|
// Companion .md endpoint for content negotiation. Prerendered, so
|
|
802
1360
|
// it's served as a static asset at runtime — no Worker overhead.
|
|
803
1361
|
//
|
|
@@ -833,14 +1391,55 @@ export async function emitAstroPages(pages, nav, outputDir, options) {
|
|
|
833
1391
|
}
|
|
834
1392
|
}
|
|
835
1393
|
// Generate index redirect at src/pages/index.astro — sends `/` to the
|
|
836
|
-
// first nav href.
|
|
837
|
-
//
|
|
838
|
-
//
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
1394
|
+
// first nav href. Two cases need it:
|
|
1395
|
+
// - basePath set: `/` (host apex) isn't a content page, so redirect
|
|
1396
|
+
// into the basePath subtree.
|
|
1397
|
+
// - basePath empty BUT no root home page emitted (no
|
|
1398
|
+
// `content/index.md`): the corpus's entry point is a nested page
|
|
1399
|
+
// (e.g. OpenShift's `welcome/index`), so `/` would 404 without a
|
|
1400
|
+
// redirect. Only emit here for non-section builds and never when a
|
|
1401
|
+
// real root index page exists (writing a redirect would clobber it).
|
|
1402
|
+
const firstHref = findFirstNavHref(nav, basePath);
|
|
1403
|
+
const needsRootRedirect = basePath !== "" ||
|
|
1404
|
+
(!section && !rootIndexEmitted && firstHref !== "");
|
|
1405
|
+
if (needsRootRedirect) {
|
|
1406
|
+
const indexPath = join(outputDir, "src", "pages", "index.astro");
|
|
1407
|
+
writeFileSync(indexPath, `---\nreturn Astro.redirect("${firstHref}");\n---\n`);
|
|
1408
|
+
generatedPaths.add(relative(outputDir, indexPath));
|
|
1409
|
+
}
|
|
1410
|
+
return { generated, outputNav, generatedPaths };
|
|
1411
|
+
}
|
|
1412
|
+
/**
|
|
1413
|
+
* Copy each passthrough `.astro` source to its computed output path.
|
|
1414
|
+
* Aborts with a clear error if the destination is already in
|
|
1415
|
+
* `generatedPaths` (a generated page from `emitAstroPages` would
|
|
1416
|
+
* silently overwrite the hand-authored file otherwise).
|
|
1417
|
+
*/
|
|
1418
|
+
export function emitPassthroughAstroPages(copies, outputDir, generatedPaths) {
|
|
1419
|
+
if (copies.length === 0)
|
|
1420
|
+
return { copied: 0 };
|
|
1421
|
+
// Collision detection — a generated page and a passthrough page
|
|
1422
|
+
// would write to the same file. Refuse to overwrite; tell the
|
|
1423
|
+
// author exactly which two files conflict.
|
|
1424
|
+
const collisions = [];
|
|
1425
|
+
for (const copy of copies) {
|
|
1426
|
+
if (generatedPaths.has(copy.outputRelPath)) {
|
|
1427
|
+
collisions.push(copy.outputRelPath);
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
if (collisions.length > 0) {
|
|
1431
|
+
throw new Error(`Passthrough Astro page collides with a generated page:\n` +
|
|
1432
|
+
collisions.map((c) => ` - ${c}`).join("\n") + "\n" +
|
|
1433
|
+
`Rename the .astro source or remove the colliding entry from nav.yml.`);
|
|
1434
|
+
}
|
|
1435
|
+
let copied = 0;
|
|
1436
|
+
for (const copy of copies) {
|
|
1437
|
+
const dest = join(outputDir, copy.outputRelPath);
|
|
1438
|
+
mkdirSync(dirname(dest), { recursive: true });
|
|
1439
|
+
copyFileSync(copy.sourceAbs, dest);
|
|
1440
|
+
copied++;
|
|
1441
|
+
}
|
|
1442
|
+
return { copied };
|
|
844
1443
|
}
|
|
845
1444
|
// ─── Tier 1: config-derived ─────────────────────────────────────────────
|
|
846
1445
|
// Files driven entirely by config + flags. Always regenerated; site
|
|
@@ -856,6 +1455,54 @@ export function emitConfigDerivedFiles(outputDir, options) {
|
|
|
856
1455
|
const hasSiteUrl = Boolean(options.siteUrl && /^https?:\/\//.test(options.siteUrl));
|
|
857
1456
|
writeFileSync(join(outputDir, "public", "robots.txt"), buildRobotsTxt(options, hasSiteUrl));
|
|
858
1457
|
}
|
|
1458
|
+
/**
|
|
1459
|
+
* Per-deploy-target artifact emission.
|
|
1460
|
+
*
|
|
1461
|
+
* Called from `emitSiteScaffold` (with `forceOverwrite=writeScaffold`
|
|
1462
|
+
* so `--force` regenerates from template) and from `dogsbay site
|
|
1463
|
+
* build` (with `forceOverwrite=false` so an existing site can adopt
|
|
1464
|
+
* a deploy target by editing config and rebuilding — the missing
|
|
1465
|
+
* artifact gets created on the next build).
|
|
1466
|
+
*
|
|
1467
|
+
* Emit policy is the union: write when forced OR when the file is
|
|
1468
|
+
* missing. Author edits to e.g. the workflow YAML survive every
|
|
1469
|
+
* regular build.
|
|
1470
|
+
*
|
|
1471
|
+
* Currently handles `github-pages` (workflow + .nojekyll). The
|
|
1472
|
+
* existing `cloudflare-workers` artifacts (wrangler.jsonc + package
|
|
1473
|
+
* scripts) stay in the scaffold-only path because they overlap with
|
|
1474
|
+
* scaffold-only files (package.json scripts, devDependencies). A
|
|
1475
|
+
* future refactor could fold them in here too.
|
|
1476
|
+
*/
|
|
1477
|
+
export function emitDeployArtifacts(outputDir, options, opts = { forceOverwrite: false }) {
|
|
1478
|
+
if (options.deploy === "github-pages") {
|
|
1479
|
+
// GitHub reads workflows from <repo-root>/.github/workflows/, NOT
|
|
1480
|
+
// from inside subdirectories. Use projectDir (the repo root) for
|
|
1481
|
+
// the workflow file; fall back to outputDir when unset (flat
|
|
1482
|
+
// `dogsbay convert` flows where the Astro project IS the repo).
|
|
1483
|
+
const projectDir = options.projectDir ?? outputDir;
|
|
1484
|
+
// Path of the Astro output relative to the project root. Used by
|
|
1485
|
+
// the workflow's working-directory + cache-dependency-path so
|
|
1486
|
+
// pnpm install / pnpm run build target the right place. Empty
|
|
1487
|
+
// string when outputDir === projectDir (flat layout).
|
|
1488
|
+
const astroDirRel = relative(projectDir, outputDir).replace(/\\/g, "/");
|
|
1489
|
+
const workflowPath = join(projectDir, ".github", "workflows", "deploy.yml");
|
|
1490
|
+
if (opts.forceOverwrite || !existsSync(workflowPath)) {
|
|
1491
|
+
mkdirSync(dirname(workflowPath), { recursive: true });
|
|
1492
|
+
writeFileSync(workflowPath, buildGitHubPagesWorkflow(astroDirRel));
|
|
1493
|
+
}
|
|
1494
|
+
// .nojekyll — must exist in the deployed artifact root so GH
|
|
1495
|
+
// Pages skips Jekyll's `_underscored-paths` filter (Astro's
|
|
1496
|
+
// `_astro/` chunk dir gets eaten otherwise). Lives inside the
|
|
1497
|
+
// Astro project's `public/` so it's copied into `dist/` at
|
|
1498
|
+
// build time.
|
|
1499
|
+
const nojekyllPath = join(outputDir, "public", ".nojekyll");
|
|
1500
|
+
mkdirSync(dirname(nojekyllPath), { recursive: true });
|
|
1501
|
+
if (opts.forceOverwrite || !existsSync(nojekyllPath)) {
|
|
1502
|
+
writeFileSync(nojekyllPath, "");
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
859
1506
|
/**
|
|
860
1507
|
* Emit `src/data/switcherMap.json` describing per-page
|
|
861
1508
|
* version + locale equivalents. Always writes the file —
|
|
@@ -872,7 +1519,10 @@ export function emitConfigDerivedFiles(outputDir, options) {
|
|
|
872
1519
|
* baseline page in a multi-version site).
|
|
873
1520
|
*/
|
|
874
1521
|
export function emitSwitcherMap(pages, outputDir, options) {
|
|
875
|
-
|
|
1522
|
+
// Switcher URLs use combined so the link the dropdown emits
|
|
1523
|
+
// resolves under the host's served subpath (GH Pages project
|
|
1524
|
+
// pages, multi-mount Cloudflare).
|
|
1525
|
+
const combined = combinedPrefix(options);
|
|
876
1526
|
const dataDir = join(outputDir, "src", "data");
|
|
877
1527
|
const outPath = join(dataDir, "switcherMap.json");
|
|
878
1528
|
// Detect axis activation by inspecting the data the loader
|
|
@@ -911,7 +1561,7 @@ export function emitSwitcherMap(pages, outputDir, options) {
|
|
|
911
1561
|
const variant = {
|
|
912
1562
|
...(ms.locale !== undefined ? { locale: ms.locale } : {}),
|
|
913
1563
|
...(ms.version !== undefined ? { version: ms.version } : {}),
|
|
914
|
-
url: `${
|
|
1564
|
+
url: `${combined}/${page.slug}`,
|
|
915
1565
|
};
|
|
916
1566
|
if (!byLogicalKey[key])
|
|
917
1567
|
byLogicalKey[key] = [];
|
|
@@ -989,6 +1639,10 @@ export function emitMissingTranslationStubs(pages, outputDir, options) {
|
|
|
989
1639
|
return;
|
|
990
1640
|
const basePath = normalizeBasePath(options.basePath);
|
|
991
1641
|
const baseSegments = basePathSegments(basePath);
|
|
1642
|
+
// combined drives the redirect URL (the user-facing path they
|
|
1643
|
+
// get bounced to); basePath stays the filesystem path under
|
|
1644
|
+
// src/pages/ where the stub lives.
|
|
1645
|
+
const combined = combinedPrefix(options);
|
|
992
1646
|
// Index existing pages by (slug after locale segment) so we
|
|
993
1647
|
// can detect missing translations cheaply. Key shape:
|
|
994
1648
|
// `<other-axis-prefix>/<originalSlug>` where other-axis-prefix
|
|
@@ -1022,7 +1676,7 @@ export function emitMissingTranslationStubs(pages, outputDir, options) {
|
|
|
1022
1676
|
const targetUrl = `${basePath}/${targetSlug}`;
|
|
1023
1677
|
if (existingByUrl.has(targetUrl))
|
|
1024
1678
|
continue; // already translated
|
|
1025
|
-
const defaultUrl = `${
|
|
1679
|
+
const defaultUrl = `${combined}/${defaultPage.slug}`;
|
|
1026
1680
|
const filePath = join(outputDir, "src", "pages", ...baseSegments, ...targetSlug.split("/"));
|
|
1027
1681
|
// Ensure parent dir exists; write a redirect-stub Astro
|
|
1028
1682
|
// file. Adding `.astro` to the leaf turns it into a
|
|
@@ -1064,10 +1718,20 @@ export function emitAgentReadinessFiles(pages, outputNav, outputDir, siteName, o
|
|
|
1064
1718
|
if (options.llmsTxt !== false) {
|
|
1065
1719
|
emitLlmsTxtFiles(outputDir, siteName, options, outputNav, pages);
|
|
1066
1720
|
// public/_headers — Cloudflare Workers / Pages convention. Adds an
|
|
1067
|
-
// RFC 8288 Link header pointing agents at
|
|
1068
|
-
// HTML. Emitted alongside
|
|
1721
|
+
// RFC 8288 Link header pointing agents at this mount's llms.txt
|
|
1722
|
+
// (basePath-prefixed) without parsing HTML. Emitted alongside
|
|
1723
|
+
// llms.txt so the two files travel together.
|
|
1069
1724
|
mkdirSync(join(outputDir, "public"), { recursive: true });
|
|
1070
|
-
|
|
1725
|
+
// _headers Link header points at the per-mount llms.txt at
|
|
1726
|
+
// <combined>/llms.txt — the URL agents would actually fetch.
|
|
1727
|
+
writeFileSync(join(outputDir, "public", "_headers"), buildHeadersFile(combinedPrefix(options)));
|
|
1728
|
+
}
|
|
1729
|
+
// Sitemap — emitted by Dogsbay (not @astrojs/sitemap) into
|
|
1730
|
+
// public/<basePath>/sitemap-{index,0}.xml so multi-mount deploys
|
|
1731
|
+
// don't collide at host root. Gated on a valid http(s) siteUrl
|
|
1732
|
+
// because <loc> entries must be absolute.
|
|
1733
|
+
if (options.siteUrl && /^https?:\/\//.test(options.siteUrl)) {
|
|
1734
|
+
emitSitemapFiles(outputDir, options, pages);
|
|
1071
1735
|
}
|
|
1072
1736
|
// src/middleware.ts — Tier 1 (always update). Drives both the
|
|
1073
1737
|
// `Accept: text/markdown` content-negotiation rewrite (via
|
|
@@ -1086,12 +1750,29 @@ export function emitAgentReadinessFiles(pages, outputNav, outputDir, siteName, o
|
|
|
1086
1750
|
const localeRedirectOn = options.defaultLocale !== undefined && knownLocales.length >= 2;
|
|
1087
1751
|
const axisRedirectOn = versionRedirectOn || localeRedirectOn;
|
|
1088
1752
|
if (mdMirrorOn || axisRedirectOn) {
|
|
1753
|
+
// Taxonomy index paths share a single global namespace across
|
|
1754
|
+
// locales / versions (one `/tags/` for the whole site, not one
|
|
1755
|
+
// per locale). The redirect helper has to know to skip them or
|
|
1756
|
+
// it will 302 chip hrefs to non-existent locale-prefixed routes.
|
|
1757
|
+
// Strip leading `/` and pull just the first segment so a config
|
|
1758
|
+
// like `/tags` becomes the global-prefix entry `tags`.
|
|
1759
|
+
const globalPrefixes = [];
|
|
1760
|
+
if (options.taxonomyIndexPaths) {
|
|
1761
|
+
for (const raw of Object.values(options.taxonomyIndexPaths)) {
|
|
1762
|
+
const first = raw.replace(/^\/+/, "").split("/")[0];
|
|
1763
|
+
if (first)
|
|
1764
|
+
globalPrefixes.push(first);
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1089
1767
|
mkdirSync(join(outputDir, "src"), { recursive: true });
|
|
1090
1768
|
writeFileSync(join(outputDir, "src", "middleware.ts"), buildMiddlewareSource({
|
|
1091
1769
|
mdMirror: mdMirrorOn,
|
|
1092
1770
|
axisRedirect: axisRedirectOn
|
|
1093
1771
|
? {
|
|
1094
|
-
|
|
1772
|
+
// Middleware compares paths against the request URL,
|
|
1773
|
+
// which carries the host's served subpath — so use the
|
|
1774
|
+
// combined prefix here.
|
|
1775
|
+
basePath: combinedPrefix(options),
|
|
1095
1776
|
...(versionRedirectOn
|
|
1096
1777
|
? {
|
|
1097
1778
|
defaultVersion: options.defaultVersion,
|
|
@@ -1104,6 +1785,7 @@ export function emitAgentReadinessFiles(pages, outputNav, outputDir, siteName, o
|
|
|
1104
1785
|
knownLocales,
|
|
1105
1786
|
}
|
|
1106
1787
|
: {}),
|
|
1788
|
+
...(globalPrefixes.length > 0 ? { globalPrefixes } : {}),
|
|
1107
1789
|
}
|
|
1108
1790
|
: undefined,
|
|
1109
1791
|
}));
|
|
@@ -1164,21 +1846,49 @@ function buildRobotsTxt(options, hasSiteUrl) {
|
|
|
1164
1846
|
const aiInput = options.aiInput ?? "yes";
|
|
1165
1847
|
const aiTrain = options.aiTrain ?? "no";
|
|
1166
1848
|
const contentSignal = `Content-Signal: search=${search}, ai-input=${aiInput}, ai-train=${aiTrain}\n`;
|
|
1167
|
-
|
|
1168
|
-
|
|
1849
|
+
// Per-mount sitemap path: each Dogsbay site emits its sitemap
|
|
1850
|
+
// index under <basePath>/, so robots.txt must point there too.
|
|
1851
|
+
// (Multi-mount deploys end up with one robots.txt per site at
|
|
1852
|
+
// their respective hosts / paths; each correctly references its
|
|
1853
|
+
// own mount's sitemap-index.)
|
|
1854
|
+
// Sitemap URL = origin + combined + /sitemap-index.xml. Use the
|
|
1855
|
+
// origin (no path) from site.url and the combined prefix (urlBase
|
|
1856
|
+
// + basePath); siteUrl could itself include a path component when
|
|
1857
|
+
// hosting on a subpath (GH Pages project page), so we strip it
|
|
1858
|
+
// here to avoid double-counting.
|
|
1859
|
+
const { origin } = parseSiteUrl(options.siteUrl);
|
|
1860
|
+
const combined = combinedPrefix(options);
|
|
1861
|
+
const sitemap = hasSiteUrl && origin
|
|
1862
|
+
? `Sitemap: ${origin}${withBasePath(combined, "/sitemap-index.xml")}\n`
|
|
1169
1863
|
: "";
|
|
1170
|
-
|
|
1864
|
+
// Llms-Txt: line — non-standard but follows the same shape as
|
|
1865
|
+
// `Sitemap:`. Crawlers and agents that scan robots.txt before
|
|
1866
|
+
// fetching pages get a direct pointer at the per-mount llms.txt.
|
|
1867
|
+
// RFC 9309 explicitly permits unknown directives ("intentionally
|
|
1868
|
+
// permissive of such future extensions") so this is harmless to
|
|
1869
|
+
// standards-compliant parsers. Emitted alongside Sitemap when
|
|
1870
|
+
// siteUrl is set; absolute URLs only (relative paths would be
|
|
1871
|
+
// ambiguous without a base).
|
|
1872
|
+
const llmsTxt = options.llmsTxt !== false && hasSiteUrl && origin
|
|
1873
|
+
? `Llms-Txt: ${origin}${withBasePath(combined, "/llms.txt")}\n`
|
|
1874
|
+
: "";
|
|
1875
|
+
return `User-agent: *\nAllow: /\n${contentSignal}${sitemap}${llmsTxt}`;
|
|
1171
1876
|
}
|
|
1172
1877
|
/**
|
|
1173
1878
|
* Build the contents of `public/_headers` (Cloudflare Pages / Workers
|
|
1174
1879
|
* Static Assets convention). Emits a global RFC 8288 Link header
|
|
1175
|
-
* pointing at
|
|
1880
|
+
* pointing at this mount's llms.txt index, so agents don't need to
|
|
1176
1881
|
* parse HTML to discover the LLM-friendly content listing.
|
|
1882
|
+
*
|
|
1883
|
+
* The Link target is basePath-prefixed (`</docs/llms.txt>` for a
|
|
1884
|
+
* `/docs` mount) — matches where the platform actually emits
|
|
1885
|
+
* llms.txt under the per-mount layout.
|
|
1177
1886
|
*/
|
|
1178
|
-
function buildHeadersFile() {
|
|
1887
|
+
function buildHeadersFile(basePath) {
|
|
1888
|
+
const llmsHref = withBasePath(basePath, "/llms.txt");
|
|
1179
1889
|
return [
|
|
1180
1890
|
"/*",
|
|
1181
|
-
|
|
1891
|
+
` Link: <${llmsHref}>; rel="describedby"; type="text/plain"`,
|
|
1182
1892
|
"",
|
|
1183
1893
|
].join("\n");
|
|
1184
1894
|
}
|
|
@@ -1187,20 +1897,28 @@ function buildMiddlewareSource(config) {
|
|
|
1187
1897
|
"// AUTO-GENERATED by `dogsbay site build` — do not edit.",
|
|
1188
1898
|
"// Composes the docs-layout middleware helpers.",
|
|
1189
1899
|
"//",
|
|
1190
|
-
"//
|
|
1191
|
-
"//
|
|
1192
|
-
"//
|
|
1193
|
-
"//
|
|
1194
|
-
"//
|
|
1195
|
-
"//
|
|
1196
|
-
"//
|
|
1197
|
-
"//
|
|
1198
|
-
"//
|
|
1199
|
-
"// <link rel=\"alternate\" type=\"text/markdown\"> href to fetch",
|
|
1200
|
-
"// the .md mirror directly (e.g. /docs.md).",
|
|
1900
|
+
"// Static-prerender guard:",
|
|
1901
|
+
"// In Astro's static output mode, this middleware is invoked",
|
|
1902
|
+
"// for every prerendered route at build time. Reading",
|
|
1903
|
+
"// `context.request.headers` there triggers an Astro warning",
|
|
1904
|
+
"// per page (\"Astro.request.headers was used during static",
|
|
1905
|
+
"// render\"), which floods `dogsbay site build` / `site preview`",
|
|
1906
|
+
"// output. Worse, the negotiation can't actually happen at",
|
|
1907
|
+
"// build time — there's no runtime client whose Accept header",
|
|
1908
|
+
"// we'd be honoring.",
|
|
1201
1909
|
"//",
|
|
1202
|
-
"//
|
|
1203
|
-
"//
|
|
1910
|
+
"// We guard with `context.isPrerendered` so prerendered routes",
|
|
1911
|
+
"// short-circuit to `next()` immediately. At runtime in static",
|
|
1912
|
+
"// deploys, middleware doesn't fire at all (no server); at",
|
|
1913
|
+
"// runtime in SSR / hybrid deploys, only dynamic routes fire,",
|
|
1914
|
+
"// which is exactly when negotiation makes sense.",
|
|
1915
|
+
"//",
|
|
1916
|
+
"// Markdown content negotiation:",
|
|
1917
|
+
"// For pure-static deploys, `Accept: text/markdown` is honored",
|
|
1918
|
+
"// by the platform (Cloudflare _headers + Worker, Netlify Edge",
|
|
1919
|
+
"// functions). Agents that can't send Accept headers should",
|
|
1920
|
+
"// follow the page's <link rel=\"alternate\" type=\"text/markdown\">",
|
|
1921
|
+
"// to fetch the .md mirror directly (e.g. /docs.md).",
|
|
1204
1922
|
'import { defineMiddleware } from "astro:middleware";',
|
|
1205
1923
|
];
|
|
1206
1924
|
if (config.mdMirror) {
|
|
@@ -1214,6 +1932,11 @@ function buildMiddlewareSource(config) {
|
|
|
1214
1932
|
lines.push(`const AXIS_REDIRECT_CONFIG = ${JSON.stringify(config.axisRedirect, null, 2)};`, "");
|
|
1215
1933
|
}
|
|
1216
1934
|
lines.push("export const onRequest = defineMiddleware((context, next) => {");
|
|
1935
|
+
// Skip prerendered routes — see file-top comment for the rationale.
|
|
1936
|
+
// Avoids per-page Astro.request.headers warnings during build, and
|
|
1937
|
+
// matches runtime semantics (middleware doesn't fire on prerendered
|
|
1938
|
+
// routes when deployed).
|
|
1939
|
+
lines.push(" if (context.isPrerendered) return next();");
|
|
1217
1940
|
lines.push(" const url = new URL(context.request.url);");
|
|
1218
1941
|
if (config.mdMirror) {
|
|
1219
1942
|
lines.push(' const accept = context.request.headers.get("accept");', " const mdTarget = shouldRewriteToMarkdown(accept, url.pathname);", " if (mdTarget) return context.rewrite(mdTarget);");
|
|
@@ -1245,8 +1968,18 @@ function buildMdEndpoint(page, sourceRel) {
|
|
|
1245
1968
|
].join("\n");
|
|
1246
1969
|
}
|
|
1247
1970
|
/**
|
|
1248
|
-
* Emit
|
|
1249
|
-
*
|
|
1971
|
+
* Emit per-mount llms.txt + llms-full.txt + per-section indexes.
|
|
1972
|
+
*
|
|
1973
|
+
* Files live under `public/<basePath>/...` so multiple Dogsbay sites
|
|
1974
|
+
* can mount on the same host (`/docs/llms.txt` + `/api/llms.txt` +
|
|
1975
|
+
* `/handbook/llms.txt`) without colliding at the root. When basePath
|
|
1976
|
+
* is empty, this collapses to `public/llms.txt` — the single-site
|
|
1977
|
+
* llmstxt.org-spec layout.
|
|
1978
|
+
*
|
|
1979
|
+
* The host root `/llms.txt` is intentionally NOT emitted by the
|
|
1980
|
+
* platform: it's the user's umbrella file, analogous to
|
|
1981
|
+
* `sitemap-index.xml`. Multi-mount deploys hand-write a top-level
|
|
1982
|
+
* `/llms.txt` that links to each per-mount index.
|
|
1250
1983
|
*
|
|
1251
1984
|
* Per-section files are written for every top-level nav group that
|
|
1252
1985
|
* resolves to a site directory (either via `group.href` or via the
|
|
@@ -1258,26 +1991,92 @@ function emitLlmsTxtFiles(outputDir, siteName, options, nav, pages) {
|
|
|
1258
1991
|
description: options.description,
|
|
1259
1992
|
siteUrl: options.siteUrl,
|
|
1260
1993
|
};
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1994
|
+
// hrefPrefix is the COMBINED prefix — used for the URL paths that
|
|
1995
|
+
// appear inside the llms.txt body (so agents fetch the correct
|
|
1996
|
+
// host-relative URLs). Filesystem layout uses basePath alone:
|
|
1997
|
+
// `public/<basePath>/llms.txt` matches the existing per-mount
|
|
1998
|
+
// delivery shape.
|
|
1999
|
+
const hrefPrefix = combinedPrefix(options);
|
|
2000
|
+
const basePath = normalizeBasePath(options.basePath);
|
|
2001
|
+
const baseSegments = basePathSegments(basePath);
|
|
2002
|
+
const mountDir = join(outputDir, "public", ...baseSegments);
|
|
2003
|
+
mkdirSync(mountDir, { recursive: true });
|
|
2004
|
+
writeFileSync(join(mountDir, "llms.txt"), buildLlmsTxt(siteConfig, nav, pages, { hrefPrefix }));
|
|
2005
|
+
writeFileSync(join(mountDir, "llms-full.txt"), buildLlmsFullTxt(siteConfig, nav, pages, {
|
|
1266
2006
|
summary: "body",
|
|
1267
2007
|
serializePage: serializePageMd,
|
|
1268
2008
|
hrefPrefix,
|
|
1269
2009
|
}));
|
|
2010
|
+
// Per-section files. `deriveSectionDir` returns a host-absolute
|
|
2011
|
+
// path derived from nav hrefs, which since the combined-prefix
|
|
2012
|
+
// refactor (commit 132891e) include urlBase + basePath — NOT just
|
|
2013
|
+
// basePath. So joining its return onto public/ directly would
|
|
2014
|
+
// double-prefix into `public/<urlBase>/<basePath>/<section>/llms.txt`,
|
|
2015
|
+
// which then serves at `<urlBase>/<urlBase>/<basePath>/<section>/...`
|
|
2016
|
+
// once Astro's base prefix is applied at request time.
|
|
2017
|
+
//
|
|
2018
|
+
// Strip the combined prefix off the section dir to get just the
|
|
2019
|
+
// section tail, then re-prepend basePath via mountDir. Result:
|
|
2020
|
+
// `public/<basePath>/<section>/llms.txt`, served under the deploy's
|
|
2021
|
+
// base mount as `<urlBase>/<basePath>/<section>/llms.txt`.
|
|
2022
|
+
const combinedSegs = hrefPrefix.replace(/^\//, "");
|
|
1270
2023
|
for (const group of nav) {
|
|
1271
2024
|
if (!group.children || group.children.length === 0)
|
|
1272
2025
|
continue;
|
|
1273
2026
|
const dir = deriveSectionDir(group);
|
|
1274
2027
|
if (!dir)
|
|
1275
2028
|
continue;
|
|
1276
|
-
|
|
2029
|
+
let relDir;
|
|
2030
|
+
if (combinedSegs && dir === combinedSegs) {
|
|
2031
|
+
relDir = "";
|
|
2032
|
+
}
|
|
2033
|
+
else if (combinedSegs && dir.startsWith(`${combinedSegs}/`)) {
|
|
2034
|
+
relDir = dir.slice(combinedSegs.length + 1);
|
|
2035
|
+
}
|
|
2036
|
+
else {
|
|
2037
|
+
// Defensive: if for some reason the dir doesn't carry the
|
|
2038
|
+
// combined prefix (older importer, manual nav.yml, etc.), fall
|
|
2039
|
+
// back to the raw value rather than rooting at /.
|
|
2040
|
+
relDir = dir;
|
|
2041
|
+
}
|
|
2042
|
+
const sectionPath = relDir
|
|
2043
|
+
? join(mountDir, relDir, "llms.txt")
|
|
2044
|
+
: join(mountDir, "llms.txt");
|
|
1277
2045
|
mkdirSync(dirname(sectionPath), { recursive: true });
|
|
1278
2046
|
writeFileSync(sectionPath, buildSectionLlmsTxt(siteConfig, group, pages, { hrefPrefix }));
|
|
1279
2047
|
}
|
|
1280
2048
|
}
|
|
2049
|
+
/**
|
|
2050
|
+
* Emit per-mount sitemap files.
|
|
2051
|
+
*
|
|
2052
|
+
* Writes `public/<basePath>/sitemap-index.xml` + `sitemap-0.xml`.
|
|
2053
|
+
* The index lists the single sub-sitemap today; future splits add
|
|
2054
|
+
* more sub-sitemap entries as the page count grows past
|
|
2055
|
+
* sitemaps.org's 50K-URL recommendation.
|
|
2056
|
+
*
|
|
2057
|
+
* Caller has already guarded on a valid http(s) `siteUrl` — without
|
|
2058
|
+
* one, `<loc>` entries can't be absolute and crawlers reject the
|
|
2059
|
+
* file. Skip emission rather than write a broken sitemap.
|
|
2060
|
+
*/
|
|
2061
|
+
function emitSitemapFiles(outputDir, options, pages) {
|
|
2062
|
+
// Filesystem path uses basePath (sitemap files live in
|
|
2063
|
+
// public/<basePath>/sitemap-*.xml). The URL prefix encoded into
|
|
2064
|
+
// each <loc> uses combined so the absolute URLs resolve under the
|
|
2065
|
+
// host's served subpath. buildSitemap strips path off siteUrl
|
|
2066
|
+
// internally, so passing siteUrl + combined as basePath gives
|
|
2067
|
+
// origin + combined as the final URL.
|
|
2068
|
+
const basePath = normalizeBasePath(options.basePath);
|
|
2069
|
+
const combined = combinedPrefix(options);
|
|
2070
|
+
const baseSegments = basePathSegments(basePath);
|
|
2071
|
+
const mountDir = join(outputDir, "public", ...baseSegments);
|
|
2072
|
+
mkdirSync(mountDir, { recursive: true });
|
|
2073
|
+
writeFileSync(join(mountDir, "sitemap-0.xml"), buildSitemap(pages, {
|
|
2074
|
+
siteUrl: options.siteUrl,
|
|
2075
|
+
basePath: combined,
|
|
2076
|
+
siteNoindex: options.noindex === true,
|
|
2077
|
+
}));
|
|
2078
|
+
writeFileSync(join(mountDir, "sitemap-index.xml"), buildSitemapIndex({ siteUrl: options.siteUrl, basePath: combined }));
|
|
2079
|
+
}
|
|
1281
2080
|
/**
|
|
1282
2081
|
* Pick a directory under `public/` for a top-level nav group. Prefers
|
|
1283
2082
|
* the group's own href (already a `/docs/x/y` path); otherwise falls
|
|
@@ -1355,6 +2154,11 @@ function copyComponents(outputDir) {
|
|
|
1355
2154
|
"response-tabs", "schema-viewer", "code-samples", "copy-button",
|
|
1356
2155
|
"markdown-example",
|
|
1357
2156
|
"accordion", "link-card", "avatar", "math",
|
|
2157
|
+
// Icon resolves @ui/icon/Icon.astro → built-time SVG inlining
|
|
2158
|
+
// via @dogsbay/icons. Used by `:::cards` `{icon=...}` and the
|
|
2159
|
+
// inline `:icon[name]` directive. Without this entry every page
|
|
2160
|
+
// emitting the icon import 500s with "module not found".
|
|
2161
|
+
"icon",
|
|
1358
2162
|
];
|
|
1359
2163
|
for (const name of needed) {
|
|
1360
2164
|
const src = join(componentsSource, name);
|
|
@@ -1409,6 +2213,32 @@ function copyAssets(sourceDir, outputDir, imageOptimization) {
|
|
|
1409
2213
|
catch { /* source may not exist */ }
|
|
1410
2214
|
}
|
|
1411
2215
|
// ── CSS generation (ported from import-mkdocs.ts) ───────
|
|
2216
|
+
/**
|
|
2217
|
+
* Build the `@source inline("...")` directive that pins the
|
|
2218
|
+
* grid-tone palette into the generated stylesheet.
|
|
2219
|
+
*
|
|
2220
|
+
* Why we need it: tone classes like `bg-primary/10` only appear in
|
|
2221
|
+
* `.astro` pages emitted by Dogsbay's grid-item serializer. When
|
|
2222
|
+
* Tailwind's content scanner doesn't pick them up — because the
|
|
2223
|
+
* page lives outside the default scan globs, or because a class
|
|
2224
|
+
* is composed at the boundary of an interpolation — they get
|
|
2225
|
+
* purged. Result observed in dogsbay-docs-markdown audit: half
|
|
2226
|
+
* the grid demo cells render with no background. Pinning forces
|
|
2227
|
+
* generation regardless of scanner reach.
|
|
2228
|
+
*
|
|
2229
|
+
* Single source of truth: derived from TONE_CLASSES so any new
|
|
2230
|
+
* tone added to the palette is automatically safelisted.
|
|
2231
|
+
*/
|
|
2232
|
+
function buildToneSafelist() {
|
|
2233
|
+
const seen = new Set();
|
|
2234
|
+
for (const classes of Object.values(TONE_CLASSES)) {
|
|
2235
|
+
for (const cls of classes.split(/\s+/)) {
|
|
2236
|
+
if (cls)
|
|
2237
|
+
seen.add(cls);
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
return [...seen].sort().join(" ");
|
|
2241
|
+
}
|
|
1412
2242
|
function generateGlobalCss() {
|
|
1413
2243
|
return `@import "tailwindcss";
|
|
1414
2244
|
@import "./theme.css";
|
|
@@ -1417,6 +2247,14 @@ function generateGlobalCss() {
|
|
|
1417
2247
|
@source "../../node_modules/@dogsbay/ui/src";
|
|
1418
2248
|
@source "../../node_modules/@dogsbay/docs-layout/src";
|
|
1419
2249
|
|
|
2250
|
+
/* Pin the grid-tone palette. These classes are emitted into
|
|
2251
|
+
markdown-generated .astro pages by the grid-item serializer
|
|
2252
|
+
(TONE_CLASSES in @dogsbay/format-astro). Without inlining,
|
|
2253
|
+
opacity-modified utilities like bg-primary/10 get purged when
|
|
2254
|
+
Tailwind doesn't see them in the scanned globs, leaving grid
|
|
2255
|
+
demo cells with no visible background. */
|
|
2256
|
+
@source inline("${buildToneSafelist()}");
|
|
2257
|
+
|
|
1420
2258
|
/* Prose typography for rendered content */
|
|
1421
2259
|
.docs-prose {
|
|
1422
2260
|
line-height: 1.7;
|
|
@@ -1463,6 +2301,33 @@ function generateGlobalCss() {
|
|
|
1463
2301
|
& dl { margin: 1rem 0; }
|
|
1464
2302
|
& dt { font-weight: 600; margin-top: 0.75rem; }
|
|
1465
2303
|
& dd { margin-left: 1.5rem; color: var(--muted-foreground); }
|
|
2304
|
+
|
|
2305
|
+
/* AsciiDoc block roles ([role="x"] / [.x]) preserved as classes (#384).
|
|
2306
|
+
_abstract marks a module's lead/intro paragraph; .lead/.small are
|
|
2307
|
+
Asciidoctor built-ins; _additional-resources marks the trailing
|
|
2308
|
+
"Additional resources" section heading. */
|
|
2309
|
+
& ._abstract, & .abstract, & .lead {
|
|
2310
|
+
font-size: 1.05rem;
|
|
2311
|
+
line-height: 1.6;
|
|
2312
|
+
color: var(--muted-foreground);
|
|
2313
|
+
}
|
|
2314
|
+
& .small { font-size: 0.875rem; }
|
|
2315
|
+
& h2._additional-resources, & h3._additional-resources {
|
|
2316
|
+
font-size: 1.15rem;
|
|
2317
|
+
margin-top: 2rem;
|
|
2318
|
+
}
|
|
2319
|
+
|
|
2320
|
+
/* Related resources (#384 R3): [role="_additional-resources"] + .Title +
|
|
2321
|
+
list folds to a <section class="related-resources"> (→ DITA related-links). */
|
|
2322
|
+
& .related-resources {
|
|
2323
|
+
margin-top: 2rem;
|
|
2324
|
+
padding-top: 1rem;
|
|
2325
|
+
border-top: 1px solid var(--border);
|
|
2326
|
+
}
|
|
2327
|
+
& .related-resources-title {
|
|
2328
|
+
font-weight: 600;
|
|
2329
|
+
margin: 0 0 0.5rem;
|
|
2330
|
+
}
|
|
1466
2331
|
}
|
|
1467
2332
|
|
|
1468
2333
|
@utility scrollbar-none {
|