Skip to content

Commit fdd3a6c

Browse files
authored
Use more reasonable sidebar ordering logic (#132)
Closes gravitational/teleport#51030 Closes gravitational/teleport#47231 The Docusaurus sidebar generator currently orders guides within a sidebar section by slug, which makes sidebar labels appear out of order. Instead, apply the following logic, which places page labels in the sidebar in positions where users would expect to find them: - Labels that include "introduction" appear first - Labels that include "get started" or "getting started" appear next - After that, labels in a sidebar section appear in alphabeitcal order This change adds a function that modifies the order of the sidebar items returned by the default Docusaurus sidebar generation function.
1 parent b6b58a9 commit fdd3a6c

File tree

3 files changed

+641
-2
lines changed

3 files changed

+641
-2
lines changed

docusaurus.config.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import "dotenv/config";
22
import type { Config } from "@docusaurus/types";
33
import type { VFile } from "vfile";
44

5+
import { useDocById } from "@docusaurus/plugin-content-docs/client";
56
import { getFromSecretOrEnv } from "./utils/general";
67
import { loadConfig } from "./server/config-docs";
78
import {
@@ -22,6 +23,7 @@ import {
2223
getRootDir,
2324
updatePathsInIncludes,
2425
} from "./server/asset-path-helpers";
26+
import { orderSidebarItems } from "./server/sidebar-order";
2527
import { extendedPostcssConfigPlugin } from "./server/postcss";
2628
import { rehypeHLJS } from "./server/rehype-hljs";
2729
import { definer as hcl } from "highlightjs-terraform";
@@ -154,9 +156,9 @@ const config: Config = {
154156
},
155157
],
156158
[
157-
'@docusaurus/plugin-google-gtag',
159+
"@docusaurus/plugin-google-gtag",
158160
{
159-
trackingID: 'G-Z1BMQRVFH3',
161+
trackingID: "G-Z1BMQRVFH3",
160162
anonymizeIP: true,
161163
},
162164
],
@@ -165,6 +167,33 @@ const config: Config = {
165167
[
166168
"@docusaurus/plugin-content-docs",
167169
{
170+
async sidebarItemsGenerator({
171+
defaultSidebarItemsGenerator,
172+
numberPrefixParser,
173+
item,
174+
version,
175+
docs,
176+
categoriesMetadata,
177+
isCategoryIndex,
178+
}) {
179+
const items = await defaultSidebarItemsGenerator({
180+
defaultSidebarItemsGenerator,
181+
numberPrefixParser,
182+
item,
183+
version,
184+
docs,
185+
categoriesMetadata,
186+
isCategoryIndex,
187+
});
188+
const idToDocPage = new Map();
189+
docs.forEach((d) => {
190+
idToDocPage.set(d.id, d);
191+
});
192+
const getDocPageByID = (id: string) => {
193+
return idToDocPage.get(id);
194+
};
195+
return orderSidebarItems(items, getDocPageByID);
196+
},
168197
// Host docs on the root page, later it will be exposed on goteleport.com/docs
169198
// next to the website and blog
170199
// https://docusaurus.io/docs/docs-introduction#docs-only-mode

0 commit comments

Comments
 (0)