Skip to content

Commit 1d1c5f0

Browse files
docs: add folder-based navigation documentation
Add comprehensive documentation for the new folder configuration feature that allows automatic navigation generation from a folder of markdown files. The documentation covers: - Basic usage and how it works - Filename to title/slug conversion rules - Nested folder support - All configuration options (title, slug, icon, collapsed, hidden, etc.) - Combining folder and manual navigation - Controlling page order with frontmatter - Use cases and real-world examples Includes example from Slack's documentation showing the feature in action. Co-Authored-By: Deep Singhvi <[email protected]>
1 parent e748c3b commit 1d1c5f0

File tree

2 files changed

+261
-0
lines changed

2 files changed

+261
-0
lines changed

fern/products/docs/docs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ navigation:
1919
path: ./pages/customization/what-is-docs-yml.mdx
2020
- page: Navigation
2121
path: ./pages/navigation/overview.mdx
22+
- page: Folder-based navigation
23+
path: ./pages/navigation/folder-based-navigation.mdx
2224
- page: Tabs and tab variants
2325
path: ./pages/navigation/tabs.mdx
2426
slug: tabs
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
---
2+
title: Folder-based navigation
3+
description: Automatically generate navigation from a folder of markdown files in your Fern Docs site.
4+
---
5+
6+
The folder configuration allows you to automatically generate navigation from a folder of markdown files. Instead of manually listing each page in your `docs.yml` file, you can point to a folder and Fern will automatically discover and add all markdown files to your navigation.
7+
8+
This feature is useful when you have many pages in a section and want to avoid manually maintaining the navigation structure, or when you want to quickly add multiple pages without updating the configuration file.
9+
10+
## Basic usage
11+
12+
To use folder-based navigation, add a `folder` key to your navigation configuration with the relative path to a folder containing markdown files:
13+
14+
```yaml docs.yml
15+
navigation:
16+
- section: Getting started
17+
contents:
18+
- page: Introduction
19+
path: ./pages/intro.mdx
20+
- folder: ./pages/guides
21+
title: Guides
22+
```
23+
24+
In this example, Fern will automatically discover all markdown files (`.md` and `.mdx`) in the `./pages/guides` folder and add them to the navigation under a section titled "Guides".
25+
26+
## How it works
27+
28+
When you use the `folder` configuration, Fern:
29+
30+
1. Scans the specified folder for all markdown files (`.md` and `.mdx`)
31+
2. Automatically generates page titles from filenames (e.g., `getting-started.mdx` becomes "Getting Started")
32+
3. Generates URL slugs from filenames (e.g., `getting-started.mdx` becomes `getting-started`)
33+
4. Sorts pages and sections alphabetically by title
34+
5. Creates nested sections for subdirectories
35+
36+
### Filename to title conversion
37+
38+
Fern converts filenames to human-readable titles using the following rules:
39+
40+
- Removes file extensions (`.md` or `.mdx`)
41+
- Replaces hyphens and underscores with spaces
42+
- Capitalizes the first letter of each word
43+
44+
Examples:
45+
- `getting-started.mdx` → "Getting Started"
46+
- `api_reference.md` → "Api Reference"
47+
- `quickstart.mdx` → "Quickstart"
48+
49+
### Filename to slug conversion
50+
51+
Fern converts filenames to URL slugs using the following rules:
52+
53+
- Removes file extensions (`.md` or `.mdx`)
54+
- Converts to lowercase
55+
- Replaces spaces with hyphens
56+
- Removes special characters
57+
58+
Examples:
59+
- `Getting Started.mdx` → `getting-started`
60+
- `API Reference.md` → `api-reference`
61+
- `Quick Start!.mdx` → `quick-start`
62+
63+
## Nested folders
64+
65+
Fern automatically creates nested sections for subdirectories within your folder. Each subdirectory becomes a collapsible section in the navigation.
66+
67+
For example, with this folder structure:
68+
69+
```
70+
pages/
71+
guides/
72+
getting-started.mdx
73+
advanced/
74+
custom-code.mdx
75+
webhooks.mdx
76+
integrations/
77+
slack.mdx
78+
github.mdx
79+
```
80+
81+
And this configuration:
82+
83+
```yaml docs.yml
84+
navigation:
85+
- folder: ./pages/guides
86+
title: Guides
87+
```
88+
89+
Fern will generate this navigation structure:
90+
91+
- Guides
92+
- Getting Started
93+
- Advanced
94+
- Custom Code
95+
- Webhooks
96+
- Integrations
97+
- Slack
98+
- Github
99+
100+
## Configuration options
101+
102+
The `folder` configuration supports several optional properties to customize the generated navigation:
103+
104+
### Title
105+
106+
Specify a custom title for the folder section. If not provided, the folder name will be used.
107+
108+
```yaml docs.yml
109+
navigation:
110+
- folder: ./pages/tech-ref
111+
title: Technical Reference
112+
```
113+
114+
### Slug
115+
116+
Specify a custom URL slug for the folder section. If not provided, a slug will be generated from the folder name.
117+
118+
```yaml docs.yml
119+
navigation:
120+
- folder: ./pages/guides
121+
title: Guides
122+
slug: user-guides
123+
```
124+
125+
### Icon
126+
127+
Add an icon next to the folder section in the navigation.
128+
129+
```yaml docs.yml
130+
navigation:
131+
- folder: ./pages/guides
132+
title: Guides
133+
icon: fa-regular fa-book
134+
```
135+
136+
### Collapsed
137+
138+
Set the folder section to be collapsed by default when the page loads.
139+
140+
```yaml docs.yml
141+
navigation:
142+
- folder: ./pages/advanced
143+
title: Advanced topics
144+
collapsed: true
145+
```
146+
147+
### Hidden
148+
149+
Hide the folder section from the navigation. The pages will still be accessible via direct URLs but won't appear in the sidebar.
150+
151+
```yaml docs.yml
152+
navigation:
153+
- folder: ./pages/internal
154+
title: Internal documentation
155+
hidden: true
156+
```
157+
158+
### Skip slug
159+
160+
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.
161+
162+
```yaml docs.yml
163+
navigation:
164+
- folder: ./pages/guides
165+
title: Guides
166+
skip-slug: true
167+
```
168+
169+
### Availability
170+
171+
Set the availability status for all pages in the folder section. Options are `stable`, `generally-available`, `in-development`, `pre-release`, `deprecated`, or `beta`.
172+
173+
```yaml docs.yml
174+
navigation:
175+
- folder: ./pages/beta-features
176+
title: Beta features
177+
availability: beta
178+
```
179+
180+
## Combining folder and manual navigation
181+
182+
You can combine folder-based navigation with manually defined pages and sections. This allows you to have some pages automatically discovered while maintaining explicit control over others.
183+
184+
```yaml docs.yml
185+
navigation:
186+
- section: Overview
187+
contents:
188+
- page: Introduction
189+
path: ./pages/intro.mdx
190+
191+
- folder: ./pages/guides
192+
title: Guides
193+
194+
- page: FAQ
195+
path: ./pages/faq.mdx
196+
```
197+
198+
In this example, the "Overview" section contains a manually defined "Introduction" page, followed by all pages from the `guides` folder, and then a manually defined "FAQ" page.
199+
200+
## Controlling page order with frontmatter
201+
202+
By default, pages discovered from a folder are sorted alphabetically by their generated titles. To control the order of pages, you can add a `position` field to the frontmatter of your markdown files:
203+
204+
```mdx getting-started.mdx
205+
---
206+
title: Getting started
207+
position: 1
208+
---
209+
210+
Your content here...
211+
```
212+
213+
```mdx advanced-topics.mdx
214+
---
215+
title: Advanced topics
216+
position: 2
217+
---
218+
219+
Your content here...
220+
```
221+
222+
Pages with a `position` field will be sorted numerically before alphabetically sorted pages. Pages without a `position` field will appear after positioned pages in alphabetical order.
223+
224+
## Use cases
225+
226+
Folder-based navigation is particularly useful in these scenarios:
227+
228+
**Large documentation sets**: When you have dozens or hundreds of pages, manually maintaining the navigation structure in `docs.yml` becomes tedious. Folder-based navigation lets you organize pages in the filesystem and have the navigation generated automatically.
229+
230+
**Frequently updated content**: If you regularly add new pages to a section, folder-based navigation eliminates the need to update `docs.yml` every time you add a page.
231+
232+
**Changelog or blog sections**: For date-based content like changelogs, you can organize files by date in a folder and have them automatically appear in the navigation.
233+
234+
**Team collaboration**: When multiple team members are adding documentation, folder-based navigation reduces merge conflicts in the `docs.yml` file since new pages don't require configuration changes.
235+
236+
## Example from Slack
237+
238+
Here's a real-world example from Slack's documentation that combines manually defined pages with folder-based navigation:
239+
240+
```yaml docs.yml
241+
navigation:
242+
- tab: overview
243+
layout:
244+
- page: Introduction
245+
path: ../../docs/pages/realtime-server-sdk/v4/index.mdx
246+
247+
- folder: ../../docs/pages/realtime-server-sdk/v4/tech-ref
248+
title: Technical Reference
249+
250+
- folder: ../../docs/pages/realtime-server-sdk/v4/guides
251+
title: Guides
252+
```
253+
254+
In this configuration:
255+
- The "Introduction" page is explicitly defined with a specific path
256+
- The "Technical Reference" section is automatically generated from all files in the `tech-ref` folder
257+
- The "Guides" section is automatically generated from all files in the `guides` folder
258+
259+
This approach provides a clean balance between explicit control for important pages and automatic discovery for content-heavy sections.

0 commit comments

Comments
 (0)