@writedocs/generator 0.16.0 → 0.17.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 +8 -2
- package/package.json +1 -1
- package/src/cli/build.js +38 -3
- package/src/cli/dev.js +16 -0
- package/src/cli/run-pagefind.js +24 -11
- package/src/cli/write-redirects-file.js +5 -1
- package/src/layout/components/LockMark.astro +28 -0
- package/src/layout/components/MobileMenu.astro +4 -0
- package/src/layout/components/Sidebar.astro +3 -2
- package/src/layout/components/TopBar.astro +9 -0
- package/src/lib/config-schema.js +41 -3
- package/src/lib/config-schema.ts +59 -6
- package/src/lib/config.ts +23 -11
- package/src/lib/content-check.js +18 -3
- package/src/lib/json-schema-descriptions.js +3 -1
- package/src/lib/llms-index.ts +5 -0
- package/src/lib/mcp-index.ts +5 -1
- package/src/lib/protected-sections.js +238 -0
- package/src/pages/[...slug].astro +53 -14
- package/src/pages/llms-full.txt.ts +4 -0
- package/src/pages/og/[...slug].png.ts +11 -2
- package/writedocs.schema.json +455 -70
package/astro.config.mjs
CHANGED
|
@@ -44,6 +44,8 @@ import { rehypeImageLoading } from './src/lib/rehype-image-loading.js';
|
|
|
44
44
|
import { rehypeBasePath } from './src/lib/rehype-base-path.js';
|
|
45
45
|
import { gitLastModified, newestDate } from './src/lib/last-modified.js';
|
|
46
46
|
import { readSpecPaths } from './src/lib/project-files.js';
|
|
47
|
+
import { protectedPages } from './src/lib/protected-sections.js';
|
|
48
|
+
import { fileIdForPath } from './src/lib/pages.js';
|
|
47
49
|
import {
|
|
48
50
|
loadDocsConfig,
|
|
49
51
|
resolveCodeblockTheme,
|
|
@@ -166,6 +168,9 @@ function collectNoindexIds(rootContentDir) {
|
|
|
166
168
|
const pageIds = [];
|
|
167
169
|
// When each page last changed, for <lastmod> - see lib/last-modified.js.
|
|
168
170
|
const fileDates = gitLastModified(rootContentDir);
|
|
171
|
+
// A protected page (lib/protected-sections.js) is noindex, whatever its
|
|
172
|
+
// frontmatter says - and never listed in a public file.
|
|
173
|
+
const protectedRules = protectedPages(docsConfig.navigation);
|
|
169
174
|
|
|
170
175
|
for (const relativeId of findAllPages(rootContentDir)) {
|
|
171
176
|
const file = path.join(rootContentDir, relativeId);
|
|
@@ -183,7 +188,8 @@ function collectNoindexIds(rootContentDir) {
|
|
|
183
188
|
// canonical URL is another address (the sitemap lists canonical ones).
|
|
184
189
|
const canonical = data?.seo?.canonical ?? data?.canonical;
|
|
185
190
|
const pagePath = pageId === 'index' ? '/' : `/${pageId}/`;
|
|
186
|
-
|
|
191
|
+
const isProtected = protectedRules.has(fileIdForPath(relativeId));
|
|
192
|
+
if (!isProtected && !frontmatterNoindex(data) && !data?.url && !canonicalIsElsewhere(siteUrl, pagePath, canonical)) continue;
|
|
187
193
|
ids.add(pageId);
|
|
188
194
|
}
|
|
189
195
|
// Generated OpenAPI stub pages always set an explicit `slug` (see
|
|
@@ -197,7 +203,7 @@ function collectNoindexIds(rootContentDir) {
|
|
|
197
203
|
// A generated API page changes when a spec does. Which spec it came
|
|
198
204
|
// from isn't recorded on the page, so it gets the newest of them.
|
|
199
205
|
if (data?.slug && specsChanged) lastModifiedById.set(normalizeEntryId(data.slug), specsChanged);
|
|
200
|
-
if (frontmatterNoindex(data) && data.slug) ids.add(normalizeEntryId(data.slug));
|
|
206
|
+
if ((frontmatterNoindex(data) || protectedRules.has(normalizeEntryId(data?.slug ?? ''))) && data.slug) ids.add(normalizeEntryId(data.slug));
|
|
201
207
|
}
|
|
202
208
|
if (!rootIsPage) ids.add('index');
|
|
203
209
|
// Folder addresses with no page of their own redirect to one under them
|
package/package.json
CHANGED
package/src/cli/build.js
CHANGED
|
@@ -20,6 +20,7 @@ import { reportApiPages } from './api-pages-output.js';
|
|
|
20
20
|
import { findDraftPages } from '../lib/pages.js';
|
|
21
21
|
import { draftWarnings } from '../lib/drafts.js';
|
|
22
22
|
import { createJsonLocator } from '../lib/config-schema.js';
|
|
23
|
+
import { usesAccess, accessRules, accessMap, ACCESS_MAP_FILE, ACCESS_NEEDS_PLATFORM } from '../lib/protected-sections.js';
|
|
23
24
|
|
|
24
25
|
/** `drafts` (`writedocs build --drafts`): draft pages are part of the site -
|
|
25
26
|
* marked, noindex, out of the sitemap, llms.txt and the MCP index, the way
|
|
@@ -72,12 +73,17 @@ export async function runBuild({ contentDir, packageRoot, verbose = false, draft
|
|
|
72
73
|
const ogCardsFile = path.join(writedocsTempDir(contentDir), 'og-cards.json');
|
|
73
74
|
fs.mkdirSync(path.dirname(ogCardsFile), { recursive: true });
|
|
74
75
|
fs.rmSync(ogCardsFile, { force: true });
|
|
76
|
+
// The protected addresses ([...slug].astro lists them here, as
|
|
77
|
+
// `{ slug, rule }` - lib/protected-sections.js). Removed first for the same
|
|
78
|
+
// reason.
|
|
79
|
+
const accessFile = path.join(writedocsTempDir(contentDir), 'access-routes.json');
|
|
80
|
+
fs.rmSync(accessFile, { force: true });
|
|
75
81
|
const { exited } = runAstro('build', {
|
|
76
82
|
packageRoot,
|
|
77
83
|
contentDir,
|
|
78
84
|
// WRITEDOCS_DRAFTS: draftsIncluded() in lib/pages.js - set either way, so
|
|
79
85
|
// one left in the shell's environment can't decide it.
|
|
80
|
-
env: { WRITEDOCS_OG_CARDS_FILE: ogCardsFile, WRITEDOCS_DRAFTS: drafts ? '1' : '' },
|
|
86
|
+
env: { WRITEDOCS_OG_CARDS_FILE: ogCardsFile, WRITEDOCS_ACCESS_FILE: accessFile, WRITEDOCS_DRAFTS: drafts ? '1' : '' },
|
|
81
87
|
onEvent(event) {
|
|
82
88
|
if (verbose) {
|
|
83
89
|
const line = verboseLine(event);
|
|
@@ -136,6 +142,10 @@ export async function runBuild({ contentDir, packageRoot, verbose = false, draft
|
|
|
136
142
|
// Without one, siteDir is distDir, and every step below is what it was.
|
|
137
143
|
const basePath = normalizeBasePath(siteConfig.basePath);
|
|
138
144
|
const siteDir = siteDirFor(distDir, basePath);
|
|
145
|
+
// Protected sections are protected by the WriteDocs platform only
|
|
146
|
+
// (lib/protected-sections.js) - said every time, so nobody hosting the
|
|
147
|
+
// build elsewhere takes them for private.
|
|
148
|
+
if (usesAccess(siteConfig.navigation)) addWarning(null, ACCESS_NEEDS_PLATFORM);
|
|
139
149
|
// Astro just wrote its actual output to writedocsBuildStagingDir()
|
|
140
150
|
// (astro.config.mjs's own `outDir`), not distDir directly - see that
|
|
141
151
|
// function's own comment (writedocs-temp-dir.js) for why. fs.cpSync
|
|
@@ -185,7 +195,11 @@ export async function runBuild({ contentDir, packageRoot, verbose = false, draft
|
|
|
185
195
|
// ever produce client-side meta-refresh pages (see write-redirects-file.js)
|
|
186
196
|
// - this turns those into real instant edge redirects on hosts that read
|
|
187
197
|
// a `_redirects` file (Cloudflare Pages, Netlify), purely additively.
|
|
188
|
-
|
|
198
|
+
// A folder redirect that leads to a protected page stays a page, behind
|
|
199
|
+
// its rule - not an edge redirect anyone can follow.
|
|
200
|
+
const protectedRoutes = fs.existsSync(accessFile) ? JSON.parse(fs.readFileSync(accessFile, 'utf8')) : [];
|
|
201
|
+
const protectedFolders = new Set(protectedRoutes.map((route) => `/${route.slug}/`));
|
|
202
|
+
writeRedirectsFile(siteDir, contentDir, { outDir: distDir, basePath, protectedFolders });
|
|
189
203
|
// Every other host follows Astro's redirect pages - rewritten so the
|
|
190
204
|
// reader never sees one (rewrite-redirect-pages.js).
|
|
191
205
|
rewriteRedirectPages(siteDir, { background: siteConfig.styles?.background?.colors, appearance: siteConfig.styles?.appearance });
|
|
@@ -198,8 +212,9 @@ export async function runBuild({ contentDir, packageRoot, verbose = false, draft
|
|
|
198
212
|
if (mcp.skipped) addWarning(null, `No _worker.js for the MCP server: ${mcp.skipped}.`);
|
|
199
213
|
|
|
200
214
|
const indexing = step('Indexing search');
|
|
215
|
+
let searchSpaces = [];
|
|
201
216
|
try {
|
|
202
|
-
await runPagefind(siteDir, { packageRoot });
|
|
217
|
+
({ spaces: searchSpaces } = await runPagefind(siteDir, { packageRoot }));
|
|
203
218
|
} catch (err) {
|
|
204
219
|
indexing.fail('Search indexing failed');
|
|
205
220
|
log.line();
|
|
@@ -208,6 +223,26 @@ export async function runBuild({ contentDir, packageRoot, verbose = false, draft
|
|
|
208
223
|
}
|
|
209
224
|
indexing.succeed('Indexed search');
|
|
210
225
|
|
|
226
|
+
// The map the WriteDocs platform protects the site by: each access rule
|
|
227
|
+
// and every path it serves only to the rule's readers
|
|
228
|
+
// (lib/protected-sections.js, docs/dev/docs/protected-sections.mdx). At
|
|
229
|
+
// the root of dist/, outside a basePath's folder - the platform never
|
|
230
|
+
// serves /.writedocs/. Without `access` in writedocs.json, no file, and
|
|
231
|
+
// dist/ is what it was.
|
|
232
|
+
if (usesAccess(siteConfig.navigation)) {
|
|
233
|
+
const map = accessMap({
|
|
234
|
+
rules: accessRules(siteConfig.navigation),
|
|
235
|
+
routes: protectedRoutes,
|
|
236
|
+
spaces: searchSpaces,
|
|
237
|
+
basePath,
|
|
238
|
+
exists: (rel) => fs.existsSync(path.join(siteDir, ...rel.split('/'))),
|
|
239
|
+
});
|
|
240
|
+
const mapFile = path.join(distDir, ...ACCESS_MAP_FILE.split('/'));
|
|
241
|
+
fs.mkdirSync(path.dirname(mapFile), { recursive: true });
|
|
242
|
+
fs.writeFileSync(mapFile, `${JSON.stringify(map, null, 2)}
|
|
243
|
+
`);
|
|
244
|
+
}
|
|
245
|
+
|
|
211
246
|
if (warnings.length) {
|
|
212
247
|
log.line();
|
|
213
248
|
log.warn(plural(warnings.length, 'warning'));
|
package/src/cli/dev.js
CHANGED
|
@@ -10,6 +10,7 @@ import { showUpdateNotice } from './update-check.js';
|
|
|
10
10
|
import { shouldOpenBrowser, openBrowser } from './open-browser.js';
|
|
11
11
|
import { watchPageList } from './page-list-watch.js';
|
|
12
12
|
import { readConfigText } from '../lib/config-file.js';
|
|
13
|
+
import { usesAccess, ACCESS_IN_DEV } from '../lib/protected-sections.js';
|
|
13
14
|
import { normalizeBasePath } from '../lib/base-path.js';
|
|
14
15
|
import { writeDevOpenApiState } from '../lib/openapi-dev-status.js';
|
|
15
16
|
|
|
@@ -143,6 +144,12 @@ export async function runDev({ contentDir, packageRoot, port, verbose = false, o
|
|
|
143
144
|
log.line();
|
|
144
145
|
log.line(color.dim(' Edit any page and the preview updates. Press Ctrl+C to stop.'));
|
|
145
146
|
log.line();
|
|
147
|
+
// Protected sections (lib/protected-sections.js) are the
|
|
148
|
+
// platform's to protect - here every page opens.
|
|
149
|
+
if (configUsesAccess(contentDir)) {
|
|
150
|
+
log.info(ACCESS_IN_DEV);
|
|
151
|
+
log.line();
|
|
152
|
+
}
|
|
146
153
|
// `dev` runs until Ctrl+C - the notice goes under the ready screen,
|
|
147
154
|
// not after the command like everywhere else.
|
|
148
155
|
showUpdateNotice();
|
|
@@ -267,3 +274,12 @@ export async function runDev({ contentDir, packageRoot, port, verbose = false, o
|
|
|
267
274
|
}
|
|
268
275
|
throw new CliExit(code || 1);
|
|
269
276
|
}
|
|
277
|
+
|
|
278
|
+
/** Whether writedocs.json names an access rule - false when it can't be read. */
|
|
279
|
+
function configUsesAccess(contentDir) {
|
|
280
|
+
try {
|
|
281
|
+
return usesAccess(JSON.parse(readConfigText(contentDir)).navigation);
|
|
282
|
+
} catch {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
}
|
package/src/cli/run-pagefind.js
CHANGED
|
@@ -60,19 +60,30 @@ function resolvePagefindBin(packageRoot) {
|
|
|
60
60
|
* result (/docs/pagefind/ -> "/docs/a/"). Adding the base here too gave
|
|
61
61
|
* results with it twice.
|
|
62
62
|
*/
|
|
63
|
+
/**
|
|
64
|
+
* Returns the ids of the search spaces it wrote, each in
|
|
65
|
+
* pagefind-spaces/<id>/ - the build lists a protected one's folder in
|
|
66
|
+
* dist/.writedocs/access.json (lib/protected-sections.js).
|
|
67
|
+
*/
|
|
63
68
|
export async function runPagefind(siteDir, { packageRoot }) {
|
|
64
69
|
const groups = searchSpaces(siteDir);
|
|
65
|
-
if (groups)
|
|
66
|
-
|
|
70
|
+
if (groups) {
|
|
71
|
+
await indexBySpace(siteDir, packageRoot, groups);
|
|
72
|
+
return { spaces: [...groups.spaces.keys()] };
|
|
73
|
+
}
|
|
74
|
+
await indexWholeSite(siteDir, packageRoot);
|
|
75
|
+
return { spaces: [] };
|
|
67
76
|
}
|
|
68
77
|
|
|
69
|
-
// Pages under a hidden navigation item name their search
|
|
70
|
-
// markup ([...slug].astro, lib/hidden-sections.js
|
|
78
|
+
// Pages under a hidden or a protected navigation item name their search
|
|
79
|
+
// space in their markup ([...slug].astro, lib/hidden-sections.js,
|
|
80
|
+
// lib/protected-sections.js).
|
|
71
81
|
const SPACE = /data-wd-search-space="([^"]+)"/;
|
|
72
82
|
const SEARCH_PUBLIC = /data-wd-search-public="true"/;
|
|
73
83
|
|
|
74
84
|
/** The site's pages by search space - `{ public, spaces }` - or null when
|
|
75
|
-
* no page is in a hidden space (the whole site is one index,
|
|
85
|
+
* no page is in a hidden or protected space (the whole site is one index,
|
|
86
|
+
* as ever).
|
|
76
87
|
* Only pages Pagefind would index: those with a data-pagefind-body. A
|
|
77
88
|
* page is `{ rel }`, its path in the site with forward slashes.
|
|
78
89
|
* Exported for scripts/search-spaces.test.js. */
|
|
@@ -109,11 +120,13 @@ export function searchSpaces(siteDir) {
|
|
|
109
120
|
return spaces.size ? { public: publicPages, spaces } : null;
|
|
110
121
|
}
|
|
111
122
|
|
|
112
|
-
/** One index for the public pages (dist/pagefind/) and one per hidden
|
|
113
|
-
* space (dist/pagefind-spaces/<id>/) - so the public search never
|
|
114
|
-
* hidden page, and a
|
|
115
|
-
* the public ones when it sets `searchPublic`.
|
|
116
|
-
*
|
|
123
|
+
/** One index for the public pages (dist/pagefind/) and one per hidden or
|
|
124
|
+
* protected space (dist/pagefind-spaces/<id>/) - so the public search never
|
|
125
|
+
* finds a hidden or protected page, and a space's search finds only its own
|
|
126
|
+
* pages, plus the public ones when it sets `searchPublic`. A protected
|
|
127
|
+
* space holds one access rule's pages only (searchSpaceOf() in
|
|
128
|
+
* lib/protected-sections.js), so its folder is behind that rule.
|
|
129
|
+
* src/scripts/search.ts loads the index of the page's space. */
|
|
117
130
|
async function indexBySpace(siteDir, packageRoot, groups) {
|
|
118
131
|
const pagefind = await import(pathToFileURL(path.join(findPagefindDir(packageRoot), 'lib', 'index.js')).href);
|
|
119
132
|
const check = (result, what) => {
|
|
@@ -129,7 +142,7 @@ async function indexBySpace(siteDir, packageRoot, groups) {
|
|
|
129
142
|
await write(groups.public, path.join(siteDir, 'pagefind'), 'public pages');
|
|
130
143
|
for (const [id, space] of groups.spaces) {
|
|
131
144
|
const pages = space.searchPublic ? [...space.pages, ...groups.public] : space.pages;
|
|
132
|
-
await write(pages, path.join(siteDir, 'pagefind-spaces', id), `
|
|
145
|
+
await write(pages, path.join(siteDir, 'pagefind-spaces', id), `search space ${id}`);
|
|
133
146
|
}
|
|
134
147
|
} finally {
|
|
135
148
|
await pagefind.close();
|
|
@@ -41,7 +41,10 @@ import { withBase } from '../lib/base-path.js';
|
|
|
41
41
|
// the rules name, source and destination - the host matches the full path
|
|
42
42
|
// it was asked for - and adds `/ -> /docs/` for whoever opens the root of
|
|
43
43
|
// the address directly.
|
|
44
|
-
|
|
44
|
+
/** `protectedFolders` - folder addresses ("/partners/") whose redirect leads
|
|
45
|
+
* to a protected page (lib/protected-sections.js): left out here, so the
|
|
46
|
+
* redirect stays a page behind the page's access rule. */
|
|
47
|
+
export function writeRedirectsFile(distDir, contentDir, { outDir = distDir, basePath = '', protectedFolders = new Set() } = {}) {
|
|
45
48
|
const writedocsJson = JSON.parse(readConfigText(contentDir));
|
|
46
49
|
const redirects = writedocsJson.redirects ?? [];
|
|
47
50
|
const lines = [];
|
|
@@ -100,6 +103,7 @@ export function writeRedirectsFile(distDir, contentDir, { outDir = distDir, base
|
|
|
100
103
|
// automatic folder redirects. (Read before rewrite-redirect-pages.js makes
|
|
101
104
|
// every redirect page go at once.)
|
|
102
105
|
for (const { url, target } of temporaryRedirectPages(distDir)) {
|
|
106
|
+
if (protectedFolders.has(url)) continue;
|
|
103
107
|
lines.push(`${at(url)} ${target} 302`, `${at(url).replace(/\/$/, '')} ${target} 302`);
|
|
104
108
|
}
|
|
105
109
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
// The padlock beside a protected navigation item's name - one with
|
|
3
|
+
// `"lock": true` next to its `access` rule (lib/protected-sections.js) -
|
|
4
|
+
// wherever the item is listed: the tabs, a tab's menu, the switchers in the
|
|
5
|
+
// top bar and the sidebar, and the mobile menu. Renders nothing otherwise.
|
|
6
|
+
//
|
|
7
|
+
// Lucide's "lock", the icon set the generator already has, drawn inline with
|
|
8
|
+
// its size in a style attribute - a rule in the site's stylesheet would be on
|
|
9
|
+
// every site, and a site without `access` builds byte for byte as it did
|
|
10
|
+
// before. role="img" and aria-label put "Requires sign-in" in the link's
|
|
11
|
+
// accessible name; <title> shows it on hover.
|
|
12
|
+
import { iconSvg } from '../../lib/config';
|
|
13
|
+
|
|
14
|
+
interface Props {
|
|
15
|
+
locked?: boolean;
|
|
16
|
+
// Inside a line of text rather than a flex row with its own gap: a space
|
|
17
|
+
// before it.
|
|
18
|
+
inline?: boolean;
|
|
19
|
+
}
|
|
20
|
+
const LABEL = 'Requires sign-in';
|
|
21
|
+
const svg = Astro.props.locked ? iconSvg('lock') : null;
|
|
22
|
+
const margin = Astro.props.inline ? 'margin-inline-start:.35em;' : '';
|
|
23
|
+
const html = svg?.replace(
|
|
24
|
+
/^<svg ([^>]*)>/,
|
|
25
|
+
`<svg $1 class="wd-lock" role="img" aria-label="${LABEL}" width="12" height="12" style="${margin}width:.8em;height:.8em;flex-shrink:0;opacity:.7;vertical-align:-.05em"><title>${LABEL}</title>`
|
|
26
|
+
);
|
|
27
|
+
---
|
|
28
|
+
{html && <Fragment set:html={html} />}
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
// several unrelated concerns in one file - see that component's own
|
|
30
30
|
// comment for the fuller rationale.
|
|
31
31
|
import { isExternalHref, type DocsConfig, type Selector, type GlobalDropdownView } from '../../lib/config';
|
|
32
|
+
import LockMark from './LockMark.astro';
|
|
32
33
|
import AppIcon from '../../../packages/components/src/components/AppIcon.astro';
|
|
33
34
|
import { logoWidth } from '../../lib/image-size.js';
|
|
34
35
|
import { showsThemeToggle } from '../../lib/appearance.js';
|
|
@@ -121,6 +122,7 @@ const showMenu = hasMobileMenu({ sidebar: showSidebarCol, selectors, globalDropd
|
|
|
121
122
|
>
|
|
122
123
|
<AppIcon icon={opt.icon} class="wd-tab-icon" />
|
|
123
124
|
<span class="wd-mobile-accordion-option-label">{opt.label}</span>
|
|
125
|
+
<LockMark locked={opt.locked} />
|
|
124
126
|
{opt.tag && <span class="wd-selector-tag">{opt.tag}</span>}
|
|
125
127
|
</a>
|
|
126
128
|
))}
|
|
@@ -133,6 +135,7 @@ const showMenu = hasMobileMenu({ sidebar: showSidebarCol, selectors, globalDropd
|
|
|
133
135
|
<summary class="wd-mobile-accordion-trigger">
|
|
134
136
|
<AppIcon icon={current.icon} class="wd-tab-icon" />
|
|
135
137
|
<span class="wd-mobile-accordion-label">{current.label}</span>
|
|
138
|
+
<LockMark locked={(current as { locked?: boolean }).locked} />
|
|
136
139
|
{current.tag && <span class="wd-selector-tag">{current.tag}</span>}
|
|
137
140
|
<svg class="wd-mobile-accordion-caret" width="12" height="12" viewBox="0 0 10 10" aria-hidden="true">
|
|
138
141
|
<path d="M2 3.5L5 6.5L8 3.5" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
|
|
@@ -149,6 +152,7 @@ const showMenu = hasMobileMenu({ sidebar: showSidebarCol, selectors, globalDropd
|
|
|
149
152
|
>
|
|
150
153
|
<AppIcon icon={opt.icon} class="wd-tab-icon" />
|
|
151
154
|
<span class="wd-mobile-accordion-option-label">{opt.label}</span>
|
|
155
|
+
<LockMark locked={opt.locked} />
|
|
152
156
|
{opt.tag && <span class="wd-selector-tag">{opt.tag}</span>}
|
|
153
157
|
{opt.active && (
|
|
154
158
|
<svg class="wd-mobile-accordion-check" width="14" height="14" viewBox="0 0 14 14" aria-hidden="true">
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { isExternalHref, type NavTreeNode, type Selector } from "../../lib/config";
|
|
3
3
|
import NavTree from "./NavTree.astro";
|
|
4
4
|
import { currentOption } from "../../lib/selector-placement.js";
|
|
5
|
+
import LockMark from "./LockMark.astro";
|
|
5
6
|
import AppIcon from "../../../packages/components/src/components/AppIcon.astro";
|
|
6
7
|
// Two colorways of the same "Powered by writedocs" mark, not a
|
|
7
8
|
// theme-matched pair in the wd-logo-light/wd-logo-dark sense (that
|
|
@@ -50,7 +51,7 @@ const { navTree, hrefForSlug, currentSlug, switchers = [] } = Astro.props as Pro
|
|
|
50
51
|
<button type="button" class="wd-dropdown-trigger wd-sidebar-switcher-trigger" aria-expanded="false">
|
|
51
52
|
<AppIcon icon={current.icon} class="wd-tab-icon wd-sidebar-switcher-icon" />
|
|
52
53
|
<span class="wd-sidebar-switcher-text">
|
|
53
|
-
<span class="wd-sidebar-switcher-label">{current.label}
|
|
54
|
+
<span class="wd-sidebar-switcher-label">{current.label}<LockMark locked={(current as { locked?: boolean }).locked} inline /></span>
|
|
54
55
|
{current.description && <span class="wd-sidebar-switcher-desc">{current.description}</span>}
|
|
55
56
|
</span>
|
|
56
57
|
<svg class="wd-sidebar-switcher-chevrons" width="12" height="12" viewBox="0 0 12 12" aria-hidden="true">
|
|
@@ -69,7 +70,7 @@ const { navTree, hrefForSlug, currentSlug, switchers = [] } = Astro.props as Pro
|
|
|
69
70
|
>
|
|
70
71
|
<AppIcon icon={opt.icon} class="wd-tab-icon wd-sidebar-switcher-icon" />
|
|
71
72
|
<span class="wd-sidebar-switcher-text">
|
|
72
|
-
<span class="wd-sidebar-switcher-label">{opt.label}
|
|
73
|
+
<span class="wd-sidebar-switcher-label">{opt.label}<LockMark locked={opt.locked} inline /></span>
|
|
73
74
|
{opt.description && <span class="wd-sidebar-switcher-desc">{opt.description}</span>}
|
|
74
75
|
</span>
|
|
75
76
|
</a>
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
// comment for the fuller rationale.
|
|
14
14
|
import { isExternalHref, type DocsConfig, type Selector, type GlobalDropdownView } from '../../lib/config';
|
|
15
15
|
import AppIcon from '../../../packages/components/src/components/AppIcon.astro';
|
|
16
|
+
import LockMark from './LockMark.astro';
|
|
16
17
|
import { logoWidth } from '../../lib/image-size.js';
|
|
17
18
|
import { showsThemeToggle } from '../../lib/appearance.js';
|
|
18
19
|
import { selectorPlacements, hasMobileMenu, currentOption } from '../../lib/selector-placement.js';
|
|
@@ -114,6 +115,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
|
|
|
114
115
|
<button type="button" class="wd-dropdown-trigger wd-switcher-trigger" aria-expanded="false">
|
|
115
116
|
<AppIcon icon={current.icon} class="wd-tab-icon" />
|
|
116
117
|
{current.label}
|
|
118
|
+
<LockMark locked={(current as { locked?: boolean }).locked} />
|
|
117
119
|
{current.tag && <span class="wd-selector-tag">{current.tag}</span>}
|
|
118
120
|
<svg class="wd-dropdown-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
|
|
119
121
|
<path d="M2 3.5L5 6.5L8 3.5" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
|
|
@@ -130,6 +132,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
|
|
|
130
132
|
>
|
|
131
133
|
<AppIcon icon={opt.icon} class="wd-tab-icon" />
|
|
132
134
|
{opt.label}
|
|
135
|
+
<LockMark locked={opt.locked} />
|
|
133
136
|
{opt.tag && <span class="wd-selector-tag">{opt.tag}</span>}
|
|
134
137
|
</a>
|
|
135
138
|
))}
|
|
@@ -249,6 +252,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
|
|
|
249
252
|
>
|
|
250
253
|
<AppIcon icon={opt.icon} class="wd-tab-icon" />
|
|
251
254
|
{opt.label}
|
|
255
|
+
<LockMark locked={opt.locked} />
|
|
252
256
|
<svg class="wd-dropdown-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
|
|
253
257
|
<path d="M2 3.5L5 6.5L8 3.5" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
|
|
254
258
|
</svg>
|
|
@@ -267,6 +271,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
|
|
|
267
271
|
<a href={siteHref(d.pageHref)} class={`wd-submenu-entry ${d.active ? 'active' : ''}`} aria-current={d.active ? 'true' : undefined}>
|
|
268
272
|
<AppIcon icon={d.icon} class="wd-tab-icon" />
|
|
269
273
|
<span class="wd-submenu-label">{d.label}</span>
|
|
274
|
+
<LockMark locked={d.locked} />
|
|
270
275
|
</a>
|
|
271
276
|
) : null}
|
|
272
277
|
<button
|
|
@@ -277,6 +282,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
|
|
|
277
282
|
>
|
|
278
283
|
{!d.pageHref && <AppIcon icon={d.icon} class="wd-tab-icon" />}
|
|
279
284
|
{!d.pageHref && <span class="wd-submenu-label">{d.label}</span>}
|
|
285
|
+
{!d.pageHref && <LockMark locked={d.locked} />}
|
|
280
286
|
<svg class="wd-submenu-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
|
|
281
287
|
<path d="M3.5 2L6.5 5L3.5 8" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
|
|
282
288
|
</svg>
|
|
@@ -298,6 +304,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
|
|
|
298
304
|
>
|
|
299
305
|
<AppIcon icon={sub.icon} class="wd-tab-icon" />
|
|
300
306
|
{sub.label}
|
|
307
|
+
<LockMark locked={sub.locked} />
|
|
301
308
|
</a>
|
|
302
309
|
))}
|
|
303
310
|
</div>
|
|
@@ -312,6 +319,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
|
|
|
312
319
|
>
|
|
313
320
|
<AppIcon icon={d.icon} class="wd-tab-icon" />
|
|
314
321
|
{d.label}
|
|
322
|
+
<LockMark locked={d.locked} />
|
|
315
323
|
</a>
|
|
316
324
|
)
|
|
317
325
|
)}
|
|
@@ -328,6 +336,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
|
|
|
328
336
|
>
|
|
329
337
|
<AppIcon icon={opt.icon} class="wd-tab-icon" />
|
|
330
338
|
{opt.label}
|
|
339
|
+
<LockMark locked={opt.locked} />
|
|
331
340
|
</a>
|
|
332
341
|
)
|
|
333
342
|
)}
|
package/src/lib/config-schema.js
CHANGED
|
@@ -34,8 +34,17 @@ const navLinkSchema = z.object({ label: z.string(), href: z.string() }).strict()
|
|
|
34
34
|
const navItemSchema = z.lazy(
|
|
35
35
|
() => z.union([navPageSchema, navGroupSchema, navLinkSchema])
|
|
36
36
|
);
|
|
37
|
+
const ACCESS_RULE_NAME = /^[a-z0-9-]{1,40}$/;
|
|
38
|
+
const accessSchema = z.string().regex(ACCESS_RULE_NAME, `An access rule's name is 1 to 40 lowercase letters, numbers and hyphens, like "partners".`);
|
|
37
39
|
function withChildren(ownFields) {
|
|
38
|
-
const base = {
|
|
40
|
+
const base = {
|
|
41
|
+
...ownFields,
|
|
42
|
+
hidden: z.boolean().optional(),
|
|
43
|
+
searchPublic: z.boolean().optional(),
|
|
44
|
+
page: z.string().optional(),
|
|
45
|
+
access: accessSchema.optional(),
|
|
46
|
+
lock: z.boolean().optional()
|
|
47
|
+
};
|
|
39
48
|
return z.union([
|
|
40
49
|
z.object({ ...base, pages: z.array(navItemSchema) }).strict(),
|
|
41
50
|
z.object({ ...base, tabs: z.array(tabSchema).min(1) }).strict(),
|
|
@@ -118,11 +127,25 @@ const navigationSchema = z.union([
|
|
|
118
127
|
message: "An item with `href` is a link, so it has no page of its own - remove `page`, or `href`."
|
|
119
128
|
});
|
|
120
129
|
}
|
|
121
|
-
if (own2?.
|
|
130
|
+
if (own2?.access !== void 0 && own2.href !== void 0) {
|
|
131
|
+
ctx.addIssue({
|
|
132
|
+
code: "custom",
|
|
133
|
+
path: [...path, key, i, "access"],
|
|
134
|
+
message: "An item with `href` is a link, so it has no pages to protect - remove `access`, or `href`."
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (own2?.searchPublic === true && own2.hidden !== true && own2.access === void 0) {
|
|
122
138
|
ctx.addIssue({
|
|
123
139
|
code: "custom",
|
|
124
140
|
path: [...path, key, i, "searchPublic"],
|
|
125
|
-
message: '`searchPublic` only applies to a hidden item - add "hidden": true, or remove `searchPublic`.'
|
|
141
|
+
message: '`searchPublic` only applies to a hidden or protected item - add "hidden": true or an `access` rule, or remove `searchPublic`.'
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
if (own2?.lock === true && own2.access === void 0) {
|
|
145
|
+
ctx.addIssue({
|
|
146
|
+
code: "custom",
|
|
147
|
+
path: [...path, key, i, "lock"],
|
|
148
|
+
message: "`lock` marks a protected item, and this one has no `access` rule - add `access`, or remove `lock`."
|
|
126
149
|
});
|
|
127
150
|
}
|
|
128
151
|
const inner = key === "languages" ? String(item?.language ?? "") : language;
|
|
@@ -132,6 +155,20 @@ const navigationSchema = z.union([
|
|
|
132
155
|
}
|
|
133
156
|
};
|
|
134
157
|
walk(navigation, [], null, []);
|
|
158
|
+
const protectedIn = (node, path) => {
|
|
159
|
+
if (!node || typeof node !== "object") return;
|
|
160
|
+
if (Array.isArray(node)) return node.forEach((child, i) => protectedIn(child, [...path, i]));
|
|
161
|
+
for (const [key, value] of Object.entries(node)) {
|
|
162
|
+
if (key === "access" || key === "lock") {
|
|
163
|
+
ctx.addIssue({
|
|
164
|
+
code: "custom",
|
|
165
|
+
path: [...path, key],
|
|
166
|
+
message: `\`${key}\` doesn't apply in \`global.dropdowns\` - protect a tab, version, language, dropdown or product of the navigation instead.`
|
|
167
|
+
});
|
|
168
|
+
} else if (key !== "pages") protectedIn(value, [...path, key]);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
if (!Array.isArray(navigation)) protectedIn(navigation.global, ["global"]);
|
|
135
172
|
});
|
|
136
173
|
const DEFAULT_PRIMARY = "#6366f1";
|
|
137
174
|
const logoSchema = z.union([
|
|
@@ -1416,6 +1453,7 @@ function localizarEHumanizar(lista, rawText, raw, criar) {
|
|
|
1416
1453
|
}));
|
|
1417
1454
|
}
|
|
1418
1455
|
export {
|
|
1456
|
+
ACCESS_RULE_NAME,
|
|
1419
1457
|
CONTEXT_MENU_OPTIONS,
|
|
1420
1458
|
MAX_TAB_LEVELS,
|
|
1421
1459
|
MAX_TAB_MENU_LEVELS,
|
package/src/lib/config-schema.ts
CHANGED
|
@@ -144,8 +144,21 @@ export type NavChildren =
|
|
|
144
144
|
* And any can have a `page` of its own: where choosing the item leads, in
|
|
145
145
|
* place of its first page - an overview of what's in it. In a sidebar too,
|
|
146
146
|
* it opens there; otherwise it opens inside the item (resolveLandings() in
|
|
147
|
-
* lib/config.ts).
|
|
148
|
-
|
|
147
|
+
* lib/config.ts).
|
|
148
|
+
* And any can be protected: `access` names an access rule the WriteDocs
|
|
149
|
+
* platform keeps (a password or a list of emails). Every page under the
|
|
150
|
+
* item is served only to the readers that rule lets in, and the innermost
|
|
151
|
+
* item's rule wins. `lock` shows a padlock where the item is listed. See
|
|
152
|
+
* lib/protected-sections.js. */
|
|
153
|
+
export type Hideable = { hidden?: boolean; searchPublic?: boolean; page?: string; access?: string; lock?: boolean };
|
|
154
|
+
|
|
155
|
+
/** An access rule's name: lowercase letters, numbers and hyphens, 1 to 40
|
|
156
|
+
* characters. Never a secret - it names the rule, which the platform keeps,
|
|
157
|
+
* and it's part of the paths the build writes (lib/protected-sections.js). */
|
|
158
|
+
export const ACCESS_RULE_NAME = /^[a-z0-9-]{1,40}$/;
|
|
159
|
+
const accessSchema = z
|
|
160
|
+
.string()
|
|
161
|
+
.regex(ACCESS_RULE_NAME, 'An access rule\'s name is 1 to 40 lowercase letters, numbers and hyphens, like "partners".');
|
|
149
162
|
|
|
150
163
|
export type TabItem = { tab: string; icon?: string } & Hideable & NavChildren;
|
|
151
164
|
export type VersionItem = { version: string; label?: string; tag?: string; default?: boolean } & Hideable & NavChildren;
|
|
@@ -161,7 +174,14 @@ export type ProductItem = { product: string; icon?: string; description?: string
|
|
|
161
174
|
// rule this schema exists to enforce (mirroring Mintlify's own "a tab
|
|
162
175
|
// cannot contain both anchors and groups at the same level").
|
|
163
176
|
function withChildren<Base extends z.ZodRawShape>(ownFields: Base) {
|
|
164
|
-
const base = {
|
|
177
|
+
const base = {
|
|
178
|
+
...ownFields,
|
|
179
|
+
hidden: z.boolean().optional(),
|
|
180
|
+
searchPublic: z.boolean().optional(),
|
|
181
|
+
page: z.string().optional(),
|
|
182
|
+
access: accessSchema.optional(),
|
|
183
|
+
lock: z.boolean().optional(),
|
|
184
|
+
};
|
|
165
185
|
return z.union([
|
|
166
186
|
z.object({ ...base, pages: z.array(navItemSchema) }).strict(),
|
|
167
187
|
z.object({ ...base, tabs: z.array(tabSchema).min(1) }).strict(),
|
|
@@ -283,7 +303,7 @@ const navigationSchema = z.union([
|
|
|
283
303
|
continue;
|
|
284
304
|
}
|
|
285
305
|
items.forEach((item, i) => {
|
|
286
|
-
const own = item as { hidden?: unknown; searchPublic?: unknown; page?: unknown; href?: unknown };
|
|
306
|
+
const own = item as { hidden?: unknown; searchPublic?: unknown; page?: unknown; href?: unknown; access?: unknown; lock?: unknown };
|
|
287
307
|
if (own?.page !== undefined && own.href !== undefined) {
|
|
288
308
|
ctx.addIssue({
|
|
289
309
|
code: 'custom',
|
|
@@ -291,11 +311,27 @@ const navigationSchema = z.union([
|
|
|
291
311
|
message: 'An item with `href` is a link, so it has no page of its own - remove `page`, or `href`.',
|
|
292
312
|
});
|
|
293
313
|
}
|
|
294
|
-
if (own?.
|
|
314
|
+
if (own?.access !== undefined && own.href !== undefined) {
|
|
315
|
+
ctx.addIssue({
|
|
316
|
+
code: 'custom',
|
|
317
|
+
path: [...path, key, i, 'access'],
|
|
318
|
+
message: 'An item with `href` is a link, so it has no pages to protect - remove `access`, or `href`.',
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
// A protected item is a search space of its own too
|
|
322
|
+
// (lib/protected-sections.js), so `searchPublic` applies to it.
|
|
323
|
+
if (own?.searchPublic === true && own.hidden !== true && own.access === undefined) {
|
|
295
324
|
ctx.addIssue({
|
|
296
325
|
code: 'custom',
|
|
297
326
|
path: [...path, key, i, 'searchPublic'],
|
|
298
|
-
message: '`searchPublic` only applies to a hidden item - add "hidden": true, or remove `searchPublic`.',
|
|
327
|
+
message: '`searchPublic` only applies to a hidden or protected item - add "hidden": true or an `access` rule, or remove `searchPublic`.',
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
if (own?.lock === true && own.access === undefined) {
|
|
331
|
+
ctx.addIssue({
|
|
332
|
+
code: 'custom',
|
|
333
|
+
path: [...path, key, i, 'lock'],
|
|
334
|
+
message: '`lock` marks a protected item, and this one has no `access` rule - add `access`, or remove `lock`.',
|
|
299
335
|
});
|
|
300
336
|
}
|
|
301
337
|
const inner = key === 'languages' ? String((item as { language?: unknown })?.language ?? '') : language;
|
|
@@ -305,6 +341,23 @@ const navigationSchema = z.union([
|
|
|
305
341
|
}
|
|
306
342
|
};
|
|
307
343
|
walk(navigation, [], null, []);
|
|
344
|
+
// `global.dropdowns` are on every page, outside the navigation's levels -
|
|
345
|
+
// there's no part of the site for a rule there to protect. Refused rather
|
|
346
|
+
// than ignored: a page an author meant to protect never goes out public.
|
|
347
|
+
const protectedIn = (node: unknown, path: (string | number)[]) => {
|
|
348
|
+
if (!node || typeof node !== 'object') return;
|
|
349
|
+
if (Array.isArray(node)) return node.forEach((child, i) => protectedIn(child, [...path, i]));
|
|
350
|
+
for (const [key, value] of Object.entries(node)) {
|
|
351
|
+
if (key === 'access' || key === 'lock') {
|
|
352
|
+
ctx.addIssue({
|
|
353
|
+
code: 'custom',
|
|
354
|
+
path: [...path, key],
|
|
355
|
+
message: `\`${key}\` doesn't apply in \`global.dropdowns\` - protect a tab, version, language, dropdown or product of the navigation instead.`,
|
|
356
|
+
});
|
|
357
|
+
} else if (key !== 'pages') protectedIn(value, [...path, key]);
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
if (!Array.isArray(navigation)) protectedIn((navigation as { global?: unknown }).global, ['global']);
|
|
308
361
|
}) as z.ZodType<NavigationConfig>;
|
|
309
362
|
|
|
310
363
|
const DEFAULT_PRIMARY = '#6366f1';
|