Skip to content

Commit dadfe49

Browse files
authored
build(docs): Ensure API docs gen doesn't create "partial" documents (#23147)
Docusaurus treats document files whose names start with `_` as "partial" documents, which don't get included in site output. We have a couple of API exports that start with `_`, and result in files that end up treated as partials. To work around this, we now prepend "u" to any files that would otherwise start with an underscore. "u" is a pretty arbitrary choice. We can't simply remove the underscore, as that would be much more likely to create filename collisions. While it is technically possible that we could export an API item that starts with "u_", doing so would violate our naming conventions, and seems pretty unlikely. If such an API item is added, Docusaurus will start failing on duplicate routes, at which point we can change strategies. See https://docusaurus.io/docs/create-doc for more details on partial documents. [AB#23443](https://dev.azure.com/fluidframework/235294da-091d-4c29-84fc-cdfc3d90890b/_workitems/edit/23443)
1 parent 580a3f7 commit dadfe49

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

docs/docusaurus.config.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ const config: Config = {
5757
// For GitHub pages deployment, it is often '/<projectName>/'
5858
baseUrl: "/",
5959

60-
// Reports many false positives for API documentation
61-
onBrokenAnchors: "ignore",
62-
onBrokenLinks: "warn", // TODO:AB#23443: Set to "throw" once violations have been fixed.
60+
onBrokenAnchors: "throw",
61+
onBrokenLinks: "throw",
6362
onBrokenMarkdownLinks: "throw",
6463
onDuplicateRoutes: "throw",
6564

docs/infra/api-markdown-documenter/render-api-documentation.mjs

+16-3
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,21 @@ export async function renderApiDocumentation(inputDir, outputDir, uriRootDir, ap
123123
return ApiItemUtilities.getUnscopedPackageName(apiItem);
124124
}
125125
default: {
126-
return ApiItemUtilities.getQualifiedApiItemName(apiItem);
126+
const qualifiedName = ApiItemUtilities.getQualifiedApiItemName(apiItem);
127+
let fileName = qualifiedName;
128+
129+
// Docusaurus treats any document name starting with "_" as a "partial" document, which
130+
// will not be included in the site output.
131+
// See: <https://docusaurus.io/docs/create-doc>
132+
// To work around this, while (hopefully) preventing name collisions, we will prefix
133+
// The filename with "u". E.g. `_foo.md` -> `u_foo.md`.
134+
// This doesn't affect displayed contents, strictly changes the resulting filenames and any
135+
// links to them.
136+
if (qualifiedName.startsWith("_")) {
137+
fileName = `u${qualifiedName}`;
138+
}
139+
140+
return fileName;
127141
}
128142
}
129143
},
@@ -169,7 +183,6 @@ export async function renderApiDocumentation(inputDir, outputDir, uriRootDir, ap
169183

170184
// #endregion
171185

172-
// TODO: custom landing pages for API suites?
173186
let fileContents;
174187
try {
175188
const documentBody = MarkdownRenderer.renderDocument(document, {
@@ -189,7 +202,7 @@ export async function renderApiDocumentation(inputDir, outputDir, uriRootDir, ap
189202
);
190203
}
191204

192-
let filePath = path.join(outputDir, `${document.documentPath}.md`);
205+
const filePath = path.join(outputDir, `${document.documentPath}.md`);
193206

194207
try {
195208
await fs.ensureFile(filePath);

docs/skipped-urls.txt

-6
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,3 @@ https://foo-my.sharepoint.com*
3333

3434
# Docusaurus infra
3535
http://localhost:3000/assets/css/styles.*.css
36-
37-
# TODO:AB#23443: Docusaurus ignores doc files whose names begin with "_".
38-
# See https://docusaurus.io/docs/create-doc
39-
# We need to update our API docs build configuration to not emit files starting with "_"s.
40-
http://localhost:3000/docs/api/fluid-framework/internaltypes/_inlinetrick-typealias
41-
http://localhost:3000/docs/api/tree/internaltypes/_inlinetrick-typealias

0 commit comments

Comments
 (0)