Skip to content

Commit c9abfa2

Browse files
authored
Merge pull request #1818 from hydephp/unify-the-navigation-api
[2.x] Unify the Navigation API
2 parents 0a4b35b + e2cdca6 commit c9abfa2

29 files changed

+1469
-427
lines changed

RELEASE_NOTES.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ This serves two purposes:
1515
- Added a new `\Hyde\Framework\Exceptions\ParseException` exception class to handle parsing exceptions in data collection files in https://github.com/hydephp/develop/pull/1732
1616
- Added a new `\Hyde\Framework\Exceptions\InvalidConfigurationException` exception class to handle invalid configuration exceptions in https://github.com/hydephp/develop/pull/1799
1717
- The `\Hyde\Facades\Features` class is no longer marked as internal, and is now thus part of the public API.
18+
- Added support for setting custom navigation items in the YAML configuration in https://github.com/hydephp/develop/pull/1818
19+
- Added support for setting extra attributes for navigation items in https://github.com/hydephp/develop/pull/1824
20+
- Introduced a new navigation config builder class to simplify navigation configuration in https://github.com/hydephp/develop/pull/1827
1821

1922
### Changed
2023
- **Breaking:** The internals of the navigation system has been rewritten into a new Navigation API. This change is breaking for custom navigation implementations. For more information, see below.
@@ -23,6 +26,8 @@ This serves two purposes:
2326
- **Breaking:** The `hyde.authors` config setting should now be keyed by the usernames. For more information, see below.
2427
- **Breaking:** The `Author::create()` method now returns an array instead of a `PostAuthor` instance. For more information, see below.
2528
- **Breaking:** The `Author::get()` method now returns `null` if an author is not found, rather than creating a new instance. For more information, see below.
29+
- **Breaking:** The custom navigation item configuration now uses array inputs instead of the previous format. For more information, see the upgrade guide below.
30+
- **Breaking:** Renamed the `hyde.navigation.subdirectories` configuration option to `hyde.navigation.subdirectory_display`.
2631
- Medium: The `route` function will now throw a `RouteNotFoundException` if the route does not exist in https://github.com/hydephp/develop/pull/1741
2732
- Minor: Navigation menu items are now no longer filtered by duplicates (meaning two items with the same label can now exist in the same menu) in https://github.com/hydephp/develop/pull/1573
2833
- Minor: Due to changes in the navigation system, it is possible that existing configuration files will need to be adjusted in order for menus to look the same (in terms of ordering etc.)
@@ -43,6 +48,8 @@ This serves two purposes:
4348
- Calling the `DataCollection` methods will no longer create the data collections directory in https://github.com/hydephp/develop/pull/1732
4449
- Markdown includes are now converted to HTML using the custom HydePHP Markdown service, meaning they now support full GFM spec and custom Hyde features like colored blockquotes and code block filepath labels in https://github.com/hydephp/develop/pull/1738
4550
- Markdown returned from includes are now trimmed of trailing whitespace and newlines in https://github.com/hydephp/develop/pull/1738
51+
- Reorganized and cleaned up the navigation and sidebar documentation for improved clarity.
52+
- Moved the sidebar documentation to the documentation pages section for better organization.
4653

4754
### Deprecated
4855
- for soon-to-be removed features.
@@ -333,3 +340,78 @@ For example, an empty or malformed JSON file will now throw an exception like th
333340

