Skip to content

Commit dd1918e

Browse files
devin-ai-integration[bot]dsinghvidevalog
authored
Document folder-based navigation configuration (#1765)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Deep Singhvi <[email protected]> Co-authored-by: Devin Logan <[email protected]>
1 parent a4ae921 commit dd1918e

File tree

3 files changed

+106
-43
lines changed

3 files changed

+106
-43
lines changed

fern/docs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ redirects:
307307
destination: /learn/docs/configuration/navigation
308308
- source: /learn/docs/navigation/overview
309309
destination: /learn/docs/configuration/navigation
310+
- source: /learn/docs/configuration/folder-based-navigation
311+
destination: /learn/docs/configuration/navigation
310312
- source: /learn/docs/building-and-customizing-your-docs/versioning
311313
destination: /learn/docs/configuration/versions
312314
- source: /learn/docs/navigation/versions
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Folder-based navigation
2+
3+
Auto-generate navigation from a folder of markdown files using the new `folder` configuration. Instead of manually listing each page in `docs.yml`, point to a folder. Fern discovers all `.md` and `.mdx` files and adds them to the navigation.
4+
5+
```yaml docs.yml {6-10}
6+
navigation:
7+
- section: Getting started
8+
contents:
9+
- page: Introduction
10+
path: ./pages/intro.mdx
11+
- folder: ./pages/guides
12+
title: Guides # Display name for folder section
13+
icon: fa-regular fa-book
14+
collapsed: true
15+
availability: beta # Optional badge to display in navigation
16+
```
17+
18+
Subfolders become nested sections. Supported options: `title`, `slug`, `icon`, `collapsed`, `hidden`, `skip-slug`, `availability`.
19+
20+
[Learn more about navigation configuration](/learn/docs/configuration/navigation).

fern/products/docs/pages/navigation/overview.mdx

Lines changed: 84 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@ title: Configure your site navigation
33
description: Set up the navigation for your documentation site built with Fern Docs using the docs.yml file, including tabs, sections, pages, and more.
44
---
55

6-
## Use `docs.yml`
7-
86
Every Fern Docs website has a special configuration file called `docs.yml`. Use this file to configure the navigation for your documentation site.
97

10-
### Example configuration
11-
128
Here's a complete example of a `docs.yml` file:
139

1410
<CodeBlock title="An example docs.yml">
@@ -20,8 +16,8 @@ navigation:
2016
contents:
2117
- page: Introduction
2218
path: ./intro.mdx
23-
- page: Authentication
24-
path: ./auth.mdx
19+
- folder: ./auth # directory
20+
title: Authentication
2521
- api: API Reference
2622
navbar-links:
2723
- type: secondary
@@ -33,59 +29,77 @@ navbar-links:
3329
```
3430
</CodeBlock>
3531
36-
## Sections, contents, and pages
32+
## Sections, contents, pages, and folders
3733
38-
The navigation organizes your documentation in the left-side nav bar. You can create sections for grouping related content. Each `section` has a name and a list of `contents`. The sections appear in the left-side nav bar in the order listed in `docs.yml`.
34+
Sections organize your documentation in the left-side nav bar. Each `section` has a name and a list of `contents`. Sections appear in the order listed in `docs.yml`.
3935

40-
In `contents`, list your pages with names and corresponding file paths. The supported file types for pages are `.md` or `.mdx`.
36+
In `contents`, you can add individual pages, folders, or both:
4137

42-
A basic navigation configuration with two sections is shown below. The first section is called `Introduction` and contains a single page called `My Page`. The second section is called **API Reference**. This is a special type of section that's automatically generated by Fern, and you don't need to add any pages to it by hand. For more information, see the [Generate API Reference](/learn/docs/api-references/generate-api-ref) page.
38+
- `page` Manually list your pages with names and corresponding file paths.
39+
- `folder` Auto-discover pages from a directory and add them to your navigation.
4340

44-
{/* <!-- vale off --> */}
45-
```yaml Example navigation config
41+
You can combine folder-based navigation with manually defined pages.
42+
43+
<Info title="API Reference section">
44+
Use the special `api` key to create an automatically generated API Reference section. You don't need to add any pages to it manually. For more information, see the [Generate API Reference](/learn/docs/api-references/generate-api-ref) page.
45+
46+
```yaml docs.yml {6}
4647
navigation:
4748
- section: Introduction
4849
contents:
4950
- page: My page
5051
path: ./pages/my-page.mdx
5152
- api: API Reference
5253
```
53-
{/* <!-- vale on --> */}
54-
If you want to add another page to an existing section, create an `.md` or `.mdx` file. Then in `docs.yml`, create a new `page` in the `contents` list for that section, providing the path to the `.md` or `.mdx` file you created. Example:
55-
{/* <!-- vale off --> */}
56-
```yaml Example navigation config
54+
</Info>
55+
56+
<AccordionGroup>
57+
<Accordion title="Add a page">
58+
59+
Create an `.md` or `.mdx` file. Then in `docs.yml`, add a new `page` to the `contents` list, providing the path to the file you created.
60+
61+
```yaml docs.yml
5762
navigation:
5863
- section: Introduction
5964
contents:
6065
- page: My page
6166
path: ./pages/my-page.mdx
6267
- page: Another page
6368
path: ./pages/another-page.mdx
64-
- api: API Reference
6569
```
70+
</Accordion>
71+
<Accordion title="Add a folder">
6672

67-
To add another section, add another `section` to the `navigation`. Example:
73+
Create a directory with one or more `.md` or `.mdx` files. Add a `folder` key to your navigation configuration with the relative path to the directory you just created. Fern discovers all files in the directory and adds them to the navigation.
6874

69-
```yaml Example navigation config with additional section
75+
```yaml docs.yml {4-5}
7076
navigation:
7177
- section: Introduction
7278
contents:
73-
- page: My page
74-
path: ./pages/my-page.mdx
75-
- api: API Reference
76-
- section: Help center
77-
contents:
78-
- page: Contact us
79-
path: contact-us.mdx
79+
- folder: ./pages/getting-started
80+
title: Getting started # Optional, defaults to folder name
8081
```
81-
{/* <!-- vale on --> */}
8282

83-
### Hiding content
83+
For the pages in a folder, Fern automatically converts filenames to titles and URL slugs, creates nested sections from subdirectories, and sorts pages alphabetically.
84+
85+
<Note title="Control page order">
86+
Use frontmatter `position` to control page order. Pages with a `position` field are sorted numerically before alphabetically sorted pages.
87+
```jsx /pages/getting-started/quickstart.mdx
88+
---
89+
title: Quickstart
90+
position: 1
91+
---
92+
```
93+
</Note>
94+
</Accordion>
95+
</AccordionGroup>
96+
97+
## Hiding content
8498

85-
To hide a page or an entire section of your docs, add `hidden: true`. A hidden page or section will still be discoverable using the exact URL, but it will be excluded from search and won't be indexed.
99+
To hide a page, folder, or section, add `hidden: true`. Hidden content (including all pages within a folder) is still accessible via direct URL but is excluded from search and won't be indexed.
86100

87101
{/* <!-- vale off --> */}
88-
```yaml Example navigation config with additional section {7, 10}
102+
```yaml docs.yml {7, 10, 12}
89103
navigation:
90104
- section: Introduction
91105
contents:
@@ -94,6 +108,9 @@ navigation:
94108
- page: Hidden page
95109
hidden: true
96110
path: ./pages/my-hidden-page.mdx
111+
- folder: .pages/features
112+
title: Hidden folder
113+
hidden: true
97114
- section: Hidden sections
98115
hidden: true
99116
contents:
@@ -102,9 +119,9 @@ navigation:
102119
```
103120
{/* <!-- vale on --> */}
104121

105-
### Section and page availability
122+
## Availability
106123

107-
You can set availability for individual pages or entire sections. When you set availability for a section, all pages within that section inherit the same availability unless explicitly overridden at the page level.
124+
Set availability for individual pages, sections, or folders. Pages inherit availability from their parent section or folder unless explicitly overridden.
108125

109126
Options are: `stable`, `generally-available`, `in-development`, `pre-release`, `deprecated`, or `beta`.
110127

@@ -115,19 +132,39 @@ navigation:
115132
contents:
116133
- page: Code examples # Inherits generally-available
117134
path: ./pages/code-examples.mdx
118-
- page: CLI tools # Inherits generally-available
119-
path: ./pages/cli-tools.mdx
135+
- folder: ./pages/cli-tools # Inherits generally-available
136+
title: CLI tools
120137
- page: Testing framework
121138
path: ./pages/testing-framework.mdx
122139
availability: beta # Overrides section-level availability
123-
- page: Performance monitoring
124-
path: ./pages/performance-monitoring.mdx
140+
- folder: ./pages/performance-monitoring
141+
title: Performance monitoring
125142
availability: in-development # Overrides section-level availability
126143
```
127144
<Note>
128-
If you have different versions of your docs, section and page availability should be set in [the `.yml` files that define the navigational structure for each version](/learn/docs/configuration/versions#define-your-versions).
145+
If you have different versions of your docs, section, folder, and page availability should be set in [the `.yml` files that define the navigational structure for each version](/learn/docs/configuration/versions#define-your-versions).
129146
</Note>
130147

148+
## Folder slugs
149+
150+
Specify a custom URL slug for the folder section. If not provided, a slug will be generated from the folder name.
151+
152+
```yaml docs.yml (4)
153+
navigation:
154+
- folder: ./pages/guides
155+
title: Guides
156+
slug: user-guides
157+
```
158+
159+
Skip adding the folder's slug to the URL path. This is useful when you want the pages to appear at the parent level in the URL structure.
160+
161+
```yaml docs.yml {4}
162+
navigation:
163+
- folder: ./pages/guides
164+
title: Guides
165+
skip-slug: true
166+
```
167+
131168
## Section overviews
132169

133170
To add an overview page to a section, add a `path` property to the section.
@@ -177,17 +214,20 @@ navigation:
177214
![Result of above docs.yml example](https://fern-image-hosting.s3.amazonaws.com/fern/nested-sections.png)
178215
</Frame>
179216

180-
## Collapsed sections
217+
## Collapsed sections or folders
181218

182-
You can set sections to be collapsed by default when the page loads by adding `collapsed: true` to a section.
219+
You can set sections or folders to be collapsed by default when the page loads by adding `collapsed: true`.
183220
This helps keep the navigation tidy when you have many sections or want to highlight the most important sections by keeping others collapsed.
184221

185-
```yaml {7} Example config with collapsed section
222+
```yaml {8, 10} Example config with collapsed section
186223
navigation:
187224
- section: Getting started
188225
contents:
189226
- page: Introduction
190227
path: ./pages/intro.mdx
228+
- folder: ./pages/features
229+
title: Features
230+
collapsed: true
191231
- section: Advanced topics
192232
collapsed: true
193233
contents:
@@ -199,20 +239,21 @@ navigation:
199239

200240
## Sidebar icons
201241

202-
Add icons next to sections and pages using the `icon` key.
242+
Add icons next to sections, pages, and folders using the `icon` key.
203243

204244
<Markdown src="/snippets/icons.mdx" />
205245

206246
{/* <!-- vale off --> */}
207-
```yaml Example config with different icon files {3, 6, 9}
247+
```yaml Example config with different icon files {3, 6, 10-11, 14}
208248
navigation:
209249
- section: Home
210250
icon: fa-regular fa-home # Font Awesome icon
211251
contents:
212252
- page: Introduction
213253
icon: ./assets/icons/intro-icon.svg # Custom image file
214254
path: ./pages/intro.mdx
215-
- page: Custom Features
255+
- folder: .pages/features
256+
title: Custom features
216257
icon: "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'><path d='M12 2L2 7v10c0 5.55 3.84 10.74 9 12 5.16-1.26 9-6.45 9-12V7l-10-5z'/></svg>" # Inline SVG
217258
path: ./pages/custom.mdx
218259
- api: API Reference

0 commit comments

Comments
 (0)