Skip to content

Commit f7870ad

Browse files
authored
Merge pull request #1841 from hydephp/clean-up-the-navigation-documentation
Move the sidebar documentation to the documentation pages page
2 parents 51edfbe + c802a5a commit f7870ad

File tree

4 files changed

+125
-80
lines changed

4 files changed

+125
-80
lines changed

docs/creating-content/documentation-pages.md

Lines changed: 111 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,39 @@ navigation:
100100
priority: 5
101101
```
102102
103-
You can also change the order in the `config/docs.php` configuration file, which may be easier to manage for larger sites. See [the chapter in the customization page](customization#navigation-menu--sidebar) for more details.
103+
You can also change the order in the `config/docs.php` configuration file, which may be easier to manage for larger sites.
104+
105+
#### Basic Priority Syntax
106+
107+
A nice and simple way to define the order of pages is to add their route keys as a simple list array. Hyde will then match that array order.
108+
109+
It may be useful to know that Hyde internally will assign a priority calculated according to its position in the list, plus an offset of `500`. The offset is added to make it easier to place pages earlier in the list using front matter or with explicit priority settings.
110+
111+
```php
112+
// filepath: config/docs.php
113+
'sidebar' => [
114+
'order' => [
115+
'readme', // Priority: 500
116+
'installation', // Priority: 501
117+
'getting-started', // Priority: 502
118+
]
119+
]
120+
```
121+
122+
#### Explicit Priority Syntax
123+
124+
You can also specify explicit priorities by adding a value to the array keys. Hyde will then use these exact values as the priorities.
125+
126+
```php
127+
// filepath: config/docs.php
128+
'sidebar' => [
129+
'order' => [
130+
'readme' => 10,
131+
'installation' => 15,
132+
'getting-started' => 20,
133+
]
134+
]
135+
```
104136

105137
### Sidebar Labels
106138

@@ -130,13 +162,11 @@ navigation:
130162

131163
#### Automatic Subdirectory-Based Grouping
132164

133-
You can also automatically group your documentation pages by placing source files in sub-directories.
165+
You can also automatically group your documentation pages by placing source files in subdirectories.
134166

135167
For example, putting a Markdown file in `_docs/getting-started/` is equivalent to adding the same front matter seen above.
136168

137-
>info Note that when the [flattened output paths](#using-flattened-output-paths) setting is enabled (which it is by default), the file will still be compiled to the `_site/docs/` directory like it would be if you didn't use the subdirectories. Note that this means that you can't have two documentation pages with the same filename as they would overwrite each other.
138-
139-
>info Tip: When using subdirectory-based grouping, you can set the priority of the groups using the directory name as the array key in the config file.
169+
>warning Note that when the [flattened output paths](#using-flattened-output-paths) setting is enabled (which it is by default), the file will still be compiled to the `_site/docs/` directory like it would be if you didn't use the subdirectories. Note that this means that you can't have two documentation pages with the same filename as they would overwrite each other.
140170

141171
### Hiding Items
142172

@@ -213,11 +243,9 @@ To quickly arrange the order of items in the sidebar, you can reorder the page i
213243

214244
See [the chapter in the customization page](customization#navigation-menu--sidebar) for more details. <br>
215245

216-
### Automatic Sidebar Group Labels
217-
218-
When using the automatic sidebar grouping feature (based on subdirectories), the titles of the groups are generated from the directory names. If these are not to your liking, for example if you need to use special characters, you can override them in the Docs configuration file. The array key is the directory name, and the value is the label.
246+
### Setting Sidebar Group Labels
219247

220-
Please note that this option is not added to the config file by default, as it's not a super common use case. No worries though, just add the following yourself!
248+
When using the automatic sidebar grouping feature the titles of the groups are generated from the subdirectory names. If these are not to your liking, for example if you need to use special characters, you can override them in the configuration file. The array key is the directory name, and the value is the label.
221249

222250
```php
223251
// Filepath: config/docs.php
@@ -227,6 +255,80 @@ Please note that this option is not added to the config file by default, as it's
227255
],
228256
```
229257

258+
Please note that this option is not added to the config file by default, as it's not a super common use case. No worries though, just add the following yourself!
259+
260+
#### Setting Sidebar Group Priorities
261+
262+
By default, each group will be assigned the lowest priority found inside the group. However, you can specify the order and priorities for sidebar group keys the same way you can for the sidebar items.
263+
264+
Just use the sidebar group key as instead of the page identifier/route key:
265+
266+
```php
267+
// Filepath: config/docs.php
268+
'sidebar' => [
269+
'order' => [
270+
'readme',
271+
'installation',
272+
'getting-started',
273+
],
274+
],
275+
```
276+
277+
### Numerical Prefix Sidebar Ordering
278+
279+
HydePHP v2 introduces sidebar item ordering based on numerical prefixes in filenames. This feature works for the documentation sidebar.
280+
281+
This has the great benefit of matching the sidebar layout with the file structure view. It also works especially well with subdirectory-based sidebar grouping.
282+
283+
```shell
284+
_docs/
285+
01-installation.md # Priority: 1
286+
02-configuration.md # Priority: 2
287+
03-usage.md # Priority: 3
288+
```
289+
290+
As you can see, Hyde parses the number from the filename and uses it as the priority for the page in the sidebar, while stripping the prefix from the route key.
291+
292+
#### Important Notes
293+
294+
1. The numerical prefix remains part of the page identifier but is stripped from the route key.
295+
For example: `_docs/01-installation.md` has route key `installation` and page identifier `01-installation`.
296+
2. You can delimit the numerical prefix with either a dash or an underscore.
297+
For example: Both `_docs/01-installation.md` and `_docs/01_installation.md` are valid.
298+
3. Leading zeros are optional. `_docs/1-installation.md` is equally valid.
299+
300+
#### Using Numerical Prefix Ordering in Subdirectories
301+
302+
This feature integrates well with automatic subdirectory-based sidebar grouping. Here's an example of how you could organize a documentation site:
303+
304+
```shell
305+
_docs/
306+
01-getting-started/
307+
01-installation.md
308+
02-requirements.md
309+
03-configuration.md
310+
02-usage/
311+
01-quick-start.md
312+
02-advanced-usage.md
313+
03-features/
314+
01-feature-1.md
315+
02-feature-2.md
316+
```
317+
318+
Here are two useful tips:
319+
320+
1. You can use numerical prefixes in subdirectories to control the sidebar group order.
321+
2. The numbering within a subdirectory works independently of its siblings, so you can start from one in each subdirectory.
322+
323+
#### Customization
324+
325+
If you're not interested in using numerical prefix ordering, you can disable it in the Hyde config file. Hyde will then no longer extract the priority and will no longer strip the prefix from the route key.
326+
327+
```php
328+
// filepath: config/hyde.php
329+
'numerical_page_ordering' => false,
330+
```
331+
230332
### Table of Contents Settings
231333

232334
Hyde automatically generates a table of contents for the page and adds it to the sidebar.

docs/digging-deeper/customization.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,18 @@ Still, you will likely want to customize some parts of these menus, and thankful
283283

284284
- To customize the navigation menu, use the setting `navigation.order` in the `hyde.php` config.
285285
- When customizing the navigation menu, you should use the [route key](core-concepts#route-keys) of the page.
286+
- You can use either a basic list array or specify explicit priorities.
286287

287288
Learn more in the [Navigation Menu](navigation) documentation.
288289

289290
#### Customizing the documentation sidebar
290291

291292
- To customize the sidebar, use the setting `sidebar.order` in the `docs.php` config.
292-
- When customizing the sidebar, can use the route key, or just the [page identifier](core-concepts#page-identifiers) of the page.
293+
- When customizing the sidebar, you can use the route key, or just the [page identifier](core-concepts#page-identifiers) of the page.
294+
- Similar to the navigation menu, you can use a basic list array or specify explicit priorities.
295+
- You can also use front matter in individual documentation pages to customize their appearance and behavior in the sidebar.
293296

294-
Learn more in the [Documentation Pages](documentation-pages) documentation.
297+
Learn more in the [Documentation Pages](documentation-pages#sidebar) documentation.
295298

296299
## Additional Advanced Options
297300

docs/digging-deeper/navigation.md

Lines changed: 8 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ navigation:
88

99
## Introduction
1010

11-
HydePHP offers automatic navigation menu and documentation sidebar generation features, designed to take the pain out of creating navigation menus.
11+
HydePHP offers automatic navigation menu generation features, designed to take the pain out of creating navigation menus.
1212
While Hyde does its best to configure these menus automatically based on understanding your project files, you may want to customize them further.
1313

1414
There are two types of navigation menus in Hyde:
1515

1616
1. **Primary Navigation Menu**: The main navigation menu appearing on most pages of your site. Unique features include dropdowns for subdirectories, depending on configuration.
1717
2. **Documentation Sidebar**: The sidebar on documentation pages with links to other documentation pages. Unique features include automatic grouping based on subdirectories.
1818

19-
This documentation will guide you through the customization process. To learn even more about sidebars, visit the [Documentation Pages](documentation-pages) documentation.
19+
This documentation will guide you through the customization process of the primary navigation menu. To learn about the documentation sidebar, visit the [Documentation Pages](documentation-pages) documentation.
2020

2121
### Internal Structure Overview
2222

@@ -43,11 +43,10 @@ Hyde provides multiple ways to customize navigation menus to suit your needs:
4343

4444
1. Front matter data in Markdown and Blade page files, applicable to all menu types
4545
2. Configuration in the `hyde` config file for main navigation items
46-
3. Configuration in the `docs` config file for documentation sidebar items
4746

4847
Keep in mind that front matter data overrides dynamically inferred or config-defined priorities. While useful for quick one-off changes on small sites, it can make reordering items later on more challenging as you can't see the entire structure at once.
4948

50-
Additionally, general options for the entire navigation menus are also available in the `hyde` and `docs` config files.
49+
Additionally, general options for the entire navigation menus are also available in the `hyde` config file.
5150

5251
## Front Matter Configuration
5352

@@ -105,16 +104,15 @@ navigation:
105104

106105
## Config File Configuration
107106

108-
Let's explore how to customize navigation menus using configuration files:
107+
Let's explore how to customize the main navigation menu using configuration files:
109108

110109
- For the main navigation menu, use the `navigation` setting in the `hyde.php` config file.
111-
- For the sidebar, use the `sidebar` setting in the `docs.php` config file.
112110

113-
When customizing the main navigation menu, use the [route key](core-concepts#route-keys) of the page. For the sidebar, you can use either the route key or the [page identifier](core-concepts#page-identifiers).
111+
When customizing the main navigation menu, use the [route key](core-concepts#route-keys) of the page.
114112

115113
### Changing Priorities
116114

117-
The `navigation.order` and `sidebar.order` settings allow you to customize the order of pages in the navigation menus.
115+
The `navigation.order` setting allows you to customize the order of pages in the main navigation menu.
118116

119117
#### Basic Priority Syntax
120118

@@ -133,17 +131,6 @@ It may be useful to know that we internally will assign a priority calculated ac
133131
]
134132
```
135133

