@writedocs/generator 0.10.19 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/astro.config.mjs +32 -8
- package/package.json +96 -93
- package/src/cli/base-path-layout.js +44 -0
- package/src/cli/build.js +177 -168
- package/src/cli/check-built-styles.js +41 -33
- package/src/cli/dev.js +261 -244
- package/src/cli/generate-api-pages.js +9 -5
- package/src/cli/page-list-watch.js +69 -66
- package/src/cli/run-pagefind.js +154 -148
- package/src/cli/write-mcp-files.js +103 -96
- package/src/cli/write-redirects-file.js +25 -8
- package/src/components/AppIcon.astro +51 -50
- package/src/components/Card.astro +193 -192
- package/src/components/CopyPageMenu.astro +374 -370
- package/src/components/Hint.astro +188 -187
- package/src/components/Icon.astro +72 -71
- package/src/components/Image.astro +165 -164
- package/src/components/Tile.astro +67 -66
- package/src/components/Video.astro +137 -136
- package/src/layout/BaseLayout.astro +21 -12
- package/src/layout/components/AnalyticsScripts.astro +6 -2
- package/src/layout/components/Breadcrumbs.astro +98 -97
- package/src/layout/components/ConsentBanner.astro +119 -118
- package/src/layout/components/MobileMenu.astro +229 -228
- package/src/layout/components/NavTree.astro +393 -392
- package/src/layout/components/Sidebar.astro +232 -231
- package/src/layout/components/SiteFooter.astro +87 -86
- package/src/layout/components/TopBar.astro +386 -385
- package/src/lib/agent-markdown.js +164 -162
- package/src/lib/asset-dimensions.js +89 -0
- package/src/lib/base-path.js +90 -0
- package/src/lib/config-schema.js +10 -0
- package/src/lib/config-schema.ts +17 -0
- package/src/lib/config.ts +1314 -1289
- package/src/lib/consent.js +108 -102
- package/src/lib/image-size.js +152 -140
- package/src/lib/json-schema-descriptions.js +1 -0
- package/src/lib/link-check.js +42 -4
- package/src/lib/llms-index.ts +90 -88
- package/src/lib/mcp-dev-integration.js +65 -60
- package/src/lib/mcp-index.ts +102 -101
- package/src/lib/pages.js +312 -304
- package/src/lib/project-files-integration.js +116 -61
- package/src/lib/project-files.js +137 -126
- package/src/lib/project-ignore.js +46 -0
- package/src/lib/rehype-base-path.js +62 -0
- package/src/lib/rehype-image-loading.js +71 -71
- package/src/lib/robots-txt.js +21 -16
- package/src/lib/seo-tags.js +155 -140
- package/src/lib/site-base.ts +27 -0
- package/src/lib/styles-asset-integration.js +58 -12
- package/src/lib/wdignore-cases.json +195 -0
- package/src/lib/wdignore.js +177 -0
- package/src/pages/404.astro +63 -62
- package/src/pages/[...slug].astro +1604 -1597
- package/src/pages/[...slug].md.ts +93 -93
- package/src/pages/llms-full.txt.ts +88 -86
- package/src/scripts/search.ts +241 -237
- package/writedocs.schema.json +6 -0
|
@@ -52,12 +52,22 @@
|
|
|
52
52
|
// front the way there is for writedocs.json's own fields. A real static
|
|
53
53
|
// build has no "later" for a live-reload concern to apply to, so a
|
|
54
54
|
// single pass of each here is sufficient.
|
|
55
|
+
//
|
|
56
|
+
// A file the project's ignore rules leave out (lib/wdignore.js: the default
|
|
57
|
+
// exclusions and `.wdignore`) is never served nor copied, whoever names it:
|
|
58
|
+
// the reference is left broken, as for a file that isn't there
|
|
59
|
+
// (`writedocs broken-links` reports it). In `writedocs dev` that goes for
|
|
60
|
+
// public/ too, which Vite would otherwise serve whole; in a build,
|
|
61
|
+
// removeIgnoredPublicFiles() (lib/project-files-integration.js) takes such
|
|
62
|
+
// files out of the output.
|
|
55
63
|
import fs from 'node:fs';
|
|
56
64
|
import path from 'node:path';
|
|
57
65
|
import { fileURLToPath } from 'node:url';
|
|
66
|
+
import { withoutBase } from './base-path.js';
|
|
58
67
|
import { loadDocsConfig, collectConfiguredAssetPaths } from './config.ts';
|
|
59
68
|
import { resolveOutsidePublic } from './asset-path.js';
|
|
60
69
|
import { PUBLISHED_TYPES, isPublishedFile, readSpecPaths } from './project-files.js';
|
|
70
|
+
import { projectIgnore, isIgnoredFile } from './project-ignore.js';
|
|
61
71
|
|
|
62
72
|
const MIME_BY_EXTENSION = {
|
|
63
73
|
'.svg': 'image/svg+xml',
|
|
@@ -91,7 +101,24 @@ function isPublishedFileRequest(urlPath, contentDir) {
|
|
|
91
101
|
} catch {
|
|
92
102
|
return false;
|
|
93
103
|
}
|
|
94
|
-
return isPublishedFile(rel, { specs: readSpecPaths(contentDir) });
|
|
104
|
+
return isPublishedFile(rel, { specs: readSpecPaths(contentDir), rules: projectIgnore(contentDir) });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Whether a request is for a file in public/ that the project's ignore
|
|
108
|
+
* rules leave out - one `writedocs dev` must not serve. */
|
|
109
|
+
function isIgnoredPublicRequest(urlPath, contentDir) {
|
|
110
|
+
let rel;
|
|
111
|
+
try {
|
|
112
|
+
rel = decodeURIComponent(urlPath).replace(/^\/+/, '');
|
|
113
|
+
} catch {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
if (!rel || !projectIgnore(contentDir).ignores(`public/${rel}`)) return false;
|
|
117
|
+
try {
|
|
118
|
+
return fs.statSync(path.join(contentDir, 'public', ...rel.split('/'))).isFile();
|
|
119
|
+
} catch {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
95
122
|
}
|
|
96
123
|
|
|
97
124
|
|
|
@@ -147,7 +174,7 @@ function listFilesWithExtension(dir, extension) {
|
|
|
147
174
|
* writedocs.json field, there's no fixed set of field names to read a
|
|
148
175
|
* content image's path from ahead of time, so instead this reads
|
|
149
176
|
* whatever `src` a page's own rendered markup ends up containing. */
|
|
150
|
-
function copyReferencedContentAssets(outDir, contentDir) {
|
|
177
|
+
function copyReferencedContentAssets(outDir, contentDir, basePath) {
|
|
151
178
|
const attrPattern = /\b(?:src|srcset)="([^"]+)"/g;
|
|
152
179
|
for (const htmlFile of listHtmlFiles(outDir)) {
|
|
153
180
|
const html = fs.readFileSync(htmlFile, 'utf8');
|
|
@@ -156,7 +183,7 @@ function copyReferencedContentAssets(outDir, contentDir) {
|
|
|
156
183
|
// srcset can hold a comma-separated list of "url descriptor" pairs -
|
|
157
184
|
// split it out; a plain src is already just the one URL.
|
|
158
185
|
const candidates = match[1].split(',').map((part) => part.trim().split(/\s+/)[0]).filter(Boolean);
|
|
159
|
-
for (const urlPath of candidates) copyAssetIfMissing(urlPath, outDir, contentDir);
|
|
186
|
+
for (const urlPath of candidates) copyAssetIfMissing(urlPath, outDir, contentDir, basePath);
|
|
160
187
|
}
|
|
161
188
|
// Referências em CSS dentro do próprio HTML: um bloco <style> escrito
|
|
162
189
|
// na página (o `<style>` de uma página `mode: custom`, por exemplo) ou
|
|
@@ -164,13 +191,13 @@ function copyReferencedContentAssets(outDir, contentDir) {
|
|
|
164
191
|
// background-image nunca era copiada para o build e dava 404 em
|
|
165
192
|
// produção, embora funcionasse no dev (onde o middleware resolve
|
|
166
193
|
// qualquer caminho direto do disco).
|
|
167
|
-
for (const urlPath of cssUrlReferences(html)) copyAssetIfMissing(urlPath, outDir, contentDir);
|
|
194
|
+
for (const urlPath of cssUrlReferences(html)) copyAssetIfMissing(urlPath, outDir, contentDir, basePath);
|
|
168
195
|
}
|
|
169
196
|
// O mesmo para as folhas de estilo que o build gera (_astro/*.css): é
|
|
170
197
|
// para onde vai o .css solto na raiz do projeto, carregado automaticamente.
|
|
171
198
|
for (const cssFile of listFilesWithExtension(outDir, '.css')) {
|
|
172
199
|
for (const urlPath of cssUrlReferences(fs.readFileSync(cssFile, 'utf8'))) {
|
|
173
|
-
copyAssetIfMissing(urlPath, outDir, contentDir);
|
|
200
|
+
copyAssetIfMissing(urlPath, outDir, contentDir, basePath);
|
|
174
201
|
}
|
|
175
202
|
}
|
|
176
203
|
}
|
|
@@ -187,32 +214,50 @@ function cssUrlReferences(text) {
|
|
|
187
214
|
}
|
|
188
215
|
|
|
189
216
|
/** Copies one root-relative asset reference into the build output from
|
|
190
|
-
* wherever it lives in the project, unless it's already there.
|
|
191
|
-
|
|
192
|
-
|
|
217
|
+
* wherever it lives in the project, unless it's already there. A built
|
|
218
|
+
* page's addresses carry the site's `basePath` ("/docs/images/a.png" -
|
|
219
|
+
* lib/base-path.js); the file is the one at the address under it, and an
|
|
220
|
+
* address outside the base isn't the site's. */
|
|
221
|
+
function copyAssetIfMissing(address, outDir, contentDir, basePath = '') {
|
|
222
|
+
if (!address.startsWith('/') || address.startsWith('//')) return; // only root-relative - not external, not protocol-relative
|
|
223
|
+
const urlPath = withoutBase(basePath, address);
|
|
224
|
+
if (urlPath === null) return;
|
|
193
225
|
if (!looksLikeAssetPath(urlPath)) return;
|
|
194
226
|
const segments = urlPath.replace(/^\/+/, '').split('/');
|
|
195
227
|
const outPath = path.join(outDir, ...segments);
|
|
196
228
|
if (fs.existsSync(outPath)) return; // already present - via public/'s passthrough copy, or an earlier reference to the same file
|
|
197
229
|
const resolved = resolveOutsidePublic(urlPath, contentDir);
|
|
198
230
|
if (!resolved) return; // doesn't resolve to a real file anywhere in the project either - leave the broken reference as-is
|
|
231
|
+
if (isIgnoredFile(resolved, contentDir)) return; // left out by the ignore rules - never published
|
|
199
232
|
fs.mkdirSync(path.dirname(outPath), { recursive: true });
|
|
200
233
|
fs.copyFileSync(resolved, outPath);
|
|
201
234
|
}
|
|
202
235
|
|
|
203
|
-
|
|
236
|
+
// `basePath`: writedocs.json's, "" or "/docs" (lib/base-path.js). A request
|
|
237
|
+
// outside the base isn't the site's. Astro's dev server takes the base off
|
|
238
|
+
// req.url before this middleware runs, so /docs/images/a.png and a bare
|
|
239
|
+
// /images/a.png would look the same there - the path asked for is
|
|
240
|
+
// req.originalUrl.
|
|
241
|
+
export function stylesAssetFallback(contentDir, { basePath = '' } = {}) {
|
|
204
242
|
return {
|
|
205
243
|
name: 'writedocs-styles-asset-fallback',
|
|
206
244
|
hooks: {
|
|
207
245
|
'astro:server:setup': ({ server }) => {
|
|
208
246
|
server.middlewares.use((req, res, next) => {
|
|
209
247
|
if (!req.url) return next();
|
|
210
|
-
const [
|
|
248
|
+
const [requestPath, query = ''] = (req.originalUrl ?? req.url).split('?');
|
|
249
|
+
const urlPath = withoutBase(basePath, requestPath);
|
|
250
|
+
if (urlPath === null) return next();
|
|
251
|
+
if (!query && isIgnoredPublicRequest(urlPath, contentDir)) {
|
|
252
|
+
res.statusCode = 404;
|
|
253
|
+
res.end('Not found');
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
211
256
|
// A request with a query is Vite's own (a module: `data.json?import`).
|
|
212
257
|
if (!looksLikeAssetPath(urlPath) && (query || !isPublishedFileRequest(urlPath, contentDir))) return next();
|
|
213
258
|
if (fs.existsSync(publicPathFor(urlPath, contentDir))) return next(); // real public/ file - Vite's own static serving already handles it, don't shadow
|
|
214
259
|
const resolved = resolveOutsidePublic(urlPath, contentDir);
|
|
215
|
-
if (!resolved) return next();
|
|
260
|
+
if (!resolved || isIgnoredFile(resolved, contentDir)) return next();
|
|
216
261
|
res.setHeader('Content-Type', mimeFor(resolved));
|
|
217
262
|
fs.createReadStream(resolved).pipe(res);
|
|
218
263
|
});
|
|
@@ -232,13 +277,14 @@ export function stylesAssetFallback(contentDir) {
|
|
|
232
277
|
if (fs.existsSync(outPath)) continue; // already present via public/'s normal passthrough copy
|
|
233
278
|
const resolved = resolveOutsidePublic(urlPath, contentDir);
|
|
234
279
|
if (!resolved) continue; // not configured to a real file anywhere - same as today, just renders a broken <link>/<img>
|
|
280
|
+
if (isIgnoredFile(resolved, contentDir)) continue; // left out by the ignore rules - never published
|
|
235
281
|
fs.mkdirSync(path.dirname(outPath), { recursive: true });
|
|
236
282
|
fs.copyFileSync(resolved, outPath);
|
|
237
283
|
}
|
|
238
284
|
// Pass 2: arbitrary content-body assets - anything a page's own
|
|
239
285
|
// rendered HTML references by src/srcset that pass 1 didn't
|
|
240
286
|
// already account for.
|
|
241
|
-
copyReferencedContentAssets(outDir, contentDir);
|
|
287
|
+
copyReferencedContentAssets(outDir, contentDir, basePath);
|
|
242
288
|
},
|
|
243
289
|
},
|
|
244
290
|
};
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "Test cases for @writedocs/generator/wdignore. For each case: createWdignore(case.wdignore).ignores(path, directory === true) must equal `ignored` for every entry in `paths`. Paths are POSIX, relative to the project root. The generator's own tests (scripts/wdignore.test.js) run this file; any other implementation of the rules should too.",
|
|
3
|
+
"cases": [
|
|
4
|
+
{
|
|
5
|
+
"name": "default exclusions, no .wdignore",
|
|
6
|
+
"wdignore": "",
|
|
7
|
+
"paths": [
|
|
8
|
+
{ "path": ".env", "ignored": true },
|
|
9
|
+
{ "path": ".env.local", "ignored": true },
|
|
10
|
+
{ "path": ".env.example", "ignored": true },
|
|
11
|
+
{ "path": "docs/.env", "ignored": true },
|
|
12
|
+
{ "path": ".git/config", "ignored": true },
|
|
13
|
+
{ "path": ".git", "directory": true, "ignored": true },
|
|
14
|
+
{ "path": ".gitignore", "ignored": true },
|
|
15
|
+
{ "path": ".gitmodules", "ignored": true },
|
|
16
|
+
{ "path": ".gitattributes", "ignored": true },
|
|
17
|
+
{ "path": ".github/workflows/ci.yml", "ignored": true },
|
|
18
|
+
{ "path": ".github", "directory": true, "ignored": true },
|
|
19
|
+
{ "path": ".vscode/settings.json", "ignored": true },
|
|
20
|
+
{ "path": ".DS_Store", "ignored": true },
|
|
21
|
+
{ "path": "docs/.DS_Store", "ignored": true },
|
|
22
|
+
{ "path": "docs/.drafts/plan.pdf", "ignored": true },
|
|
23
|
+
{ "path": ".npmrc", "ignored": true },
|
|
24
|
+
{ "path": ".wdignore", "ignored": true },
|
|
25
|
+
{ "path": ".mintignore", "ignored": true },
|
|
26
|
+
{ "path": ".writedocs/asset-dimensions.json", "ignored": true },
|
|
27
|
+
{ "path": ".writedocs", "directory": true, "ignored": true },
|
|
28
|
+
{ "path": "package.json", "ignored": true },
|
|
29
|
+
{ "path": "examples/package.json", "ignored": true },
|
|
30
|
+
{ "path": "package-lock.json", "ignored": true },
|
|
31
|
+
{ "path": "yarn.lock", "ignored": true },
|
|
32
|
+
{ "path": "pnpm-lock.yaml", "ignored": true },
|
|
33
|
+
{ "path": "bun.lockb", "ignored": true },
|
|
34
|
+
{ "path": "bun.lock", "ignored": true },
|
|
35
|
+
{ "path": "composer.json", "ignored": true },
|
|
36
|
+
{ "path": "composer.lock", "ignored": true },
|
|
37
|
+
{ "path": "node_modules/pkg/index.js", "ignored": true },
|
|
38
|
+
{ "path": "node_modules", "directory": true, "ignored": true },
|
|
39
|
+
{ "path": "examples/app/node_modules/x/a.json", "ignored": true },
|
|
40
|
+
{ "path": "dist/index.html", "ignored": true },
|
|
41
|
+
{ "path": "dist", "directory": true, "ignored": true },
|
|
42
|
+
{ "path": "examples/dist/app.zip", "ignored": true },
|
|
43
|
+
{ "path": "dist", "ignored": false },
|
|
44
|
+
{ "path": "tsconfig.json", "ignored": true },
|
|
45
|
+
{ "path": "jsconfig.json", "ignored": true },
|
|
46
|
+
{ "path": "vercel.json", "ignored": true },
|
|
47
|
+
{ "path": "netlify.json", "ignored": true },
|
|
48
|
+
{ "path": "netlify.toml", "ignored": true },
|
|
49
|
+
{ "path": "wrangler.json", "ignored": true },
|
|
50
|
+
{ "path": "wrangler.jsonc", "ignored": true },
|
|
51
|
+
{ "path": "wrangler.toml", "ignored": true },
|
|
52
|
+
{ "path": "Dockerfile", "ignored": true },
|
|
53
|
+
{ "path": "docker-compose.yml", "ignored": true },
|
|
54
|
+
{ "path": "docker-compose.prod.yaml", "ignored": true },
|
|
55
|
+
{ "path": "certs/server.pem", "ignored": true },
|
|
56
|
+
{ "path": "private.key", "ignored": true },
|
|
57
|
+
{ "path": "store.p12", "ignored": true },
|
|
58
|
+
{ "path": "store.pfx", "ignored": true },
|
|
59
|
+
{ "path": "id_rsa", "ignored": true },
|
|
60
|
+
{ "path": "id_rsa.pub", "ignored": true },
|
|
61
|
+
{ "path": "keys/id_dsa", "ignored": true },
|
|
62
|
+
{ "path": "keys/id_ecdsa", "ignored": true },
|
|
63
|
+
{ "path": "keys/id_ed25519", "ignored": true },
|
|
64
|
+
{ "path": "certs/site.crt", "ignored": true },
|
|
65
|
+
{ "path": "android/release.jks", "ignored": true },
|
|
66
|
+
{ "path": "android/release.keystore", "ignored": true },
|
|
67
|
+
{ "path": "data/app.sqlite", "ignored": true },
|
|
68
|
+
{ "path": "data/app.sqlite3", "ignored": true },
|
|
69
|
+
{ "path": "data/app.db", "ignored": true },
|
|
70
|
+
{ "path": "data/dump.sql", "ignored": true },
|
|
71
|
+
{ "path": "debug.log", "ignored": true },
|
|
72
|
+
{ "path": "Package.JSON", "ignored": true },
|
|
73
|
+
{ "path": "certs/SERVER.PEM", "ignored": true },
|
|
74
|
+
|
|
75
|
+
{ "path": "writedocs.json", "ignored": false },
|
|
76
|
+
{ "path": "docs/intro.mdx", "ignored": false },
|
|
77
|
+
{ "path": "docs", "directory": true, "ignored": false },
|
|
78
|
+
{ "path": "images/hero.png", "ignored": false },
|
|
79
|
+
{ "path": "data/rates.json", "ignored": false },
|
|
80
|
+
{ "path": "docs/guides/export.csv", "ignored": false },
|
|
81
|
+
{ "path": "files/terms.pdf", "ignored": false },
|
|
82
|
+
{ "path": "robots.txt", "ignored": false },
|
|
83
|
+
{ "path": "openapi/api.yaml", "ignored": false },
|
|
84
|
+
{ "path": "snippets/Chart.jsx", "ignored": false },
|
|
85
|
+
{ "path": "theme.css", "ignored": false },
|
|
86
|
+
{ "path": "distribution/notes.txt", "ignored": false },
|
|
87
|
+
{ "path": "docs/environment.txt", "ignored": false },
|
|
88
|
+
{ "path": "docs/keys.txt", "ignored": false },
|
|
89
|
+
{ "path": "docs/package.json.txt", "ignored": false },
|
|
90
|
+
|
|
91
|
+
{ "path": "public/images/logo.svg", "ignored": false },
|
|
92
|
+
{ "path": "public", "directory": true, "ignored": false },
|
|
93
|
+
{ "path": "public/.well-known/security.txt", "ignored": false },
|
|
94
|
+
{ "path": "public/package.json", "ignored": false },
|
|
95
|
+
{ "path": "public/data/dump.sql", "ignored": false },
|
|
96
|
+
{ "path": "public/.env", "ignored": true },
|
|
97
|
+
{ "path": "public/server.key", "ignored": true },
|
|
98
|
+
{ "path": "public/.git/config", "ignored": true },
|
|
99
|
+
{ "path": "public/.npmrc", "ignored": true },
|
|
100
|
+
|
|
101
|
+
{ "path": "", "ignored": true },
|
|
102
|
+
{ "path": "../secret.txt", "ignored": true },
|
|
103
|
+
{ "path": "a/../b.txt", "ignored": true },
|
|
104
|
+
{ "path": "./a.txt", "ignored": true },
|
|
105
|
+
{ "path": "/abs/a.txt", "ignored": true },
|
|
106
|
+
{ "path": "a\\b.txt", "ignored": true }
|
|
107
|
+
]
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"name": "a .wdignore with folder patterns, an anchored pattern, a wildcard and a negation",
|
|
111
|
+
"wdignore": "# drafts and internal data\ndrafts/\n/internal\n\n*.csv\n!docs/public-data/*.csv\n",
|
|
112
|
+
"paths": [
|
|
113
|
+
{ "path": "drafts/a.mdx", "ignored": true },
|
|
114
|
+
{ "path": "drafts", "directory": true, "ignored": true },
|
|
115
|
+
{ "path": "docs/drafts/b.mdx", "ignored": true },
|
|
116
|
+
{ "path": "drafts", "ignored": false },
|
|
117
|
+
{ "path": "internal/x.pdf", "ignored": true },
|
|
118
|
+
{ "path": "docs/internal/x.pdf", "ignored": false },
|
|
119
|
+
{ "path": "data/a.csv", "ignored": true },
|
|
120
|
+
{ "path": "docs/public-data/rates.csv", "ignored": false },
|
|
121
|
+
{ "path": "docs/public-data/deep/x.csv", "ignored": true },
|
|
122
|
+
{ "path": "docs/a.mdx", "ignored": false },
|
|
123
|
+
{ "path": "images/hero.png", "ignored": false },
|
|
124
|
+
{ "path": "public/files/list.csv", "ignored": true },
|
|
125
|
+
{ "path": "public/drafts/a.png", "ignored": true },
|
|
126
|
+
{ "path": "package.json", "ignored": true },
|
|
127
|
+
{ "path": ".env", "ignored": true }
|
|
128
|
+
]
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"name": "a .wdignore with CRLF line endings and a byte order mark",
|
|
132
|
+
"wdignore": "\uFEFFdrafts/\r\n*.csv\r\n",
|
|
133
|
+
"paths": [
|
|
134
|
+
{ "path": "drafts/a.mdx", "ignored": true },
|
|
135
|
+
{ "path": "data/a.csv", "ignored": true },
|
|
136
|
+
{ "path": "docs/a.mdx", "ignored": false }
|
|
137
|
+
]
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"name": "default exclusions brought back with !",
|
|
141
|
+
"wdignore": "!.well-known/\n!examples/package.json\n!*.sql\n!examples/dist/\n",
|
|
142
|
+
"paths": [
|
|
143
|
+
{ "path": ".well-known/security.txt", "ignored": false },
|
|
144
|
+
{ "path": ".well-known", "directory": true, "ignored": false },
|
|
145
|
+
{ "path": ".github/workflows/ci.yml", "ignored": true },
|
|
146
|
+
{ "path": ".gitignore", "ignored": true },
|
|
147
|
+
{ "path": "examples/package.json", "ignored": false },
|
|
148
|
+
{ "path": "package.json", "ignored": true },
|
|
149
|
+
{ "path": "other/package.json", "ignored": true },
|
|
150
|
+
{ "path": "data/schema.sql", "ignored": false },
|
|
151
|
+
{ "path": "data/app.db", "ignored": true },
|
|
152
|
+
{ "path": "examples/dist/bundle.zip", "ignored": false },
|
|
153
|
+
{ "path": "dist/bundle.zip", "ignored": true },
|
|
154
|
+
{ "path": "other/dist/bundle.zip", "ignored": true }
|
|
155
|
+
]
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"name": "a folder brought back, with one file in it left out again",
|
|
159
|
+
"wdignore": "!.well-known/\n.well-known/private.txt\n",
|
|
160
|
+
"paths": [
|
|
161
|
+
{ "path": ".well-known/security.txt", "ignored": false },
|
|
162
|
+
{ "path": ".well-known/private.txt", "ignored": true }
|
|
163
|
+
]
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
"name": "a file can't be brought back while its folder is left out (the .gitignore rule)",
|
|
167
|
+
"wdignore": "!.well-known/security.txt\n",
|
|
168
|
+
"paths": [
|
|
169
|
+
{ "path": ".well-known/security.txt", "ignored": true },
|
|
170
|
+
{ "path": ".well-known", "directory": true, "ignored": true }
|
|
171
|
+
]
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"name": "the locked exclusions can't be brought back",
|
|
175
|
+
"wdignore": "!.env\n!.env.*\n!*.pem\n!*.key\n!*.p12\n!*.pfx\n!.git/\n!.npmrc\n!id_rsa*\n!id_ed25519*\n!*\n",
|
|
176
|
+
"paths": [
|
|
177
|
+
{ "path": ".env", "ignored": true },
|
|
178
|
+
{ "path": ".env.example", "ignored": true },
|
|
179
|
+
{ "path": "certs/server.pem", "ignored": true },
|
|
180
|
+
{ "path": "private.key", "ignored": true },
|
|
181
|
+
{ "path": "store.p12", "ignored": true },
|
|
182
|
+
{ "path": "store.pfx", "ignored": true },
|
|
183
|
+
{ "path": ".git/HEAD", "ignored": true },
|
|
184
|
+
{ "path": ".npmrc", "ignored": true },
|
|
185
|
+
{ "path": "id_rsa.pub", "ignored": true },
|
|
186
|
+
{ "path": "keys/id_ed25519", "ignored": true },
|
|
187
|
+
{ "path": "public/.env", "ignored": true },
|
|
188
|
+
{ "path": "public/server.key", "ignored": true },
|
|
189
|
+
{ "path": "package.json", "ignored": false },
|
|
190
|
+
{ "path": ".gitignore", "ignored": false },
|
|
191
|
+
{ "path": "data/dump.sql", "ignored": false }
|
|
192
|
+
]
|
|
193
|
+
}
|
|
194
|
+
]
|
|
195
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// Which of a project's files are left out: never published, never read as
|
|
2
|
+
// content. Three layers, in this order:
|
|
3
|
+
//
|
|
4
|
+
// LOCKED_PATTERNS - secrets. Always left out; no `.wdignore` line brings
|
|
5
|
+
// one back.
|
|
6
|
+
// DEFAULT_PATTERNS - tooling and data that a docs repository holds but a
|
|
7
|
+
// site rarely means to publish. Left out unless the
|
|
8
|
+
// project's `.wdignore` re-includes them with `!`.
|
|
9
|
+
// the project's `.wdignore` - its own patterns, in .gitignore syntax.
|
|
10
|
+
//
|
|
11
|
+
// Files under the top-level `public/` folder are the exception to the
|
|
12
|
+
// second layer: putting a file there is already saying "publish this", so
|
|
13
|
+
// only LOCKED_PATTERNS and the project's own `.wdignore` apply to them
|
|
14
|
+
// (`public/.well-known/security.txt` is published; `public/.env` is not).
|
|
15
|
+
//
|
|
16
|
+
// THIS FILE IS A CONTRACT. The WriteDocs platform imports it
|
|
17
|
+
// (`@writedocs/generator/wdignore`) and applies the same rules when it
|
|
18
|
+
// syncs a project, so a `.env` never reaches its storage. It runs in a
|
|
19
|
+
// Cloudflare Worker there: nothing from Node (`fs`, `path`, `process`,
|
|
20
|
+
// `Buffer`) may be imported or used here - only `ignore`, which is plain
|
|
21
|
+
// JavaScript. It takes paths and the text of `.wdignore`; whoever calls it
|
|
22
|
+
// does the reading. scripts/wdignore.test.js bundles it for a browser to
|
|
23
|
+
// prove it, and runs every case in wdignore-cases.json, which the platform
|
|
24
|
+
// runs too.
|
|
25
|
+
//
|
|
26
|
+
// The two lists below are the only place the default exclusions are
|
|
27
|
+
// written. The docs (site/ and docs/dev/) describe them; nothing else
|
|
28
|
+
// repeats them.
|
|
29
|
+
import ignore from 'ignore';
|
|
30
|
+
|
|
31
|
+
/** The project's own ignore file, at its root. */
|
|
32
|
+
export const WDIGNORE_FILE = '.wdignore';
|
|
33
|
+
|
|
34
|
+
/** Never published and never synced, whatever `.wdignore` says. */
|
|
35
|
+
export const LOCKED_PATTERNS = [
|
|
36
|
+
// Environment files: API keys and passwords.
|
|
37
|
+
'.env',
|
|
38
|
+
'.env.*',
|
|
39
|
+
// The repository's own history.
|
|
40
|
+
'.git/',
|
|
41
|
+
// npm's configuration, which can hold a registry token.
|
|
42
|
+
'.npmrc',
|
|
43
|
+
// Private keys and the containers that hold them.
|
|
44
|
+
'*.pem',
|
|
45
|
+
'*.key',
|
|
46
|
+
'*.p12',
|
|
47
|
+
'*.pfx',
|
|
48
|
+
'id_rsa*',
|
|
49
|
+
'id_dsa*',
|
|
50
|
+
'id_ecdsa*',
|
|
51
|
+
'id_ed25519*',
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
/** Left out by default; a `.wdignore` line starting with `!` brings one back. */
|
|
55
|
+
export const DEFAULT_PATTERNS = [
|
|
56
|
+
// Every file and folder whose name starts with a dot: .gitignore,
|
|
57
|
+
// .gitmodules, .gitattributes, .github/, .vscode/, .DS_Store, .wdignore,
|
|
58
|
+
// .writedocs/ ...
|
|
59
|
+
'.*',
|
|
60
|
+
// Package manifests and lockfiles.
|
|
61
|
+
'package.json',
|
|
62
|
+
'package-lock.json',
|
|
63
|
+
'yarn.lock',
|
|
64
|
+
'pnpm-lock.yaml',
|
|
65
|
+
'bun.lockb',
|
|
66
|
+
'bun.lock',
|
|
67
|
+
'composer.json',
|
|
68
|
+
'composer.lock',
|
|
69
|
+
// Dependencies and build output, at any depth.
|
|
70
|
+
'node_modules/',
|
|
71
|
+
'dist/',
|
|
72
|
+
// Tooling and hosting configuration.
|
|
73
|
+
'tsconfig.json',
|
|
74
|
+
'jsconfig.json',
|
|
75
|
+
'vercel.json',
|
|
76
|
+
'netlify.json',
|
|
77
|
+
'netlify.toml',
|
|
78
|
+
'wrangler.json',
|
|
79
|
+
'wrangler.jsonc',
|
|
80
|
+
'wrangler.toml',
|
|
81
|
+
'Dockerfile',
|
|
82
|
+
'docker-compose*.yml',
|
|
83
|
+
'docker-compose*.yaml',
|
|
84
|
+
// Certificates and key stores.
|
|
85
|
+
'*.crt',
|
|
86
|
+
'*.jks',
|
|
87
|
+
'*.keystore',
|
|
88
|
+
// Databases and dumps.
|
|
89
|
+
'*.sqlite',
|
|
90
|
+
'*.sqlite3',
|
|
91
|
+
'*.db',
|
|
92
|
+
'*.sql',
|
|
93
|
+
// Logs.
|
|
94
|
+
'*.log',
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
/** Paths that are left out of the site (the patterns above match them) but
|
|
98
|
+
* that the build reads. A sync that drops ignored files must still deliver
|
|
99
|
+
* these, or the build runs with different rules than the sync did. */
|
|
100
|
+
export const BUILD_INPUT_PATHS = ['.wdignore', '.mintignore', '.writedocs/asset-dimensions.json'];
|
|
101
|
+
|
|
102
|
+
/** The top-level folder whose files skip DEFAULT_PATTERNS. */
|
|
103
|
+
const PUBLIC_DIR = 'public';
|
|
104
|
+
|
|
105
|
+
function clean(text) {
|
|
106
|
+
return typeof text === 'string' ? text.replace(/^\uFEFF/, '') : '';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** A project-relative POSIX path ("docs/a.pdf", no leading slash) with any
|
|
110
|
+
* trailing slash removed, or null when it isn't one: empty, absolute,
|
|
111
|
+
* with a backslash, or with a `.`/`..` segment. */
|
|
112
|
+
function normalize(relPath) {
|
|
113
|
+
if (typeof relPath !== 'string') return null;
|
|
114
|
+
const trimmed = relPath.replace(/\/+$/, '');
|
|
115
|
+
if (!trimmed || trimmed.startsWith('/') || trimmed.includes('\\')) return null;
|
|
116
|
+
if (trimmed.split('/').some((segment) => segment === '' || segment === '.' || segment === '..')) return null;
|
|
117
|
+
return trimmed;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** The rules for one project. `text` is the content of its `.wdignore`
|
|
121
|
+
* ('' or undefined when it has none).
|
|
122
|
+
*
|
|
123
|
+
* `ignores(relPath, isDirectory)` says whether a path is left out.
|
|
124
|
+
* `relPath` is a POSIX path from the project root, with no leading slash;
|
|
125
|
+
* pass `isDirectory` as true for a folder (a pattern ending in `/` only
|
|
126
|
+
* matches folders). A path inside an ignored folder is ignored. A path
|
|
127
|
+
* that isn't a valid project-relative path is ignored too - the safe
|
|
128
|
+
* answer. Matching ignores letter case, as it does on the file systems
|
|
129
|
+
* most projects are written on.
|
|
130
|
+
*
|
|
131
|
+
* `isLocked(relPath, isDirectory)` says whether LOCKED_PATTERNS is the
|
|
132
|
+
* reason - a path `.wdignore` can't bring back. */
|
|
133
|
+
export function createWdignore(text = '') {
|
|
134
|
+
const own = clean(text);
|
|
135
|
+
const locked = ignore().add(LOCKED_PATTERNS);
|
|
136
|
+
const everywhere = ignore().add(DEFAULT_PATTERNS).add(own);
|
|
137
|
+
const inPublic = ignore().add(own);
|
|
138
|
+
|
|
139
|
+
const target = (relPath, isDirectory) => {
|
|
140
|
+
const normal = normalize(relPath);
|
|
141
|
+
return normal === null ? null : isDirectory ? `${normal}/` : normal;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
ignores(relPath, isDirectory = false) {
|
|
146
|
+
const p = target(relPath, isDirectory);
|
|
147
|
+
if (p === null) return true;
|
|
148
|
+
if (locked.ignores(p)) return true;
|
|
149
|
+
const underPublic = p.toLowerCase().startsWith(`${PUBLIC_DIR}/`);
|
|
150
|
+
return (underPublic ? inPublic : everywhere).ignores(p);
|
|
151
|
+
},
|
|
152
|
+
isLocked(relPath, isDirectory = false) {
|
|
153
|
+
const p = target(relPath, isDirectory);
|
|
154
|
+
return p !== null && locked.ignores(p);
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Splits a list of file paths by the rules: `kept` are the files a sync
|
|
160
|
+
* delivers and a build may publish; `ignored` are left out. `buildInputs`
|
|
161
|
+
* are the ignored ones the build still has to receive (BUILD_INPUT_PATHS).
|
|
162
|
+
* Every list keeps the order of `paths`. */
|
|
163
|
+
export function partitionPaths(paths, text = '') {
|
|
164
|
+
const rules = createWdignore(text);
|
|
165
|
+
const inputs = new Set(BUILD_INPUT_PATHS);
|
|
166
|
+
const kept = [];
|
|
167
|
+
const ignored = [];
|
|
168
|
+
const buildInputs = [];
|
|
169
|
+
for (const p of paths) {
|
|
170
|
+
if (!rules.ignores(p)) kept.push(p);
|
|
171
|
+
else {
|
|
172
|
+
ignored.push(p);
|
|
173
|
+
if (inputs.has(p)) buildInputs.push(p);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return { kept, ignored, buildInputs };
|
|
177
|
+
}
|
package/src/pages/404.astro
CHANGED
|
@@ -1,62 +1,63 @@
|
|
|
1
|
-
---
|
|
2
|
-
// Astro's own file-based convention: a static build (`output: 'static'`,
|
|
3
|
-
// this package's only supported mode - see astro.config.mjs) emits this
|
|
4
|
-
// file's output as a literal `404.html` at the site root, and most static
|
|
5
|
-
// hosts (Netlify, Vercel, GitHub Pages, Cloudflare Pages, ...) serve it
|
|
6
|
-
// automatically for any unmatched path. No params, no getStaticPaths -
|
|
7
|
-
// this is a single fixed route, same category as llms.txt.ts/
|
|
8
|
-
// llms-full.txt.ts (see their own comments on Astro auto-prerendering a
|
|
9
|
-
// non-dynamic page at its literal path).
|
|
10
|
-
import { loadDocsConfig } from '../lib/config';
|
|
11
|
-
import BaseLayout from '../layout/BaseLayout.astro';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
<
|
|
27
|
-
<
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
</
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
font-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
1
|
+
---
|
|
2
|
+
// Astro's own file-based convention: a static build (`output: 'static'`,
|
|
3
|
+
// this package's only supported mode - see astro.config.mjs) emits this
|
|
4
|
+
// file's output as a literal `404.html` at the site root, and most static
|
|
5
|
+
// hosts (Netlify, Vercel, GitHub Pages, Cloudflare Pages, ...) serve it
|
|
6
|
+
// automatically for any unmatched path. No params, no getStaticPaths -
|
|
7
|
+
// this is a single fixed route, same category as llms.txt.ts/
|
|
8
|
+
// llms-full.txt.ts (see their own comments on Astro auto-prerendering a
|
|
9
|
+
// non-dynamic page at its literal path).
|
|
10
|
+
import { loadDocsConfig } from '../lib/config';
|
|
11
|
+
import BaseLayout from '../layout/BaseLayout.astro';
|
|
12
|
+
import { siteHref } from '../lib/site-base';
|
|
13
|
+
|
|
14
|
+
const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
|
|
15
|
+
const config = loadDocsConfig(contentDir);
|
|
16
|
+
|
|
17
|
+
// writedocs.json's `notFound.{title,description}` (notFoundSchema in
|
|
18
|
+
// lib/config.ts) - both optional, with the hardcoded fallbacks below, so
|
|
19
|
+
// a site gets a reasonably branded 404 page without having to configure
|
|
20
|
+
// anything.
|
|
21
|
+
const title = config.notFound.title ?? 'Page not found';
|
|
22
|
+
const description = config.notFound.description ?? "The page you're looking for doesn't exist or has moved.";
|
|
23
|
+
---
|
|
24
|
+
<BaseLayout config={config} title={title} description={description} path="/404/" seo={{ noindex: true }} mode="frame">
|
|
25
|
+
<div class="wd-404">
|
|
26
|
+
<p class="wd-404-eyebrow">404</p>
|
|
27
|
+
<h1>{title}</h1>
|
|
28
|
+
<p class="wd-404-description">{description}</p>
|
|
29
|
+
<a class="wd-404-home" href={siteHref("/")}>← Back to home</a>
|
|
30
|
+
</div>
|
|
31
|
+
</BaseLayout>
|
|
32
|
+
|
|
33
|
+
<style>
|
|
34
|
+
.wd-404 {
|
|
35
|
+
max-width: 560px;
|
|
36
|
+
margin: 0 auto;
|
|
37
|
+
padding: 5rem 1.5rem 6rem;
|
|
38
|
+
text-align: center;
|
|
39
|
+
}
|
|
40
|
+
.wd-404-eyebrow {
|
|
41
|
+
margin: 0 0 0.5rem;
|
|
42
|
+
font-size: 0.85rem;
|
|
43
|
+
font-weight: 600;
|
|
44
|
+
letter-spacing: 0.08em;
|
|
45
|
+
color: var(--wd-primary);
|
|
46
|
+
}
|
|
47
|
+
.wd-404 h1 {
|
|
48
|
+
margin: 0 0 0.75rem;
|
|
49
|
+
font-size: 1.75rem;
|
|
50
|
+
}
|
|
51
|
+
.wd-404-description {
|
|
52
|
+
margin: 0 0 2rem;
|
|
53
|
+
color: var(--wd-text-muted);
|
|
54
|
+
}
|
|
55
|
+
.wd-404-home {
|
|
56
|
+
color: var(--wd-primary);
|
|
57
|
+
text-decoration: none;
|
|
58
|
+
font-weight: 500;
|
|
59
|
+
}
|
|
60
|
+
.wd-404-home:hover {
|
|
61
|
+
text-decoration: underline;
|
|
62
|
+
}
|
|
63
|
+
</style>
|