334341
In order to normalize the thrown exceptions, we now rethrow the `ParseException` from `Symfony/Yaml` as our custom `ParseException` to match the JSON and Markdown validation.
335342
Additionally, an exception will be thrown if a data file is empty, as this is unlikely to be intentional. Markdown files can have an empty body if front matter is present.
343+
344+
## New features
345+
346+
<!-- Editors note: Todo: Maybe move to the relevant docs... -->
347+
348+
### Navigation configuration changes
349+
350+
The custom navigation item configuration format has been updated to use array inputs. This change allows for more flexibility and consistency in defining navigation items.
351+
352+
#### Old format:
353+
354+
```php
355+
'navigation' => [
356+
'custom_items' => [
357+
'Custom Item' => '/custom-page',
358+
],
359+
],
360+
```
361+
362+
#### New format:
363+
364+
```php
365+
'navigation' => [
366+
'custom_items' => [
367+
['label' => 'Custom Item', 'destination' => '/custom-page'],
368+
],
369+
],
370+
```
371+
372+
Additionally, the `hyde.navigation.subdirectories` configuration option has been renamed to `hyde.navigation.subdirectory_display`. Update your configuration files accordingly.
373+
374+
### YAML configuration for navigation items
375+
376+
You can now set custom navigation items directly in your YAML configuration files. This provides an alternative to defining them in the PHP configuration files.
377+
378+
Example:
379+
380+
```yaml
381+
navigation:
382+
custom_items:
383+
- label: Custom Item
384+
destination: /custom-page
385+
```
386+
387+
### Extra attributes for navigation items
388+
389+
Navigation items now support extra attributes, allowing you to add custom data or styling to your navigation elements. You can set these attributes in both PHP and YAML configurations.
390+
391+
Example in PHP:
392+
393+
```php
394+
'navigation' => [
395+
'custom_items' => [
396+
[
397+
'label' => 'Custom Item',
398+
'destination' => '/custom-page',
399+
'attributes' => ['class' => 'special-link', 'target' => '_blank'],
400+
],
401+
],
402+
],
403+
```
404+
405+
Example in YAML:
406+
407+
```yaml
408+
navigation:
409+
custom_items:
410+
- label: Custom Item
411+
destination: /custom-page
412+
attributes:
413+
class: special-link
414+
target: _blank
415+
```
416+
417+
These changes provide more flexibility and control over your site's navigation structure. Make sure to update your configuration files and any custom code that interacts with navigation items to align with these new formats and features.

app/config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
'Features' => \Hyde\Facades\Features::class,
9898
'Config' => \Hyde\Facades\Config::class,
9999
'Filesystem' => \Hyde\Facades\Filesystem::class,
100+
'Navigation' => \Hyde\Facades\Navigation::class,
100101
'Routes' => \Hyde\Foundation\Facades\Routes::class,
101102
'HtmlPage' => \Hyde\Pages\HtmlPage::class,
102103
'BladePage' => \Hyde\Pages\BladePage::class,

config/hyde.php

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Hyde\Facades\Author;
2626
use Hyde\Facades\Meta;
2727
use Hyde\Enums\Feature;
28+
use Hyde\Facades\Navigation;
2829

2930
return [
3031

@@ -331,40 +332,23 @@
331332
|
332333
*/
333334

334-
'navigation' => [
335-
// This configuration sets the priorities used to determine the order of the menu.
336-
// The default values have been added below for reference and easy editing.
337-
// The array key is the page's route key, the value is the priority.
338-
// Lower values show up first in the menu. The default is 999.
339-
'order' => [
335+
'navigation' => Navigation::configure()
336+
->setPagePriorities([
340337
'index' => 0,
341338
'posts' => 10,
342339
'docs/index' => 100,
343-
],
344-
345-
// In case you want to customize the labels for the menu items, you can do so here.
346-
// Simply add the route key as the array key, and the label as the value.
347-
'labels' => [
340+
])
341+
->setPageLabels([
348342
'index' => 'Home',
349343
'docs/index' => 'Docs',
350-
],
351-
352-
// These are the route keys of pages that should not show up in the navigation menu.
353-
'exclude' => [
344+
])
345+
->excludePages([
354346
'404',
355-
],
356-
357-
// Any extra links you want to add to the navigation menu can be added here.
358-
// To get started quickly, you can uncomment the defaults here.
359-
// See the documentation link above for more information.
360-
'custom' => [
361-
// NavigationItem::create('https://github.com/hydephp/hyde', 'GitHub', 200),
362-
],
363-
364-
// How should pages in subdirectories be displayed in the menu?
365-
// You can choose between 'dropdown', 'flat', and 'hidden'.
366-
'subdirectories' => 'hidden',
367-
],
347+
])
348+
->addNavigationItems([
349+
// Navigation::item('https://github.com/hydephp/hyde', 'GitHub', 200),
350+
])
351+
->setSubdirectoryDisplayMode('hidden'),
368352

369353
/*
370354
|--------------------------------------------------------------------------

0 commit comments

Comments
 (0)