136-
```php
137-
// filepath: config/docs.php
138-
'sidebar' => [
139-
'order' => [
140-
'readme', // Priority: 500
141-
'installation', // Priority: 501
142-
'getting-started', // Priority: 502
143-
]
144-
]
145-
```
146-
147134
#### Explicit Priority Syntax
148135

149136
You can also specify explicit priorities by adding a value to the array keys. We'll then use these exact values as the priorities.
@@ -159,28 +146,6 @@ You can also specify explicit priorities by adding a value to the array keys. We
159146
]
160147
```
161148

162-
```php
163-
// filepath: config/docs.php
164-
'sidebar' => [
165-
'order' => [
166-
'readme' => 10,
167-
'installation' => 15,
168-
'getting-started' => 20,
169-
]
170-
]
171-
```
172-
173-
You could also combine these methods if desired:
174-
175-
```php
176-
// filepath: Applicable to both
177-
[
178-
'readme' => 10, // Priority: 10
179-
'installation', // Priority: 500
180-
'getting-started', // Priority: 501
181-
]
182-
```
183-
184149
### Changing Menu Item Labels
185150

186151
Hyde makes a few attempts to find suitable labels for the navigation menu items to automatically create helpful titles.
@@ -197,8 +162,6 @@ If you're not happy with these, it's easy to override navigation link labels by
197162
]
198163
```
199164

