@writedocs/generator 0.13.5 → 0.15.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 +31 -69
- package/bin/writedocs.js +4 -1
- package/package.json +4 -2
- package/packages/components/package.json +53 -0
- package/{src → packages/components/src}/components/Accordion.astro +2 -2
- package/{src → packages/components/src}/components/AppIcon.astro +3 -3
- package/{src → packages/components/src}/components/Callout.astro +3 -3
- package/{src → packages/components/src}/components/CodeBlock.astro +8 -27
- package/{src → packages/components/src}/components/CodeGroup.astro +3 -3
- package/{src → packages/components/src}/components/Image.astro +7 -9
- package/{src → packages/components/src}/components/compound.ts +1 -1
- package/packages/components/src/host.js +24 -0
- package/packages/components/src/index.ts +59 -0
- package/packages/components/src/integration.js +151 -0
- package/packages/components/src/lib/base-path.js +39 -0
- package/{src → packages/components/src}/lib/code-line-numbers.js +1 -1
- package/packages/components/src/lib/code-transformers.js +45 -0
- package/{src → packages/components/src}/lib/icons.js +13 -7
- package/{src → packages/components/src}/lib/shiki-code-block.js +9 -9
- package/{src → packages/components/src}/lib/site-base.ts +9 -6
- package/packages/components/src/scripts/code-block.ts +62 -0
- package/packages/components/src/styles/components.css +373 -0
- package/packages/components/src/styles/theme.css +63 -0
- package/src/cli/build.js +23 -3
- package/src/cli/dev.js +2 -1
- package/src/cli/generate-api-pages.js +9 -7
- package/src/cli/page-list-watch.js +4 -2
- package/src/cli/run-astro.js +2 -2
- package/src/components/ApiPlayground.astro +2 -2
- package/src/components/ApiSchemaField.astro +1 -1
- package/src/components/CopyPageMenu.astro +2 -2
- package/src/content.config.ts +16 -0
- package/src/icons/README.md +1 -1
- package/src/layout/BaseLayout.astro +7 -2
- package/src/layout/components/AnalyticsScripts.astro +2 -2
- package/src/layout/components/Breadcrumbs.astro +1 -1
- package/src/layout/components/ConsentBanner.astro +1 -1
- package/src/layout/components/MobileMenu.astro +2 -2
- package/src/layout/components/NavTree.astro +16 -2
- package/src/layout/components/Sidebar.astro +2 -2
- package/src/layout/components/SiteFooter.astro +2 -2
- package/src/layout/components/TopBar.astro +2 -2
- package/src/layout/styles/base.css +4 -37
- package/src/lib/a11y-check.js +1 -1
- package/src/lib/base-path.js +4 -25
- package/src/lib/color.js +1 -1
- package/src/lib/components-host.ts +21 -0
- package/src/lib/config-file.js +1 -1
- package/src/lib/config-schema.js +12 -1
- package/src/lib/config-schema.ts +14 -0
- package/src/lib/config.ts +22 -6
- package/src/lib/content-check.js +6 -3
- package/src/lib/drafts.js +186 -0
- package/src/lib/link-check.js +13 -4
- package/src/lib/mdx-inject-builtins.js +2 -2
- package/src/lib/mdx-inline-react.js +1 -1
- package/src/lib/mdx-title-anchor-ids.js +2 -2
- package/src/lib/mdx-unknown-components.js +1 -1
- package/src/lib/mintlify-convert.js +2 -2
- package/src/lib/openapi-reload-integration.js +1 -1
- package/src/lib/pages.js +41 -7
- package/src/lib/project-files-integration.js +1 -1
- package/src/lib/rehype-base-path.js +1 -1
- package/src/lib/seo-tags.js +3 -1
- package/src/lib/writedocs-legacy-convert.js +1 -1
- package/src/pages/404.astro +1 -1
- package/src/pages/[...slug].astro +65 -417
- package/src/components/index.ts +0 -62
- /package/{src → packages/components/src}/components/AccordionGroup.astro +0 -0
- /package/{src → packages/components/src}/components/Badge.astro +0 -0
- /package/{src → packages/components/src}/components/Card.astro +0 -0
- /package/{src → packages/components/src}/components/CardGroup.astro +0 -0
- /package/{src → packages/components/src}/components/Check.astro +0 -0
- /package/{src → packages/components/src}/components/Color.astro +0 -0
- /package/{src → packages/components/src}/components/ColorItem.astro +0 -0
- /package/{src → packages/components/src}/components/ColorRow.astro +0 -0
- /package/{src → packages/components/src}/components/Column.astro +0 -0
- /package/{src → packages/components/src}/components/Columns.astro +0 -0
- /package/{src → packages/components/src}/components/Danger.astro +0 -0
- /package/{src → packages/components/src}/components/Expandable.astro +0 -0
- /package/{src → packages/components/src}/components/Frame.astro +0 -0
- /package/{src → packages/components/src}/components/GitHubRepo.astro +0 -0
- /package/{src → packages/components/src}/components/Hint.astro +0 -0
- /package/{src → packages/components/src}/components/Icon.astro +0 -0
- /package/{src → packages/components/src}/components/Info.astro +0 -0
- /package/{src → packages/components/src}/components/Note.astro +0 -0
- /package/{src → packages/components/src}/components/Panel.astro +0 -0
- /package/{src → packages/components/src}/components/ParamField.astro +0 -0
- /package/{src → packages/components/src}/components/Parameter.astro +0 -0
- /package/{src → packages/components/src}/components/Prompt.astro +0 -0
- /package/{src → packages/components/src}/components/RequestExample.astro +0 -0
- /package/{src → packages/components/src}/components/ResponseExample.astro +0 -0
- /package/{src → packages/components/src}/components/ResponseField.astro +0 -0
- /package/{src → packages/components/src}/components/Searchbar.astro +0 -0
- /package/{src → packages/components/src}/components/Step.astro +0 -0
- /package/{src → packages/components/src}/components/Steps.astro +0 -0
- /package/{src → packages/components/src}/components/Tab.astro +0 -0
- /package/{src → packages/components/src}/components/Tabs.astro +0 -0
- /package/{src → packages/components/src}/components/Tile.astro +0 -0
- /package/{src → packages/components/src}/components/Tip.astro +0 -0
- /package/{src → packages/components/src}/components/Tooltip.astro +0 -0
- /package/{src → packages/components/src}/components/Tree.astro +0 -0
- /package/{src → packages/components/src}/components/TreeFile.astro +0 -0
- /package/{src → packages/components/src}/components/TreeFolder.astro +0 -0
- /package/{src → packages/components/src}/components/Update.astro +0 -0
- /package/{src → packages/components/src}/components/Video.astro +0 -0
- /package/{src → packages/components/src}/components/View.astro +0 -0
- /package/{src → packages/components/src}/components/Visibility.astro +0 -0
- /package/{src → packages/components/src}/components/Warning.astro +0 -0
- /package/{src → packages/components/src}/components/class-names.ts +0 -0
- /package/{src → packages/components/src}/lib/cli-report.js +0 -0
- /package/{src → packages/components/src}/lib/inline-markdown.js +0 -0
- /package/{src → packages/components/src}/lib/plain-text.js +0 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// Draft pages - `draft: true` in a page's frontmatter (Docusaurus' key).
|
|
2
|
+
//
|
|
3
|
+
// In `writedocs build` a draft doesn't exist: it's left out where the build
|
|
4
|
+
// decides which pages there are - findAllPages() in lib/pages.js, the list
|
|
5
|
+
// every route, the content collection, the sitemap and `writedocs
|
|
6
|
+
// broken-links` start from - and where it reads the navigation:
|
|
7
|
+
// loadDocsConfig() in lib/config.ts puts the navigation through
|
|
8
|
+
// withoutDrafts() below, so the sidebar, the switchers, prev/next, the "/"
|
|
9
|
+
// redirect, llms.txt and the MCP index never see an entry for one. Nothing
|
|
10
|
+
// downstream filters drafts on its own.
|
|
11
|
+
//
|
|
12
|
+
// `writedocs dev` and `writedocs build --drafts` - a preview of them, for
|
|
13
|
+
// deploy previews - keep them (draftsIncluded() in lib/pages.js), marked: a
|
|
14
|
+
// strip at the top of the page (DRAFT_BANNER_HTML below, [...slug].astro), a
|
|
15
|
+
// mark on its sidebar entry (NavTree.astro) and "Draft" on its search
|
|
16
|
+
// result's section line - and noindex: the page schema makes every draft
|
|
17
|
+
// noindex (lib/config-schema.ts), which keeps it out of the sitemap, llms.txt
|
|
18
|
+
// and the MCP index the way any noindex page is.
|
|
19
|
+
//
|
|
20
|
+
// Plain JavaScript, for scripts/drafts.test.js and for the CLI, which prints
|
|
21
|
+
// draftWarnings() with the build's other warnings. No import of
|
|
22
|
+
// lib/config-schema.js: lib/config.ts loads this file inside Astro, where the
|
|
23
|
+
// schema comes from config-schema.ts - draftWarnings() gets its line locator
|
|
24
|
+
// from the caller instead.
|
|
25
|
+
import { navPageId, fileIdForPath } from './pages.js';
|
|
26
|
+
|
|
27
|
+
/** The key that names each kind of navigation item, in the order they're
|
|
28
|
+
* looked for - what a warning calls the item. */
|
|
29
|
+
const ITEM_KINDS = ['group', 'tab', 'version', 'language', 'dropdown', 'product'];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* `navigation` without the entries that name a draft page: a page in a
|
|
33
|
+
* `pages` list, or an item's own `page`. An item that had pages and is left
|
|
34
|
+
* with none - every page in it was a draft - goes too, and so on up: a tab
|
|
35
|
+
* whose groups all went. An item that keeps its own `page`, or that never
|
|
36
|
+
* had pages (an `href`, an `openapi` group, which gets its pages later), is
|
|
37
|
+
* kept. The navigation's root is always kept.
|
|
38
|
+
*
|
|
39
|
+
* `draftIds` - the drafts' page ids (fileIdForPath()); a navigation entry
|
|
40
|
+
* matches by its page id (navPageId(): "guides/index" is "guides"). With no
|
|
41
|
+
* drafts, `navigation` itself comes back. Returns { navigation, leftOut }:
|
|
42
|
+
* `leftOut` lists what was taken out, in the order it was met - `{ path,
|
|
43
|
+
* page }` for an entry (`page` as the navigation writes it), `{ path, kind,
|
|
44
|
+
* name }` for an item - with `path` the JSON path from `navigation`.
|
|
45
|
+
*/
|
|
46
|
+
export function withoutDrafts(navigation, draftIds) {
|
|
47
|
+
const leftOut = [];
|
|
48
|
+
if (!draftIds || draftIds.size === 0) return { navigation, leftOut };
|
|
49
|
+
const isDraftEntry = (value) => typeof value === 'string' && draftIds.has(navPageId(value));
|
|
50
|
+
const REMOVED = Symbol('removed');
|
|
51
|
+
|
|
52
|
+
function prune(node, trail) {
|
|
53
|
+
if (Array.isArray(node)) {
|
|
54
|
+
const kept = [];
|
|
55
|
+
node.forEach((item, i) => {
|
|
56
|
+
if (isDraftEntry(item)) {
|
|
57
|
+
leftOut.push({ path: [...trail, i], page: item });
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const value = prune(item, [...trail, i]);
|
|
61
|
+
if (value !== REMOVED) kept.push(value);
|
|
62
|
+
});
|
|
63
|
+
return kept;
|
|
64
|
+
}
|
|
65
|
+
if (!node || typeof node !== 'object') return node;
|
|
66
|
+
const out = {};
|
|
67
|
+
let hadPages = false;
|
|
68
|
+
let hasPages = false;
|
|
69
|
+
for (const [key, value] of Object.entries(node)) {
|
|
70
|
+
if (key === 'href' || key === 'openapi') {
|
|
71
|
+
out[key] = value;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (key === 'page' && typeof value === 'string') {
|
|
75
|
+
if (isDraftEntry(value)) leftOut.push({ path: [...trail, key], page: value });
|
|
76
|
+
else out[key] = value;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const pruned = prune(value, [...trail, key]);
|
|
80
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
81
|
+
hadPages = true;
|
|
82
|
+
if (pruned.length > 0) hasPages = true;
|
|
83
|
+
}
|
|
84
|
+
out[key] = pruned;
|
|
85
|
+
}
|
|
86
|
+
const emptied = hadPages && !hasPages && !('page' in out) && !('href' in out) && !('openapi' in out);
|
|
87
|
+
if (emptied && trail.length > 0) {
|
|
88
|
+
const kind = ITEM_KINDS.find((k) => typeof node[k] === 'string') ?? 'item';
|
|
89
|
+
leftOut.push({ path: trail, kind, name: node[kind] ?? '' });
|
|
90
|
+
return REMOVED;
|
|
91
|
+
}
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return { navigation: prune(navigation, []), leftOut };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** A page address the way writedocs.json's `redirects` and a page's `slug`
|
|
99
|
+
* write it, as one key: no slashes around it, no #anchor or ?query, lower
|
|
100
|
+
* case; the root is "index". */
|
|
101
|
+
function addressKey(value) {
|
|
102
|
+
const bare = String(value).split(/[?#]/)[0].replace(/^\/+|\/+$/g, '').toLowerCase();
|
|
103
|
+
return bare === '' ? 'index' : bare;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* What `writedocs build` tells the author about the drafts it leaves out,
|
|
108
|
+
* as { warnings, notes } - warnings `{ where, message }` like the build's
|
|
109
|
+
* others, `where` a "writedocs.json:line" or the draft's own file:
|
|
110
|
+
* - each navigation entry for a draft, and each item left with no pages
|
|
111
|
+
* (withoutDrafts());
|
|
112
|
+
* - each redirect that leads to a draft - it stays, and shows "not found"
|
|
113
|
+
* until the page is published;
|
|
114
|
+
* - a draft home page - "/" goes to the navigation's first page instead.
|
|
115
|
+
* `notes` says how many drafts were left out. `configText` is
|
|
116
|
+
* writedocs.json's text (valid JSON - the build checked it first), `drafts`
|
|
117
|
+
* what findDraftPages() (lib/pages.js) gives, `locate` createJsonLocator()
|
|
118
|
+
* of that text (lib/config-schema.js). Empty without drafts.
|
|
119
|
+
*/
|
|
120
|
+
export function draftWarnings({ configText, drafts, locate }) {
|
|
121
|
+
const warnings = [];
|
|
122
|
+
const notes = [];
|
|
123
|
+
if (!drafts.length) return { warnings, notes };
|
|
124
|
+
const config = JSON.parse(configText);
|
|
125
|
+
const where = (jsonPath) => {
|
|
126
|
+
const line = locate(jsonPath)?.line;
|
|
127
|
+
return line ? `writedocs.json:${line}` : 'writedocs.json';
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const { leftOut } = withoutDrafts(config.navigation, new Set(drafts.map((draft) => fileIdForPath(draft.file))));
|
|
131
|
+
for (const entry of leftOut) {
|
|
132
|
+
const jsonPath = ['navigation', ...entry.path];
|
|
133
|
+
warnings.push({
|
|
134
|
+
where: where(jsonPath),
|
|
135
|
+
message: entry.page
|
|
136
|
+
? `${entry.page} is a draft and was left out of the navigation.`
|
|
137
|
+
: `The ${entry.kind} "${entry.name}" was left out of the navigation: every page in it is a draft.`,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const byAddress = new Map(drafts.map((draft) => [addressKey(draft.slug ?? fileIdForPath(draft.file)), draft]));
|
|
142
|
+
(Array.isArray(config.redirects) ? config.redirects : []).forEach((redirect, i) => {
|
|
143
|
+
if (typeof redirect?.destination !== 'string' || /^[a-z][a-z0-9+.-]*:|^\/\//i.test(redirect.destination)) return;
|
|
144
|
+
const draft = byAddress.get(addressKey(redirect.destination));
|
|
145
|
+
if (!draft) return;
|
|
146
|
+
warnings.push({
|
|
147
|
+
where: where(['redirects', i, 'destination']),
|
|
148
|
+
message: `The redirect from ${redirect.source} leads to ${redirect.destination}, a draft (${draft.file}) - it shows "not found" until the page is published.`,
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const home = byAddress.get('index');
|
|
153
|
+
if (home) {
|
|
154
|
+
warnings.push({
|
|
155
|
+
where: home.file,
|
|
156
|
+
message: "The home page is a draft - the site's address (/) opens the navigation's first page instead.",
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
notes.push(
|
|
161
|
+
drafts.length === 1
|
|
162
|
+
? '1 draft page (draft: true) was left out of the site - writedocs dev shows it.'
|
|
163
|
+
: `${drafts.length} draft pages (draft: true) were left out of the site - writedocs dev shows them.`
|
|
164
|
+
);
|
|
165
|
+
return { warnings, notes };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** The strip at the top of a draft page, in `writedocs dev` and `build
|
|
169
|
+
* --drafts` ([...slug].astro). Its stylesheet comes with it, inline: in the
|
|
170
|
+
* site's own CSS it would be on every site, and a site with no drafts builds
|
|
171
|
+
* byte for byte as it did before drafts existed. Left out of search's text
|
|
172
|
+
* and the page's Markdown copy. */
|
|
173
|
+
export const DRAFT_BANNER_HTML =
|
|
174
|
+
'<style>' +
|
|
175
|
+
'.wd-draft-banner{display:flex;flex-wrap:wrap;align-items:baseline;gap:.25rem .625rem;margin:0 0 1.5rem;padding:.625rem .875rem;' +
|
|
176
|
+
'border:1px dashed color-mix(in srgb,#d97706 60%,transparent);border-radius:.5rem;' +
|
|
177
|
+
'background:color-mix(in srgb,#d97706 9%,var(--wd-background));color:var(--wd-text);font-size:.875rem;line-height:1.5}' +
|
|
178
|
+
'.wd-draft-banner strong{color:#b45309;font-weight:700}' +
|
|
179
|
+
'[data-theme=dark] .wd-draft-banner strong{color:#fbbf24}' +
|
|
180
|
+
'.wd-draft-banner code{font-size:.8125rem}' +
|
|
181
|
+
'.wd-canvas>.wd-draft-banner{margin:1rem}' +
|
|
182
|
+
'</style>' +
|
|
183
|
+
'<div class="wd-draft-banner" role="note" data-pagefind-ignore data-markdown-ignore>' +
|
|
184
|
+
'<strong>Draft: not published</strong>' +
|
|
185
|
+
'<span>This page has <code>draft: true</code> - the published site leaves it out.</span>' +
|
|
186
|
+
'</div>';
|
package/src/lib/link-check.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// `writedocs broken-links`: every internal link in the content - page
|
|
2
2
|
// bodies, the snippets they import, and writedocs.json - checked against the
|
|
3
3
|
// site the build would produce, without building it. Plain JavaScript,
|
|
4
|
-
// loaded by plain Node from an installed package (see lib/icons.js's
|
|
4
|
+
// loaded by plain Node from an installed package (see packages/components/src/lib/icons.js's
|
|
5
5
|
// comment on why not TypeScript).
|
|
6
6
|
//
|
|
7
7
|
// A link is broken when, on the built site:
|
|
8
|
-
// - no page, redirect or file is at its address
|
|
8
|
+
// - no page, redirect or file is at its address - a draft page (`draft:
|
|
9
|
+
// true`) included: the build leaves drafts out;
|
|
9
10
|
// - its #anchor isn't on the target page (headings, titled components -
|
|
10
11
|
// Callout/Accordion/Update and friends - and elements with an `id`).
|
|
11
12
|
// #cookie-settings is on every page when writedocs.json turns on
|
|
@@ -29,13 +30,13 @@
|
|
|
29
30
|
//
|
|
30
31
|
// External links (http:, mailto:, ...) aren't checked.
|
|
31
32
|
import fs from 'node:fs';
|
|
32
|
-
import { estreeText } from '
|
|
33
|
+
import { estreeText } from '../../packages/components/src/lib/plain-text.js';
|
|
33
34
|
import path from 'node:path';
|
|
34
35
|
import { createRequire } from 'node:module';
|
|
35
36
|
import { pathToFileURL } from 'node:url';
|
|
36
37
|
import matter from 'gray-matter';
|
|
37
38
|
import { visit } from 'unist-util-visit';
|
|
38
|
-
import { findAllPages } from './pages.js';
|
|
39
|
+
import { findAllPages, findDraftPages } from './pages.js';
|
|
39
40
|
import { createJsonLocator, contextMenuOptions } from './config-schema.js';
|
|
40
41
|
import { writedocsTempDir } from './writedocs-temp-dir.js';
|
|
41
42
|
import { folderAddresses } from './folder-redirects.js';
|
|
@@ -302,6 +303,10 @@ export async function checkLinks(contentDir, configText) {
|
|
|
302
303
|
pages.set(url, { rel, abs, scan });
|
|
303
304
|
urlOfFile.set(rel, url);
|
|
304
305
|
}
|
|
306
|
+
// Draft pages (`draft: true`) aren't on the built site - a link to one is
|
|
307
|
+
// broken, and says why (lib/drafts.js). Their own links aren't checked:
|
|
308
|
+
// they aren't published either.
|
|
309
|
+
const drafts = new Map(findDraftPages(contentDir).map((draft) => [urlOf(draft.file, draft.slug), draft.file]));
|
|
305
310
|
const generated = generatedPageUrls(contentDir);
|
|
306
311
|
const redirects = new Set(
|
|
307
312
|
(Array.isArray(config.redirects) ? config.redirects : [])
|
|
@@ -427,6 +432,10 @@ export async function checkLinks(contentDir, configText) {
|
|
|
427
432
|
// "/" always exists: the home page, or a redirect to the first page.
|
|
428
433
|
if (pageKey === '/' || generated.has(pageKey) || redirects.has(pageKey) || folders.has(pageKey) || special.has(pageKey.replace(/\/$/, '') || '/')) return;
|
|
429
434
|
if (special.has(pathname)) return;
|
|
435
|
+
if (drafts.has(pageKey)) {
|
|
436
|
+
report(`${value} - ${pageKey} is a draft (draft: true in ${drafts.get(pageKey)}), so it isn't published.`);
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
430
439
|
|
|
431
440
|
// Mintlify-style relative link: resolved from the file's folder
|
|
432
441
|
// instead of the page's URL, would it land on a page?
|
|
@@ -3,7 +3,7 @@ import { parse as acornParse } from 'acorn';
|
|
|
3
3
|
|
|
4
4
|
// The exact same set [...slug].astro passes as the `components` prop to
|
|
5
5
|
// every page's own <Content components={components} /> call (see
|
|
6
|
-
//
|
|
6
|
+
// packages/components/src/index.ts, the barrel this imports from) - kept as one
|
|
7
7
|
// literal list rather than importing that map here, since this runs inside
|
|
8
8
|
// astro.config.mjs's markdown pipeline, a different module graph than
|
|
9
9
|
// [...slug].astro's own.
|
|
@@ -58,7 +58,7 @@ const PACKAGE_SPECIFIER = 'writedocs/components';
|
|
|
58
58
|
/**
|
|
59
59
|
* A remark plugin that auto-imports any of Writedocs' built-in components
|
|
60
60
|
* (`Callout`, `Card`, ...) a `.mdx` file uses but never itself imported -
|
|
61
|
-
* from `writedocs/components` (see
|
|
61
|
+
* from `writedocs/components` (see packages/components/src/index.ts) - so a snippet
|
|
62
62
|
* (see docs/dev/docs/snippets.mdx) gets the exact same zero-import
|
|
63
63
|
* experience a page under docs/ already has via [...slug].astro's own
|
|
64
64
|
* `components` prop. Runs on every `.mdx` file, pages included - harmless
|
|
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import crypto from 'node:crypto';
|
|
4
4
|
import { parse as acornParse } from 'acorn';
|
|
5
|
-
import { report } from '
|
|
5
|
+
import { report } from '../../packages/components/src/lib/cli-report.js';
|
|
6
6
|
import { writedocsTempDir } from './writedocs-temp-dir.js';
|
|
7
7
|
import { MINTLIFY_HOOKS } from './mdx-mintlify.js';
|
|
8
8
|
import { BUILTIN_COMPONENT_NAMES } from './mdx-inject-builtins.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { visit } from 'unist-util-visit';
|
|
2
|
-
import { estreeText } from '
|
|
2
|
+
import { estreeText } from '../../packages/components/src/lib/plain-text.js';
|
|
3
3
|
|
|
4
4
|
// Every JSX tag name that can carry a `title` prop and render a linkable
|
|
5
5
|
// heading of its own - the 6 Callout variants remarkInjectBuiltinComponents
|
|
@@ -20,7 +20,7 @@ const ANCHOR_ATTRIBUTE = { Update: 'label' };
|
|
|
20
20
|
// rather than a shared import, since this file runs inside
|
|
21
21
|
// astro.config.mjs's markdown pipeline, a different module graph than
|
|
22
22
|
// either component's own (same reasoning mdx-inject-builtins.js gives for
|
|
23
|
-
// not importing
|
|
23
|
+
// not importing packages/components/src/index.ts).
|
|
24
24
|
function slugify(value) {
|
|
25
25
|
return value
|
|
26
26
|
.toLowerCase()
|
|
@@ -2,7 +2,7 @@ import path from 'node:path';
|
|
|
2
2
|
import { visit } from 'unist-util-visit';
|
|
3
3
|
import { parse as acornParse } from 'acorn';
|
|
4
4
|
import { BUILTIN_COMPONENT_NAMES } from './mdx-inject-builtins.js';
|
|
5
|
-
import { report } from '
|
|
5
|
+
import { report } from '../../packages/components/src/lib/cli-report.js';
|
|
6
6
|
|
|
7
7
|
// Which JSX elements in an MDX file are components writedocs can't resolve
|
|
8
8
|
// - neither a built-in nor something the file imports or defines itself.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Converts a Mintlify docs.json into a writedocs.json - `writedocs convert
|
|
2
2
|
// --mintlify` (src/cli/convert.js). Plain JavaScript so the CLI can load it
|
|
3
|
-
// from an installed package (see lib/icons.js's comment).
|
|
3
|
+
// from an installed package (see packages/components/src/lib/icons.js's comment).
|
|
4
4
|
//
|
|
5
5
|
// convertMintlifyConfig() is a pure function: Mintlify config in, writedocs
|
|
6
6
|
// config plus a list of notes out. A note is anything that couldn't be
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// its `$ref`s first.
|
|
11
11
|
import fs from 'node:fs';
|
|
12
12
|
import path from 'node:path';
|
|
13
|
-
import { iconExists } from '
|
|
13
|
+
import { iconExists } from '../../packages/components/src/lib/icons.js';
|
|
14
14
|
import { readJsonText } from './config-file.js';
|
|
15
15
|
|
|
16
16
|
// ---------------------------------------------------------------------
|
|
@@ -32,7 +32,7 @@ import { planApiPages, writeGeneratedFiles } from '../cli/generate-api-pages.js'
|
|
|
32
32
|
import { collectOpenApiGroups } from './openapi-spec.js';
|
|
33
33
|
import { readConfigText } from './config-file.js';
|
|
34
34
|
import { writedocsTempDir } from './writedocs-temp-dir.js';
|
|
35
|
-
import { report } from '
|
|
35
|
+
import { report } from '../../packages/components/src/lib/cli-report.js';
|
|
36
36
|
import { readDevOpenApiState, writeDevOpenApiState, specProblem } from './openapi-dev-status.js';
|
|
37
37
|
import { contentStoreChanged } from './content-store-reload-integration.js';
|
|
38
38
|
|
package/src/lib/pages.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Which files in a content directory are pages. Plain JavaScript, not
|
|
2
2
|
// TypeScript, so `writedocs validate` can load it with plain Node (Node
|
|
3
|
-
// refuses to strip types under node_modules - see lib/icons.js's comment);
|
|
3
|
+
// refuses to strip types under node_modules - see packages/components/src/lib/icons.js's comment);
|
|
4
4
|
// lib/config.ts re-exports findAllPages() for everything inside Astro.
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import path from 'node:path';
|
|
@@ -121,10 +121,41 @@ function navigationPageIds(contentDir) {
|
|
|
121
121
|
* project is scanned once and every later call gets that list
|
|
122
122
|
* (lib/build-memo.js) - a page that scanned it again made the build N x N;
|
|
123
123
|
* everywhere else (`writedocs dev`, `validate`) every call scans afresh,
|
|
124
|
-
* so a page added or removed is seen.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
* so a page added or removed is seen.
|
|
125
|
+
*
|
|
126
|
+
* Draft pages (`draft: true`) are left out unless `drafts` is true - by
|
|
127
|
+
* default, draftsIncluded() below. This is where `writedocs build` leaves
|
|
128
|
+
* them out of the site: every route, the content collection and the
|
|
129
|
+
* sitemap start from this list (lib/drafts.js). */
|
|
130
|
+
export function findAllPages(contentDir, { drafts = draftsIncluded() } = {}) {
|
|
131
|
+
// A new list, so a caller that changes its list doesn't change everyone's.
|
|
132
|
+
return scannedPages(contentDir)
|
|
133
|
+
.filter((page) => drafts || !page.draft)
|
|
134
|
+
.map((page) => page.file);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Whether draft pages (`draft: true` - lib/drafts.js) are pages here: in
|
|
138
|
+
* `writedocs dev` and `writedocs build --drafts`, which tell the Astro
|
|
139
|
+
* process so (src/cli/run-astro.js's WRITEDOCS_COMMAND, src/cli/build.js's
|
|
140
|
+
* WRITEDOCS_DRAFTS). Everywhere else - `writedocs build`, and `writedocs
|
|
141
|
+
* broken-links`, which checks the site the build makes - a draft isn't a
|
|
142
|
+
* page. The CLI's own calls in dev, build and validate pass `drafts`
|
|
143
|
+
* instead. */
|
|
144
|
+
export function draftsIncluded(env = process.env) {
|
|
145
|
+
return env.WRITEDOCS_COMMAND === 'dev' || env.WRITEDOCS_DRAFTS === '1';
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** The draft pages findAllPages() finds (whether it leaves them out or not):
|
|
149
|
+
* `{ file, slug }` - the file's path as findAllPages() gives it, and its
|
|
150
|
+
* frontmatter `slug`, if any. */
|
|
151
|
+
export function findDraftPages(contentDir) {
|
|
152
|
+
return scannedPages(contentDir)
|
|
153
|
+
.filter((page) => page.draft)
|
|
154
|
+
.map(({ file, slug }) => ({ file, slug }));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function scannedPages(contentDir) {
|
|
158
|
+
return oncePerBuild(`pages:${contentDir}`, () => scanAllPages(contentDir));
|
|
128
159
|
}
|
|
129
160
|
|
|
130
161
|
function scanAllPages(contentDir) {
|
|
@@ -165,11 +196,14 @@ function scanAllPages(contentDir) {
|
|
|
165
196
|
// frontmatter block), so the error surfaces with this file's name -
|
|
166
197
|
// from `writedocs validate`, or Astro's own loader in the build -
|
|
167
198
|
// instead of as a bare YAML error thrown from here.
|
|
168
|
-
if (/^---\r?\n/.test(raw)) results.push(rel);
|
|
199
|
+
if (/^---\r?\n/.test(raw)) results.push({ file: rel, draft: false });
|
|
169
200
|
continue;
|
|
170
201
|
}
|
|
171
202
|
if (Object.keys(data).length === 0 && !listed.has(fileIdForPath(rel))) continue; // not a page
|
|
172
|
-
|
|
203
|
+
// Only `draft: true` - `draft: "yes"` stays a page, and the schema
|
|
204
|
+
// rejects it.
|
|
205
|
+
const draft = data.draft === true;
|
|
206
|
+
results.push({ file: rel, draft, slug: draft && typeof data.slug === 'string' ? data.slug : undefined });
|
|
173
207
|
}
|
|
174
208
|
}
|
|
175
209
|
walk(contentDir, '');
|
|
@@ -25,7 +25,7 @@ import { findPublishedFiles, readSpecPaths } from './project-files.js';
|
|
|
25
25
|
import { projectIgnore } from './project-ignore.js';
|
|
26
26
|
import { robotsTxt } from './robots-txt.js';
|
|
27
27
|
import { isNoindex } from './seo-tags.js';
|
|
28
|
-
import { report } from '
|
|
28
|
+
import { report } from '../../packages/components/src/lib/cli-report.js';
|
|
29
29
|
|
|
30
30
|
/** Every file under `dir`, as POSIX paths from it. */
|
|
31
31
|
function listFiles(dir, relBase = '') {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// .md page (`raw`), and HTML tags written in MDX (`mdxJsx*` with a lowercase
|
|
10
10
|
// name) - their href, src, srcset, poster and action. Not a component's
|
|
11
11
|
// props (`<Card href="/a">`): a component writes its own addresses, with
|
|
12
|
-
// siteHref() (lib/site-base.ts), so prefixing here too would give them the
|
|
12
|
+
// siteHref() (the components package's lib/site-base.ts), so prefixing here too would give them the
|
|
13
13
|
// base twice. Not a value written as an expression (`href={link}`), which
|
|
14
14
|
// isn't known until the page runs.
|
|
15
15
|
//
|
package/src/lib/seo-tags.js
CHANGED
|
@@ -27,8 +27,10 @@ export function isNoindex(seo) {
|
|
|
27
27
|
|
|
28
28
|
/** A page's frontmatter as gray-matter read it - before the schema folds
|
|
29
29
|
* Mintlify's top-level `noindex`/`robots` into `seo`, and marks a `hidden`
|
|
30
|
-
* page noindex. Used where pages aren't loaded yet (astro.config.mjs).
|
|
30
|
+
* page noindex. Used where pages aren't loaded yet (astro.config.mjs). A
|
|
31
|
+
* draft is noindex whatever else it says, as in the schema. */
|
|
31
32
|
export function frontmatterNoindex(data) {
|
|
33
|
+
if (data?.draft === true) return true;
|
|
32
34
|
const robots = data?.seo?.robots ?? data?.robots;
|
|
33
35
|
if (typeof robots === 'string') return isNoindex({ robots });
|
|
34
36
|
return (data?.seo?.noindex ?? data?.noindex ?? data?.hidden === true) === true;
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import fs from 'node:fs';
|
|
18
18
|
import path from 'node:path';
|
|
19
19
|
import matter from 'gray-matter';
|
|
20
|
-
import { iconExists } from '
|
|
20
|
+
import { iconExists } from '../../packages/components/src/lib/icons.js';
|
|
21
21
|
import { readJsonText } from './config-file.js';
|
|
22
22
|
import { fileIdForPath } from './pages.js';
|
|
23
23
|
import { Notes, LANGUAGE_NAMES } from './mintlify-convert.js';
|
package/src/pages/404.astro
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// non-dynamic page at its literal path).
|
|
10
10
|
import { loadDocsConfig } from '../lib/config';
|
|
11
11
|
import BaseLayout from '../layout/BaseLayout.astro';
|
|
12
|
-
import { siteHref } from '
|
|
12
|
+
import { siteHref } from '../../packages/components/src/lib/site-base';
|
|
13
13
|
|
|
14
14
|
const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
|
|
15
15
|
const config = loadDocsConfig(contentDir);
|