Skip to content

Commit 6076f48

Browse files
authored
build(docs): Update api-markdown-documenter and utilize new hierarchy options (microsoft#23504)
Update dev dependency on `@fluid-tools/api-markdown-documenter` and leverage new "hierarchy" capabilities to move "folder" item documents (packages and namespaces) _into_ their folders, renamed to `index`. E.g., File structure before: ``` | fluid-framework.md | fluid-framework | foo.md | ... ``` After: ``` | fluid-framework | index.md | foo.md | ... ``` This makes the breadcrumbs and navigation drop-downs generated by docusaurus better match the intended hierarchy. E.g., Namespace appearance in the nav before: ![image](https://github.com/user-attachments/assets/37fb8974-b306-4b37-a9df-2ec53052faf4) - Note that there is a separate page and folder, and selecting the folder doesn't navigate to the page; it just functions as a drop-down. Namespace appearance after: ![image](https://github.com/user-attachments/assets/7ab5e37e-817b-495f-a569-8c00a2c360d6) Breadcrumb before: ![image](https://github.com/user-attachments/assets/adba1322-f2a8-40a3-ad07-2d4b607ba918) - Note that the parent folder isn't selectable, because Docusaurus doesn't understand that it's supposed to point to the document of the same name. Breadcrumb after: ![image](https://github.com/user-attachments/assets/d74f49bb-62ba-4dcc-a5d1-dd8a3ec70539) - Note that the parent entry is now selectable (screenshot was taken with mouse hovering over item) [AB#24263](https://dev.azure.com/fluidframework/235294da-091d-4c29-84fc-cdfc3d90890b/_workitems/edit/24263)
1 parent 4c06412 commit 6076f48

File tree

10 files changed

+10547
-8547
lines changed

10 files changed

+10547
-8547
lines changed

docs/.gitignore

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ versions.json
1414

1515
# Generated API docs.
1616
# Note: keep `mdx` files that are handwritten
17-
docs/api/*
18-
!docs/api/**/*.mdx
19-
versioned_docs/*/api/*
20-
!versioned_docs/*/api/**/*.mdx
17+
docs/api
18+
!docs/api/index.mdx
19+
versioned_docs/*/api
20+
!versioned_docs/*/api/index.mdx
21+
!versioned_docs/*/api/fluid-framework/index.mdx
2122

2223
# Test
2324
test-results

docs/docs/api/index.mdx

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ sidebar_position: 10
66

77
{/* Note: these contents are new and should be reviewed. The current website's API docs landing page has no description about what the packages do / when to use them. It's not very useful. */}
88

9-
To get started with the Fluid Framework, you'll want to take a dependency on our client library, [fluid-framework](./fluid-framework.md).
9+
To get started with the Fluid Framework, you'll want to take a dependency on our client library, [fluid-framework](./fluid-framework/index.md).
1010

1111
You'll then want to pair that with the appropriate service client implementation based on your service.
1212
These include:
1313

14-
- [@fluidframework/azure-client](./azure-client.md) (for use with [Azure Fluid Relay](../deployment/azure-fluid-relay.mdx))
15-
- [@fluidframework/odsp-client](./odsp-client.md) (for use with [SharePoint Embedded](../deployment/sharepoint-embedded.mdx))
16-
- [@fluidframework/tinylicious-client](./tinylicious-client.md) (for testing with [Tinylicious](../testing/tinylicious.mdx))
14+
- [@fluidframework/azure-client](./azure-client/index.md) (for use with [Azure Fluid Relay](../deployment/azure-fluid-relay.mdx))
15+
- [@fluidframework/odsp-client](./odsp-client/index.md) (for use with [SharePoint Embedded](../deployment/sharepoint-embedded.mdx))
16+
- [@fluidframework/tinylicious-client](./tinylicious-client/index.md) (for testing with [Tinylicious](../testing/tinylicious.mdx))
1717

1818
For more information on our service client implementations, see [Fluid Services](../deployment/service-options.mdx).

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

+37-34
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ApiItemUtilities,
99
DocumentationNodeType,
1010
getApiItemTransformationConfigurationWithDefaults,
11+
HierarchyKind,
1112
loadModel,
1213
MarkdownRenderer,
1314
ReleaseTag,
@@ -78,13 +79,42 @@ export async function renderApiDocumentation(inputDir, outputDir, uriRootDir, ap
7879

7980
const config = getApiItemTransformationConfigurationWithDefaults({
8081
apiModel,
81-
documentBoundaries: [
82-
ApiItemKind.Class,
83-
ApiItemKind.Enum,
84-
ApiItemKind.Interface,
85-
ApiItemKind.Namespace,
86-
ApiItemKind.TypeAlias,
87-
],
82+
hierarchy: {
83+
[ApiItemKind.Model]: HierarchyKind.Document,
84+
[ApiItemKind.Namespace]: HierarchyKind.Folder,
85+
[ApiItemKind.Package]: HierarchyKind.Folder,
86+
getDocumentName: (apiItem, hierarchyConfig) => {
87+
switch (apiItem.kind) {
88+
case ApiItemKind.Model:
89+
// We inject a custom landing page ("index.mdx") for a curated package reference.
90+
// So we will give the auto-generated / complete model page its own separate document.
91+
return "package-reference";
92+
93+
case ApiItemKind.Namespace:
94+
case ApiItemKind.Package:
95+
// Namespace and package items generate documents within their own folder.
96+
return "index";
97+
default:
98+
let documentName = ApiItemUtilities.createQualifiedDocumentNameForApiItem(
99+
apiItem,
100+
hierarchyConfig,
101+
);
102+
103+
// Docusaurus treats any document name starting with "_" as a "partial" document, which
104+
// will not be included in the site output.
105+
// See: <https://docusaurus.io/docs/create-doc>
106+
// To work around this, while (hopefully) preventing name collisions, we will prefix
107+
// The filename with "u". E.g. `_foo.md` -> `u_foo.md`.
108+
// This doesn't affect displayed contents, strictly changes the resulting filenames and any
109+
// links to them.
110+
if (documentName.startsWith("_")) {
111+
documentName = `u${documentName}`;
112+
}
113+
114+
return documentName;
115+
}
116+
},
117+
},
88118
newlineKind: "lf",
89119
uriRoot: uriRootDir,
90120
includeBreadcrumb: false, // Docusaurus includes this by default based on file hierarchy
@@ -111,33 +141,6 @@ export async function renderApiDocumentation(inputDir, outputDir, uriRootDir, ap
111141
}
112142
return alerts;
113143
},
114-
getFileNameForItem: (apiItem) => {
115-
switch (apiItem.kind) {
116-
case ApiItemKind.Model: {
117-
return "package-reference";
118-
}
119-
case ApiItemKind.Package: {
120-
return ApiItemUtilities.getUnscopedPackageName(apiItem);
121-
}
122-
default: {
123-
const qualifiedName = ApiItemUtilities.getQualifiedApiItemName(apiItem);
124-
let fileName = qualifiedName;
125-
126-
// Docusaurus treats any document name starting with "_" as a "partial" document, which
127-
// will not be included in the site output.
128-
// See: <https://docusaurus.io/docs/create-doc>
129-
// To work around this, while (hopefully) preventing name collisions, we will prefix
130-
// The filename with "u". E.g. `_foo.md` -> `u_foo.md`.
131-
// This doesn't affect displayed contents, strictly changes the resulting filenames and any
132-
// links to them.
133-
if (qualifiedName.startsWith("_")) {
134-
fileName = `u${qualifiedName}`;
135-
}
136-
137-
return fileName;
138-
}
139-
}
140-
},
141144
skipPackage: (apiPackage) => {
142145
const packageName = apiPackage.displayName;
143146
const packageScope = PackageName.getScope(packageName);

docs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"@docusaurus/tsconfig": "^3.6.2",
7171
"@docusaurus/types": "^3.6.2",
7272
"@easyops-cn/docusaurus-search-local": "^0.45.0",
73-
"@fluid-tools/api-markdown-documenter": "^0.17.2",
73+
"@fluid-tools/api-markdown-documenter": "^0.18.0",
7474
"@fluid-tools/markdown-magic": "file:../tools/markdown-magic",
7575
"@fluidframework/build-common": "^2.0.3",
7676
"@fluidframework/eslint-config-fluid": "^5.5.1",

0 commit comments

Comments
 (0)