200-
**Note:** This feature is not yet supported for the sidebar.
201-
202165
### Excluding Items (Blacklist)
203166

204167
When you have many pages, it may be useful to prevent links from being added to the main navigation menu.
@@ -268,22 +231,14 @@ Enable this feature in the `hyde.php` config file by setting the `subdirectory_d
268231

269232
Now if you create a page called `_pages/about/contact.md`, it will automatically be placed in a dropdown called "About".
270233

271-
#### Automatic Documentation Sidebar Grouping
272-
273-
This feature is always enabled for documentation pages. Simply place your pages in subdirectories to have them grouped in the sidebar.
274-
275-
For example: `_docs/getting-started/installation.md` will be placed in a group called "Getting Started".
276-
277-
>info Tip: When using subdirectory-based dropdowns, you can set their priority using the directory name as the array key.
278-
279234
#### Dropdown Menu Notes
280235

281236
- Dropdowns take priority over standard items. If you have a dropdown with the key `about` and a page with the key `about`, the dropdown will be created, and the page won't be in the menu.
282237
- Example: With this file structure: `_pages/foo.md`, `_pages/foo/bar.md`, `_pages/foo/baz.md`, the link to `foo` will be lost, so please keep this in mind when using this feature.
283238

284239
## Numerical Prefix Navigation Ordering
285240

286-
HydePHP v2 introduces navigation item ordering based on numerical prefixes in filenames. This feature works for both the primary navigation menu and the documentation sidebar.
241+
HydePHP v2 introduces navigation item ordering based on numerical prefixes in filenames. This feature works for the primary navigation menu.
287242

288243
This has the great benefit of matching the navigation menu layout with the file structure view. It also works especially well with subdirectory-based navigation grouping.
289244

@@ -308,25 +263,9 @@ As you can see, Hyde parses the number from the filename and uses it as the prio
308263

309264
This feature integrates well with automatic subdirectory-based navigation grouping. Here are two useful tips:
310265

311-
1. You can use numerical prefixes in subdirectories to control the dropdown/sidebar order.
266+
1. You can use numerical prefixes in subdirectories to control the dropdown order.
312267
2. The numbering within a subdirectory works independently of its siblings, so you can start from one in each subdirectory.
313268

314-
Here is an example structure of how you could organize a documentation site:
315-
316-
```shell
317-
_docs/
318-
01-getting-started/
319-
01-installation.md
320-
02-requirements.md
321-
03-configuration.md
322-
02-usage/
323-
01-quick-start.md
324-
02-advanced-usage.md
325-
03-features/
326-
01-feature-1.md
327-
02-feature-2.md
328-
```
329-
330269
### Customization
331270

332271
If you're not interested in using numerical prefix ordering, you can disable it in the Hyde config file. Hyde will then no longer extract the priority and will no longer strip the prefix from the route key.

packages/framework/src/Framework/Features/Navigation/NavigationMenuGenerator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ protected function normalizeGroupLabel(string $label): string
194194

195195
protected function searchForGroupLabelInConfig(string $groupKey): ?string
196196
{
197+
// TODO: Normalize this: sidebar_group_labels -> docs.sidebar.labels
197198
return $this->getConfigArray($this->generatesSidebar ? 'docs.sidebar_group_labels' : 'hyde.navigation.labels')[$groupKey] ?? null;
198199
}
199200

0 commit comments

Comments
 (0)