@volvel/docs-engine 0.0.0-stage → 0.6.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/LICENSE +202 -0
- package/THIRD_PARTY_NOTICES.md +23018 -0
- package/dist/among.d.ts +44 -0
- package/dist/among.js +128 -0
- package/dist/changelog.d.ts +54 -0
- package/dist/changelog.js +88 -0
- package/dist/diataxis.d.ts +52 -0
- package/dist/diataxis.js +155 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +14 -0
- package/dist/ops.d.ts +111 -0
- package/dist/ops.js +529 -0
- package/dist/output.d.ts +57 -0
- package/dist/output.js +56 -0
- package/dist/package.d.ts +34 -0
- package/dist/package.js +129 -0
- package/dist/page.d.ts +75 -0
- package/dist/page.js +189 -0
- package/dist/redirects.d.ts +27 -0
- package/dist/redirects.js +79 -0
- package/dist/schema.d.ts +210 -0
- package/dist/schema.js +238 -0
- package/dist/search-query.d.ts +103 -0
- package/dist/search-query.js +197 -0
- package/dist/search.d.ts +17 -0
- package/dist/search.js +98 -0
- package/dist/set.d.ts +198 -0
- package/dist/set.js +566 -0
- package/dist/stack.d.ts +45 -0
- package/dist/stack.js +73 -0
- package/dist/workspace.d.ts +122 -0
- package/dist/workspace.js +207 -0
- package/package.json +29 -3
- package/README.md +0 -3
package/dist/among.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type DocEntry, type DocIssue } from "./page.js";
|
|
2
|
+
import type { AboutKind } from "./schema.js";
|
|
3
|
+
/**
|
|
4
|
+
* What is known of a page without its text: enough to check another page's
|
|
5
|
+
* links, topics and terms against it. A writer's editor is given this for
|
|
6
|
+
* every page of the app, and checks the page being typed where it is typed.
|
|
7
|
+
*/
|
|
8
|
+
export interface PageIndex {
|
|
9
|
+
/** The page's path under its app's folder. */
|
|
10
|
+
path: string;
|
|
11
|
+
topic?: string | null | undefined;
|
|
12
|
+
/** The ids of the terms it defines. */
|
|
13
|
+
terms: readonly string[];
|
|
14
|
+
/** What its headings are addressed by. */
|
|
15
|
+
headings: readonly string[];
|
|
16
|
+
/** What it says of its own `type:`: on an index, the type of what is under it. Left out, it says none. */
|
|
17
|
+
type?: string | null | undefined;
|
|
18
|
+
/** Its `subjects:`. */
|
|
19
|
+
subjects?: readonly string[] | undefined;
|
|
20
|
+
/** Its `moved_from:`. */
|
|
21
|
+
moved_from?: readonly string[] | undefined;
|
|
22
|
+
}
|
|
23
|
+
export interface AmongOptions {
|
|
24
|
+
/** The product's own terms and topics, which a page may use and extend and may not take. */
|
|
25
|
+
reservedTerms?: Iterable<string>;
|
|
26
|
+
reservedTopics?: Iterable<string>;
|
|
27
|
+
/** Names that begin with this are the product's too: see `BuildOptions.reservedPrefix`. */
|
|
28
|
+
reservedPrefix?: string;
|
|
29
|
+
/** Terms defined elsewhere in the workspace: another docs app's. */
|
|
30
|
+
knownTerms?: Iterable<string>;
|
|
31
|
+
/** Whether a resource is there. Left out, or answering nothing, it is not checked: a deploy says it. */
|
|
32
|
+
resource?: (kind: AboutKind, path: string, column?: string) => boolean | undefined;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Checks one page as it is being written, beside the other pages of its app:
|
|
36
|
+
* everything a deploy would refuse it for that can be known from here. It is
|
|
37
|
+
* the same reading and the same rules as the deploy's check, given an index of
|
|
38
|
+
* the other pages in place of their text.
|
|
39
|
+
*/
|
|
40
|
+
export declare function checkPageAmong(path: string, source: string, others: readonly PageIndex[], options?: AmongOptions): {
|
|
41
|
+
entry: DocEntry;
|
|
42
|
+
issues: DocIssue[];
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=among.d.ts.map
|
package/dist/among.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { walk } from "@volvel/markup";
|
|
2
|
+
import { diataxisIssues, effectiveType } from "./diataxis.js";
|
|
3
|
+
import { readPage } from "./page.js";
|
|
4
|
+
import { ABOUT_KINDS } from "./schema.js";
|
|
5
|
+
import { crossIssues } from "./set.js";
|
|
6
|
+
/**
|
|
7
|
+
* Checks one page as it is being written, beside the other pages of its app:
|
|
8
|
+
* everything a deploy would refuse it for that can be known from here. It is
|
|
9
|
+
* the same reading and the same rules as the deploy's check, given an index of
|
|
10
|
+
* the other pages in place of their text.
|
|
11
|
+
*/
|
|
12
|
+
export function checkPageAmong(path, source, others, options = {}) {
|
|
13
|
+
const { entry, issues } = readPage(path, source);
|
|
14
|
+
const error = (code, message, line = 1) => {
|
|
15
|
+
issues.push({ path, line, column: 1, code, message, severity: "error" });
|
|
16
|
+
};
|
|
17
|
+
const rest = others.filter((one) => one.path !== path);
|
|
18
|
+
const paths = new Set([...rest.map((one) => one.path), path]);
|
|
19
|
+
// Where it is among the folders.
|
|
20
|
+
const parts = path.split("/");
|
|
21
|
+
const name = parts.at(-1);
|
|
22
|
+
if (name === "index" && entry.frontmatter.pages) {
|
|
23
|
+
const folder = parts.slice(0, -1).join("/");
|
|
24
|
+
const prefix = folder === "" ? "" : `${folder}/`;
|
|
25
|
+
const names = new Set(rest
|
|
26
|
+
.filter((one) => one.path.startsWith(prefix))
|
|
27
|
+
.map((one) => one.path.slice(prefix.length).split("/")[0]));
|
|
28
|
+
for (const listed of entry.frontmatter.pages) {
|
|
29
|
+
if (listed !== "index" && !names.has(listed)) {
|
|
30
|
+
issues.push({
|
|
31
|
+
path,
|
|
32
|
+
line: 1,
|
|
33
|
+
column: 1,
|
|
34
|
+
code: "pages_unknown",
|
|
35
|
+
message: `pages: lists "${listed}", and there is no page or folder of that name in ${folder === "" ? "this folder" : folder}.`,
|
|
36
|
+
severity: "warning",
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (name !== "index" && rest.some((one) => one.path.startsWith(`${path}/`))) {
|
|
42
|
+
error("file_and_folder", `${path}.md sits beside a folder named ${name}. A folder's own page is the index.md inside it: move this file to ${path}/index.md.`);
|
|
43
|
+
}
|
|
44
|
+
// What it says of itself, beside what the others say.
|
|
45
|
+
const reservedTerms = new Set(options.reservedTerms ?? []);
|
|
46
|
+
const reservedTopics = new Set(options.reservedTopics ?? []);
|
|
47
|
+
const prefixed = (name) => options.reservedPrefix !== undefined && name.startsWith(options.reservedPrefix);
|
|
48
|
+
const topics = {};
|
|
49
|
+
for (const one of rest)
|
|
50
|
+
if (one.topic)
|
|
51
|
+
topics[one.topic] = one.path;
|
|
52
|
+
const { topic } = entry.frontmatter;
|
|
53
|
+
if (topic !== undefined) {
|
|
54
|
+
if (reservedTopics.has(topic) || prefixed(topic)) {
|
|
55
|
+
error("topic_reserved", `The topic "${topic}" is one of the product's own. A page can add notes to it with extends: [${topic}], and cannot take its name.`);
|
|
56
|
+
}
|
|
57
|
+
else if (topics[topic] !== undefined) {
|
|
58
|
+
error("topic_duplicate", `The topic "${topic}" is also the topic of ${topics[topic]}. A topic belongs to one page.`);
|
|
59
|
+
}
|
|
60
|
+
else
|
|
61
|
+
topics[topic] = path;
|
|
62
|
+
}
|
|
63
|
+
const defined = new Map();
|
|
64
|
+
for (const one of rest)
|
|
65
|
+
for (const id of one.terms)
|
|
66
|
+
defined.set(id, one.path);
|
|
67
|
+
for (const term of entry.frontmatter.terms ?? []) {
|
|
68
|
+
if (reservedTerms.has(term.id) || prefixed(term.id)) {
|
|
69
|
+
error("term_reserved", `The term "${term.id}" is one of the product's own, and cannot be defined again. Give yours another id.`);
|
|
70
|
+
}
|
|
71
|
+
else if (defined.has(term.id)) {
|
|
72
|
+
error("term_duplicate", `The term "${term.id}" is also defined on ${defined.get(term.id)}. A term is defined once.`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
for (const extended of entry.frontmatter.extends ?? []) {
|
|
76
|
+
if (options.reservedTopics !== undefined && !reservedTopics.has(extended)) {
|
|
77
|
+
error("extends_unknown", `This page extends "${extended}", and the product's help has no such topic.`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const resource = options.resource;
|
|
81
|
+
for (const about of entry.frontmatter.about ?? []) {
|
|
82
|
+
for (const kind of ABOUT_KINDS) {
|
|
83
|
+
const target = about[kind];
|
|
84
|
+
if (target !== undefined && resource?.(kind, target) === false) {
|
|
85
|
+
error("about_unknown", `This page is about the ${kind} ${target}, and there is no such ${kind}.`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Where it used to be, and what its type says: the same checks as a deploy's, beside the others.
|
|
90
|
+
for (const old of entry.frontmatter.moved_from ?? []) {
|
|
91
|
+
if (old === path) {
|
|
92
|
+
error("moved_from_self", `moved_from lists "${old}", which is this page's own path.`);
|
|
93
|
+
}
|
|
94
|
+
else if (paths.has(old)) {
|
|
95
|
+
error("moved_from_exists", `moved_from lists "${old}", and there is a page at that path. A path that is still a page cannot lead somewhere else: take it out of moved_from, or move that page.`);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
const other = rest.find((one) => one.moved_from?.includes(old));
|
|
99
|
+
if (other) {
|
|
100
|
+
error("moved_from_duplicate", `moved_from lists "${old}", which ${other.path} also lists. An old path leads to one page.`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const ownType = (at) => at === path ? entry.frontmatter.type : rest.find((one) => one.path === at)?.type;
|
|
105
|
+
// Whether a subject is used once, and whether a folder says a type, are known to a deploy alone.
|
|
106
|
+
issues.push(...diataxisIssues(entry, { type: effectiveType(path, ownType) }));
|
|
107
|
+
// Its links and terms, against the pages around it.
|
|
108
|
+
const own = new Set();
|
|
109
|
+
for (const { node } of walk(entry.tree))
|
|
110
|
+
if (node.type === "heading")
|
|
111
|
+
own.add(node.id);
|
|
112
|
+
const headings = new Map(rest.map((one) => [one.path, new Set(one.headings)]));
|
|
113
|
+
issues.push(...crossIssues(entry, {
|
|
114
|
+
pages: paths,
|
|
115
|
+
topics,
|
|
116
|
+
headingsOf: (at) => (at === path ? own : (headings.get(at) ?? new Set())),
|
|
117
|
+
knownTerms: new Set([
|
|
118
|
+
...reservedTerms,
|
|
119
|
+
...(options.knownTerms ?? []),
|
|
120
|
+
...defined.keys(),
|
|
121
|
+
...(entry.frontmatter.terms ?? []).map((term) => term.id),
|
|
122
|
+
]),
|
|
123
|
+
...(resource ? { resource: (kind, at, column) => resource(kind, at, column) !== false } : {}),
|
|
124
|
+
}));
|
|
125
|
+
issues.sort((a, b) => a.line - b.line || a.column - b.column);
|
|
126
|
+
return { entry, issues };
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=among.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { DocEntry } from "./page.js";
|
|
2
|
+
import type { DocSet } from "./set.js";
|
|
3
|
+
/**
|
|
4
|
+
* A site's changelog is made of pages: nothing else lists it. A page is an entry when a folder in
|
|
5
|
+
* its path is named `changelog`, or when it carries the subject `changelog`. A folder's own index
|
|
6
|
+
* is the folder's landing page, never an entry.
|
|
7
|
+
*/
|
|
8
|
+
export declare const CHANGELOG_NAME = "changelog";
|
|
9
|
+
/** Where an entry's date was read from. */
|
|
10
|
+
export type DateSource = "frontmatter" | "name" | "updated";
|
|
11
|
+
export interface ChangelogEntry {
|
|
12
|
+
/** The page, by its path under the docs root. */
|
|
13
|
+
path: string;
|
|
14
|
+
title: string;
|
|
15
|
+
/** `YYYY-MM-DD`. Undefined when nothing says: the page has no `date:`, none in its name, and no last update. */
|
|
16
|
+
date?: string;
|
|
17
|
+
source?: DateSource;
|
|
18
|
+
page: DocEntry;
|
|
19
|
+
}
|
|
20
|
+
export interface ChangelogOptions {
|
|
21
|
+
/** Only the entries under this folder, by its path under the docs root (`changelog/product`). */
|
|
22
|
+
folder?: string;
|
|
23
|
+
/** Only the entries that name this subject. */
|
|
24
|
+
subject?: string;
|
|
25
|
+
}
|
|
26
|
+
/** Whether a text is a real calendar day written `YYYY-MM-DD`. */
|
|
27
|
+
export declare function isDay(text: string): boolean;
|
|
28
|
+
/** A date that begins or ends a file's name: `2026-11-24-new-intake`, `new-intake-2026-11-24`. */
|
|
29
|
+
export declare function dayInName(path: string): string | undefined;
|
|
30
|
+
/** Whether a page is an entry of the changelog. */
|
|
31
|
+
export declare function isChangelogEntry(path: string, entry: Pick<DocEntry, "frontmatter">): boolean;
|
|
32
|
+
/** An entry's day, and where it came from: its `date:`, else its file name, else its last update. */
|
|
33
|
+
export declare function changelogDate(path: string, entry: Pick<DocEntry, "frontmatter" | "updated">): {
|
|
34
|
+
date: string;
|
|
35
|
+
source: DateSource;
|
|
36
|
+
} | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* The entries of a set, newest first. An entry nothing dates has not been released: it comes
|
|
39
|
+
* first, and entries with the same day come in the reverse order of their paths, so that
|
|
40
|
+
* `…-2` follows `…-1` upwards.
|
|
41
|
+
*/
|
|
42
|
+
export declare function changelogOf(set: Pick<DocSet, "pages">, options?: ChangelogOptions): ChangelogEntry[];
|
|
43
|
+
/**
|
|
44
|
+
* The order of a changelog wherever it is listed: the list, the navigation, a page's Previous and
|
|
45
|
+
* Next. Undated first, then the latest day, then the later path.
|
|
46
|
+
*/
|
|
47
|
+
export declare function newestFirst(a: {
|
|
48
|
+
path: string;
|
|
49
|
+
date?: string | undefined;
|
|
50
|
+
}, b: {
|
|
51
|
+
path: string;
|
|
52
|
+
date?: string | undefined;
|
|
53
|
+
}): number;
|
|
54
|
+
//# sourceMappingURL=changelog.d.ts.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A site's changelog is made of pages: nothing else lists it. A page is an entry when a folder in
|
|
3
|
+
* its path is named `changelog`, or when it carries the subject `changelog`. A folder's own index
|
|
4
|
+
* is the folder's landing page, never an entry.
|
|
5
|
+
*/
|
|
6
|
+
export const CHANGELOG_NAME = "changelog";
|
|
7
|
+
const DAY = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
8
|
+
/** Whether a text is a real calendar day written `YYYY-MM-DD`. */
|
|
9
|
+
export function isDay(text) {
|
|
10
|
+
const found = DAY.exec(text);
|
|
11
|
+
if (!found)
|
|
12
|
+
return false;
|
|
13
|
+
const [, year, month, day] = found.map(Number);
|
|
14
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
15
|
+
return (date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day);
|
|
16
|
+
}
|
|
17
|
+
/** A date that begins or ends a file's name: `2026-11-24-new-intake`, `new-intake-2026-11-24`. */
|
|
18
|
+
export function dayInName(path) {
|
|
19
|
+
const name = path.split("/").at(-1) ?? "";
|
|
20
|
+
const first = /^(\d{4}-\d{2}-\d{2})(?:[-_.]|$)/.exec(name)?.[1];
|
|
21
|
+
if (first && isDay(first))
|
|
22
|
+
return first;
|
|
23
|
+
const last = /(?:^|[-_.])(\d{4}-\d{2}-\d{2})$/.exec(name)?.[1];
|
|
24
|
+
return last && isDay(last) ? last : undefined;
|
|
25
|
+
}
|
|
26
|
+
/** Whether a page is an entry of the changelog. */
|
|
27
|
+
export function isChangelogEntry(path, entry) {
|
|
28
|
+
if (path === "index" || path.endsWith("/index"))
|
|
29
|
+
return false;
|
|
30
|
+
const folders = path.split("/").slice(0, -1);
|
|
31
|
+
return (folders.includes(CHANGELOG_NAME) || (entry.frontmatter.subjects ?? []).includes(CHANGELOG_NAME));
|
|
32
|
+
}
|
|
33
|
+
/** An entry's day, and where it came from: its `date:`, else its file name, else its last update. */
|
|
34
|
+
export function changelogDate(path, entry) {
|
|
35
|
+
const said = entry.frontmatter.date;
|
|
36
|
+
if (said && isDay(said))
|
|
37
|
+
return { date: said, source: "frontmatter" };
|
|
38
|
+
const named = dayInName(path);
|
|
39
|
+
if (named)
|
|
40
|
+
return { date: named, source: "name" };
|
|
41
|
+
if (entry.updated) {
|
|
42
|
+
const when = new Date(entry.updated);
|
|
43
|
+
if (!Number.isNaN(when.getTime())) {
|
|
44
|
+
return { date: when.toISOString().slice(0, 10), source: "updated" };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The entries of a set, newest first. An entry nothing dates has not been released: it comes
|
|
51
|
+
* first, and entries with the same day come in the reverse order of their paths, so that
|
|
52
|
+
* `…-2` follows `…-1` upwards.
|
|
53
|
+
*/
|
|
54
|
+
export function changelogOf(set, options = {}) {
|
|
55
|
+
const folder = options.folder?.replace(/^\/+|\/+$/g, "");
|
|
56
|
+
const out = [];
|
|
57
|
+
for (const [path, page] of set.pages) {
|
|
58
|
+
if (!isChangelogEntry(path, page))
|
|
59
|
+
continue;
|
|
60
|
+
if (folder && !path.startsWith(`${folder}/`))
|
|
61
|
+
continue;
|
|
62
|
+
if (options.subject && !(page.frontmatter.subjects ?? []).includes(options.subject))
|
|
63
|
+
continue;
|
|
64
|
+
const dated = changelogDate(path, page);
|
|
65
|
+
out.push({
|
|
66
|
+
path,
|
|
67
|
+
title: page.frontmatter.title,
|
|
68
|
+
...(dated ? { date: dated.date, source: dated.source } : {}),
|
|
69
|
+
page,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return out.sort(newestFirst);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The order of a changelog wherever it is listed: the list, the navigation, a page's Previous and
|
|
76
|
+
* Next. Undated first, then the latest day, then the later path.
|
|
77
|
+
*/
|
|
78
|
+
export function newestFirst(a, b) {
|
|
79
|
+
if (a.date !== b.date) {
|
|
80
|
+
if (a.date === undefined)
|
|
81
|
+
return -1;
|
|
82
|
+
if (b.date === undefined)
|
|
83
|
+
return 1;
|
|
84
|
+
return b.date.localeCompare(a.date);
|
|
85
|
+
}
|
|
86
|
+
return b.path.localeCompare(a.path);
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=changelog.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { DocEntry, DocIssue } from "./page.js";
|
|
2
|
+
/**
|
|
3
|
+
* The four kinds of page, by what the reader is doing (Diátaxis). A page's
|
|
4
|
+
* type is its own `type:`, or else the `type:` of the nearest folder index
|
|
5
|
+
* above it. A folder's index is a landing page: it labels what is under it
|
|
6
|
+
* and has no type itself. A site that says none of this has no types, and is
|
|
7
|
+
* drawn as it always was.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DOC_TYPES: readonly ["tutorial", "how-to", "reference", "explanation"];
|
|
10
|
+
export type DocType = (typeof DOC_TYPES)[number];
|
|
11
|
+
/** The words a reader meets for each type. */
|
|
12
|
+
export declare const DOC_TYPE_LABELS: Record<DocType, string>;
|
|
13
|
+
/** The types as a group of pages is headed: on a collection's cards and in the Related block. */
|
|
14
|
+
export declare const DOC_TYPE_PLURALS: Record<DocType, string>;
|
|
15
|
+
/** What each type is for, in a line: shown on a collection's landing page. */
|
|
16
|
+
export declare const DOC_TYPE_SUMMARIES: Record<DocType, string>;
|
|
17
|
+
export declare const isDocType: (value: unknown) => value is DocType;
|
|
18
|
+
/** The most subjects of a page that count. */
|
|
19
|
+
export declare const MAX_SUBJECTS = 5;
|
|
20
|
+
/**
|
|
21
|
+
* The type of a page: its own, and for a page that is not a folder's index,
|
|
22
|
+
* else the nearest index above it that says one. `own` reads what a page
|
|
23
|
+
* says for itself. An index has no type of its own, so is `undefined`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function effectiveType(path: string, own: (path: string) => unknown): DocType | undefined;
|
|
26
|
+
/** What a folder's index says is under it: the nearest, going up. */
|
|
27
|
+
export declare function folderType(path: string, own: (path: string) => unknown): DocType | undefined;
|
|
28
|
+
/** The lints of the typed pages. Each is a warning: a deploy is never refused for one. */
|
|
29
|
+
export declare const DIATAXIS_CODES: readonly ["type_unknown", "subjects_many", "subject_once", "type_folder", "type_steps_missing", "type_steps_present", "type_title", "type_goal_missing"];
|
|
30
|
+
export interface DiataxisContext {
|
|
31
|
+
/** The page's type, as `effectiveType` works it out. */
|
|
32
|
+
type: DocType | undefined;
|
|
33
|
+
/** Whether a folder above the page says a type. Left out, that is not asked. */
|
|
34
|
+
folderTyped?: boolean;
|
|
35
|
+
/** How many pages have each subject. Left out, a subject used once is not said. */
|
|
36
|
+
subjectUses?: (subject: string) => number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* What is not as it should be about a page's type and subjects. A page with
|
|
40
|
+
* none of them says nothing, so a site that does not use types is never told
|
|
41
|
+
* anything. A folder's index is a landing page, so only what it says for
|
|
42
|
+
* itself is read.
|
|
43
|
+
*/
|
|
44
|
+
export declare function diataxisIssues(entry: DocEntry, context: DiataxisContext): DocIssue[];
|
|
45
|
+
/** The source a new page of each type starts from, under its frontmatter. */
|
|
46
|
+
export declare const DOC_TEMPLATES: Record<DocType, string>;
|
|
47
|
+
/**
|
|
48
|
+
* The source a new changelog entry starts from, under its frontmatter. An entry is not one of the
|
|
49
|
+
* four types: it says what changed, for whoever follows the site.
|
|
50
|
+
*/
|
|
51
|
+
export declare const CHANGELOG_TEMPLATE = "One sentence on what changed and who it matters to.\n\n## What is new\n\n- What a person can do now that they could not, in plain words.\n\n## What to do\n\nWhat a reader needs to do about it, if anything. Delete this heading if nothing.\n";
|
|
52
|
+
//# sourceMappingURL=diataxis.d.ts.map
|
package/dist/diataxis.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { walk } from "@volvel/markup";
|
|
2
|
+
/**
|
|
3
|
+
* The four kinds of page, by what the reader is doing (Diátaxis). A page's
|
|
4
|
+
* type is its own `type:`, or else the `type:` of the nearest folder index
|
|
5
|
+
* above it. A folder's index is a landing page: it labels what is under it
|
|
6
|
+
* and has no type itself. A site that says none of this has no types, and is
|
|
7
|
+
* drawn as it always was.
|
|
8
|
+
*/
|
|
9
|
+
export const DOC_TYPES = ["tutorial", "how-to", "reference", "explanation"];
|
|
10
|
+
/** The words a reader meets for each type. */
|
|
11
|
+
export const DOC_TYPE_LABELS = {
|
|
12
|
+
tutorial: "Tutorial",
|
|
13
|
+
"how-to": "How-to guide",
|
|
14
|
+
reference: "Reference",
|
|
15
|
+
explanation: "Explanation",
|
|
16
|
+
};
|
|
17
|
+
/** The types as a group of pages is headed: on a collection's cards and in the Related block. */
|
|
18
|
+
export const DOC_TYPE_PLURALS = {
|
|
19
|
+
tutorial: "Tutorials",
|
|
20
|
+
"how-to": "How-to guides",
|
|
21
|
+
reference: "Reference",
|
|
22
|
+
explanation: "Explanations",
|
|
23
|
+
};
|
|
24
|
+
/** What each type is for, in a line: shown on a collection's landing page. */
|
|
25
|
+
export const DOC_TYPE_SUMMARIES = {
|
|
26
|
+
tutorial: "Learn by building something, one step at a time.",
|
|
27
|
+
"how-to": "Get one task done.",
|
|
28
|
+
reference: "Look up how something is, exactly.",
|
|
29
|
+
explanation: "Understand how it works and why.",
|
|
30
|
+
};
|
|
31
|
+
export const isDocType = (value) => typeof value === "string" && DOC_TYPES.includes(value);
|
|
32
|
+
/** The most subjects of a page that count. */
|
|
33
|
+
export const MAX_SUBJECTS = 5;
|
|
34
|
+
const isIndex = (path) => path === "index" || path.endsWith("/index");
|
|
35
|
+
/**
|
|
36
|
+
* The type of a page: its own, and for a page that is not a folder's index,
|
|
37
|
+
* else the nearest index above it that says one. `own` reads what a page
|
|
38
|
+
* says for itself. An index has no type of its own, so is `undefined`.
|
|
39
|
+
*/
|
|
40
|
+
export function effectiveType(path, own) {
|
|
41
|
+
if (isIndex(path))
|
|
42
|
+
return undefined;
|
|
43
|
+
const mine = own(path);
|
|
44
|
+
if (isDocType(mine))
|
|
45
|
+
return mine;
|
|
46
|
+
return folderType(path, own);
|
|
47
|
+
}
|
|
48
|
+
/** What a folder's index says is under it: the nearest, going up. */
|
|
49
|
+
export function folderType(path, own) {
|
|
50
|
+
// `a/b/page` asks `a/b/index`, `a/index` and `index`; `a/b/index` asks from `a`.
|
|
51
|
+
let parts = path.split("/").slice(0, -1);
|
|
52
|
+
if (isIndex(path))
|
|
53
|
+
parts = parts.slice(0, -1);
|
|
54
|
+
for (;;) {
|
|
55
|
+
const found = own(parts.length === 0 ? "index" : `${parts.join("/")}/index`);
|
|
56
|
+
if (isDocType(found))
|
|
57
|
+
return found;
|
|
58
|
+
if (parts.length === 0)
|
|
59
|
+
return undefined;
|
|
60
|
+
parts = parts.slice(0, -1);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** The lints of the typed pages. Each is a warning: a deploy is never refused for one. */
|
|
64
|
+
export const DIATAXIS_CODES = [
|
|
65
|
+
"type_unknown",
|
|
66
|
+
"subjects_many",
|
|
67
|
+
"subject_once",
|
|
68
|
+
"type_folder",
|
|
69
|
+
"type_steps_missing",
|
|
70
|
+
"type_steps_present",
|
|
71
|
+
"type_title",
|
|
72
|
+
"type_goal_missing",
|
|
73
|
+
];
|
|
74
|
+
/** Whether a page has a numbered list or a `steps` block. */
|
|
75
|
+
function hasSteps(entry) {
|
|
76
|
+
for (const { node } of walk(entry.tree)) {
|
|
77
|
+
if (node.type === "list" && node.ordered)
|
|
78
|
+
return true;
|
|
79
|
+
if (node.type === "component" && node.name === "steps")
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
const NOT_A_TASK = /^(about|overview|introduction|understanding|reference|guide to|what is|why)\b/i;
|
|
85
|
+
/**
|
|
86
|
+
* What is not as it should be about a page's type and subjects. A page with
|
|
87
|
+
* none of them says nothing, so a site that does not use types is never told
|
|
88
|
+
* anything. A folder's index is a landing page, so only what it says for
|
|
89
|
+
* itself is read.
|
|
90
|
+
*/
|
|
91
|
+
export function diataxisIssues(entry, context) {
|
|
92
|
+
const issues = [];
|
|
93
|
+
const warn = (code, message) => {
|
|
94
|
+
issues.push({
|
|
95
|
+
path: entry.path,
|
|
96
|
+
line: 1,
|
|
97
|
+
column: 1,
|
|
98
|
+
code,
|
|
99
|
+
message,
|
|
100
|
+
severity: "warning",
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
const { type: written, subjects } = entry.frontmatter;
|
|
104
|
+
if (written !== undefined && !isDocType(written)) {
|
|
105
|
+
warn("type_unknown", `The type "${written}" is none of ${DOC_TYPES.join(", ")}. The page is treated as having no type.`);
|
|
106
|
+
}
|
|
107
|
+
if (subjects && subjects.length > MAX_SUBJECTS) {
|
|
108
|
+
warn("subjects_many", `This page names ${subjects.length} subjects, and the first ${MAX_SUBJECTS} are used. Keep the ones a reader would look for.`);
|
|
109
|
+
}
|
|
110
|
+
if (isIndex(entry.path))
|
|
111
|
+
return issues;
|
|
112
|
+
for (const subject of (subjects ?? []).slice(0, MAX_SUBJECTS)) {
|
|
113
|
+
if (context.subjectUses && context.subjectUses(subject) === 1) {
|
|
114
|
+
warn("subject_once", `The subject "${subject}" is on no other page, so it relates this page to nothing. Use it on a page of another type, or take it out.`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const { type } = context;
|
|
118
|
+
if (type === undefined)
|
|
119
|
+
return issues;
|
|
120
|
+
if (isDocType(written) && context.folderTyped === false) {
|
|
121
|
+
warn("type_folder", `This page says it is ${/^[aeiou]/i.test(type) ? "an" : "a"} ${type}, in a folder whose index says no type. Put type: ${type} on the folder's index.md so that every page in it has it.`);
|
|
122
|
+
}
|
|
123
|
+
const steps = hasSteps(entry);
|
|
124
|
+
if ((type === "tutorial" || type === "how-to") && !steps) {
|
|
125
|
+
warn("type_steps_missing", `A ${type} is followed in order, and this page has no numbered steps. Write them as a numbered list or a :::steps block.`);
|
|
126
|
+
}
|
|
127
|
+
if ((type === "reference" || type === "explanation") && steps) {
|
|
128
|
+
warn("type_steps_present", `A ${type} is read, not followed, and this page has numbered steps. Move the steps to a how-to and link to it.`);
|
|
129
|
+
}
|
|
130
|
+
const title = entry.frontmatter.title;
|
|
131
|
+
if ((type === "tutorial" || type === "how-to") &&
|
|
132
|
+
(NOT_A_TASK.test(title) || title.endsWith("?"))) {
|
|
133
|
+
warn("type_title", `A ${type}'s title says what the reader will do ("Connect a table to a flow"), and "${title}" does not.`);
|
|
134
|
+
}
|
|
135
|
+
if (type === "how-to") {
|
|
136
|
+
const headed = [...walk(entry.tree)].some(({ node }) => node.type === "heading");
|
|
137
|
+
if (!headed) {
|
|
138
|
+
warn("type_goal_missing", "A how-to opens with a heading that says its goal, then gives the steps. This page has no heading.");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return issues;
|
|
142
|
+
}
|
|
143
|
+
/** The source a new page of each type starts from, under its frontmatter. */
|
|
144
|
+
export const DOC_TEMPLATES = {
|
|
145
|
+
tutorial: "In this tutorial you will build something small, and it works at the end. It takes about ten minutes.\n\n## Before you start\n\nWhat the reader needs: an account, a table, ten minutes.\n\n:::steps\n1. The first thing to do, and what they see when it works.\n2. The next thing.\n:::\n\n## What you built\n\nWhat now exists, and where to go next.\n",
|
|
146
|
+
"how-to": "## Do the thing\n\nOne sentence on what the reader will have done at the end.\n\n## Before you start\n\nWhat the reader needs, and who can give it.\n\n:::steps\n1. The first step.\n2. The next step.\n:::\n\n## The result\n\nWhat the reader now sees.\n\n## If it does not work\n\nThe one or two things that go wrong, and what to do.\n",
|
|
147
|
+
reference: "What this is, in a sentence. Then the facts, in tables and lists, in a fixed order.\n\n## Fields\n\n| Name | What it is |\n| --- | --- |\n| | |\n",
|
|
148
|
+
explanation: "Why this is the way it is, in prose, with the ideas in order.\n\n## The idea\n\nWhat it is for.\n\n## How it fits\n\nWhat it works with, and what it leaves to others.\n",
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* The source a new changelog entry starts from, under its frontmatter. An entry is not one of the
|
|
152
|
+
* four types: it says what changed, for whoever follows the site.
|
|
153
|
+
*/
|
|
154
|
+
export const CHANGELOG_TEMPLATE = "One sentence on what changed and who it matters to.\n\n## What is new\n\n- What a person can do now that they could not, in plain words.\n\n## What to do\n\nWhat a reader needs to do about it, if anything. Delete this heading if nothing.\n";
|
|
155
|
+
//# sourceMappingURL=diataxis.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { type AmongOptions, checkPageAmong, type PageIndex } from "./among.js";
|
|
2
|
+
export { CHANGELOG_NAME, type ChangelogEntry, type ChangelogOptions, changelogDate, changelogOf, dayInName, isChangelogEntry, isDay, } from "./changelog.js";
|
|
3
|
+
export { CHANGELOG_TEMPLATE, DIATAXIS_CODES, DOC_TEMPLATES, DOC_TYPE_LABELS, DOC_TYPE_PLURALS, DOC_TYPE_SUMMARIES, DOC_TYPES, type DocType, diataxisIssues, effectiveType, folderType, isDocType, MAX_SUBJECTS, } from "./diataxis.js";
|
|
4
|
+
export { type Change, changelogEntryName, childrenOf, inverseOf, NAME_PATTERN, nameProblem, newPageSource, orderOf, type PageSource, type Place, type Plan, planDelete, planDuplicate, planMove, planNewChangelogEntry, planNewFolder, planNewPage, planRename, relativeHref, slugOf, } from "./ops.js";
|
|
5
|
+
export { type Manifest, manifestOf, type PageFile, packageOutput } from "./output.js";
|
|
6
|
+
export { type OpenedPackage, openPackage, setFromManifest } from "./package.js";
|
|
7
|
+
export { asDirectory, type DocEntry, type DocIssue, frontmatterOf, pagePath, type ReadOptions, readPage, setFrontmatter, splitFrontmatter, titleOf, } from "./page.js";
|
|
8
|
+
export { type MovedPage, type RedirectProblem, redirectedPath, redirectMap, } from "./redirects.js";
|
|
9
|
+
export { ABOUT_KINDS, type About, type AboutKind, check, FRONTMATTER_SCHEMA, type Frontmatter, PATH_PATTERN, type Schema, type SchemaProblem, type TermDefinition, } from "./schema.js";
|
|
10
|
+
export { buildSearchIndex, loadSearchIndex, type Marked, mark, type PageHit, type PlaceHit, RESULT_LIMIT, type SearchHit, } from "./search.js";
|
|
11
|
+
export { type Around, type BuildOptions, buildDocSet, type Collection, crossIssues, type DocSet, type Folder, folderItems, glossaryOf, homeTypeCardsOf, type Nav, nameOf, neighboursOf, ordered, type PageRef, PRODUCT_PREFIX, pagesInOrder, RELATED_PER_TYPE, relatedTo, resolveAsset, resolveLink, resourceKey, type Target, type Term, type TypeCard, trailOf, typeCardsOf, UNCATEGORIZED, urlOf, } from "./set.js";
|
|
12
|
+
export { allTerms, attachedTo, clashes, extensionsOf, type Found, findTerm, findTopic, type Layer, type Stack, } from "./stack.js";
|
|
13
|
+
export { appOf, type BuiltApp, buildApp, checkWorkspaceDocs, type DocsApp, docsApps, FEEDBACK_COLUMNS, FEEDBACK_TABLE, hasFeedbackColumns, isFeedbackTable, pagesOf, type ResourceLike, resourceChecker, type WorkspaceOptions, workspaceDocsWarnings, } from "./workspace.js";
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { checkPageAmong } from "./among.js";
|
|
2
|
+
export { CHANGELOG_NAME, changelogDate, changelogOf, dayInName, isChangelogEntry, isDay, } from "./changelog.js";
|
|
3
|
+
export { CHANGELOG_TEMPLATE, DIATAXIS_CODES, DOC_TEMPLATES, DOC_TYPE_LABELS, DOC_TYPE_PLURALS, DOC_TYPE_SUMMARIES, DOC_TYPES, diataxisIssues, effectiveType, folderType, isDocType, MAX_SUBJECTS, } from "./diataxis.js";
|
|
4
|
+
export { changelogEntryName, childrenOf, inverseOf, NAME_PATTERN, nameProblem, newPageSource, orderOf, planDelete, planDuplicate, planMove, planNewChangelogEntry, planNewFolder, planNewPage, planRename, relativeHref, slugOf, } from "./ops.js";
|
|
5
|
+
export { manifestOf, packageOutput } from "./output.js";
|
|
6
|
+
export { openPackage, setFromManifest } from "./package.js";
|
|
7
|
+
export { asDirectory, frontmatterOf, pagePath, readPage, setFrontmatter, splitFrontmatter, titleOf, } from "./page.js";
|
|
8
|
+
export { redirectedPath, redirectMap, } from "./redirects.js";
|
|
9
|
+
export { ABOUT_KINDS, check, FRONTMATTER_SCHEMA, PATH_PATTERN, } from "./schema.js";
|
|
10
|
+
export { buildSearchIndex, loadSearchIndex, mark, RESULT_LIMIT, } from "./search.js";
|
|
11
|
+
export { buildDocSet, crossIssues, folderItems, glossaryOf, homeTypeCardsOf, nameOf, neighboursOf, ordered, PRODUCT_PREFIX, pagesInOrder, RELATED_PER_TYPE, relatedTo, resolveAsset, resolveLink, resourceKey, trailOf, typeCardsOf, UNCATEGORIZED, urlOf, } from "./set.js";
|
|
12
|
+
export { allTerms, attachedTo, clashes, extensionsOf, findTerm, findTopic, } from "./stack.js";
|
|
13
|
+
export { appOf, buildApp, checkWorkspaceDocs, docsApps, FEEDBACK_COLUMNS, FEEDBACK_TABLE, hasFeedbackColumns, isFeedbackTable, pagesOf, resourceChecker, workspaceDocsWarnings, } from "./workspace.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|