-
Notifications
You must be signed in to change notification settings - Fork 13
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
import { existsSync, readFileSync } from "fs"; | ||
import { dirname, resolve, join } from "path"; | ||
import fs from "fs"; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
if (!!item.generateFrom && item.entries.length > 0) { | ||
throw "a navigation item cannot contain both generateFrom and entries"; | ||
} |
There was a problem hiding this comment.
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!
let firstLvlFiles = new Set(); | ||
let firstLvlDirs = new Set(); |
There was a problem hiding this comment.
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.
50a8de8
to
c6d9cdd
Compare
@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 |
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.
Add a
config.json
field within eachnavigation
entry calledgenerateFrom
. This designates a relative path fromdocs/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 calledintroduction.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, hardcodedentries
approach for some sections if we need to.Also un-skips some accidentally skipped tests.