Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate docs sidebar sections automatically #480

Merged
merged 1 commit into from
Jul 2, 2024

Conversation

ptgott
Copy link
Contributor

@ptgott ptgott commented Jul 1, 2024

Add a config.json field within each navigation entry called generateFrom. This designates a relative path from docs/pages from which to generate entries within the sidebar.

When generating pages, a function called generateNavPaths looks for pages to use as second-level section introductions. These can either be called introduction.mdx or have the same name as a second-level subdirectory.

Adding a generateFrom field is consistent with the Docusaurus approach to sidebar generation, in which a configuration field indicates which directory to generate a section from. This gives us control over the title and icons we use for navigation sections, which aren't available to fetch from a directory tree alone. It also lets us use the current, hardcoded entries approach for some sections if we need to.

Also un-skips some accidentally skipped tests.

@ptgott ptgott requested a review from avatus as a code owner July 1, 2024 17:15
Copy link

vercel bot commented Jul 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 1, 2024 7:20pm

avatus
avatus previously approved these changes Jul 1, 2024
import { existsSync, readFileSync } from "fs";
import { dirname, resolve, join } from "path";
import fs from "fs";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine, but wondering why the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generateNavPaths takes fs as an argument so I can use the in-memory fs from the memfs package in tests!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see now. That's awesome

Comment on lines +332 to +334
if (!!item.generateFrom && item.entries.length > 0) {
throw "a navigation item cannot contain both generateFrom and entries";
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for the check here!

Comment on lines +78 to +79
let firstLvlFiles = new Set();
let firstLvlDirs = new Set();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new Set() 😎

Add a `config.json` field within each `navigation` entry called
`generateFrom`. This designates a relative path from `docs/pages` from
which to generate entries within the sidebar.

When generating pages, a function called `generateNavPaths` looks for
pages to use as second-level section introductions. As with the
Docusaurus convention, second-level section introductions have the same
name as their parent directory.

Adding a `generateFrom` field is consistent with the Docusaurus
approach to sidebar generation, in which a configuration field indicates
which directory to generate a section from. This gives us control over
the title and icons we use for navigation sections, which aren't
available to fetch from a directory tree alone. It also lets us use the
current, hardcoded `entries` approach for some sections if we need to.

Also un-skips some accidentally skipped tests.
@ptgott
Copy link
Contributor Author

ptgott commented Jul 1, 2024

@avatus I've reworked this a little bit to change the expectations for subdirectory pages. I've added the expectation from Docusaurus that a category page have the same title as the parent directory (docs). Docusaurus also allows category pages to be called index.mdx and README.mdx, but Alexey advised against using index.mdx for non-root pages and README.mdx doesn't seem appropriate.

@ptgott ptgott merged commit 0dd8f1b into main Jul 2, 2024
9 checks passed
travelton pushed a commit that referenced this pull request Aug 26, 2024
Add a `config.json` field within each `navigation` entry called
`generateFrom`. This designates a relative path from `docs/pages` from
which to generate entries within the sidebar.

When generating pages, a function called `generateNavPaths` looks for
pages to use as second-level section introductions. As with the
Docusaurus convention, second-level section introductions have the same
name as their parent directory.

Adding a `generateFrom` field is consistent with the Docusaurus
approach to sidebar generation, in which a configuration field indicates
which directory to generate a section from. This gives us control over
the title and icons we use for navigation sections, which aren't
available to fetch from a directory tree alone. It also lets us use the
current, hardcoded `entries` approach for some sections if we need to.

Also un-skips some accidentally skipped tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants