diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index c8a15afb191..90bac911835 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -13,9 +13,12 @@ This serves two purposes:
- Added a new `\Hyde\Framework\Actions\PreBuildTasks\TransferMediaAssets` build task handle media assets transfers for site builds.
### Changed
+- **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.
+- 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
+- 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.)
+- Minor: The documentation article component now supports disabling the semantic rendering using a falsy value in https://github.com/hydephp/develop/pull/1566
- Changed how the documentation search is generated, to be an `InMemoryPage` instead of a post-build task.
- Media asset files are now copied using the new build task instead of the deprecated `BuildService::transferMediaAssets()` method.
-- Minor: The documentation article component now supports disabling the semantic rendering using a falsy value in https://github.com/hydephp/develop/pull/1566
### Deprecated
- for soon-to-be removed features.
@@ -41,6 +44,32 @@ Please see the "Breaking changes & upgrade guide" section below for more informa
Please read through this section to ensure your site upgrades smoothly.
+## High impact
+
+### Navigation system rewrite
+
+The navigation system has been rewritten into a new Navigation API. This change is breaking for custom navigation implementations, see more down below.
+
+For most users, the only impact will be that configuration files need to be updated to use the new configuration format. Due to the internal changes,
+it's also possible that menu items will be in a slightly different order than before, depending on your setup. Please verify that your site's menus
+look as expected after upgrading, and adjust the configuration files if necessary, before deploying to production.
+
+### Navigation and sidebar configuration changes
+
+The navigation and sidebar configuration files have been updated to use the new Navigation API.
+This means that you will need to update your configuration files to use the new format.
+
+The easiest way to upgrade is to publish updated configuration files (`hyde.php` and `docs.php`) and copy over your customizations.
+
+The following configuration entries have been updated:
+
+- Changed configuration option `docs.sidebar_order` to `docs.sidebar.order` in https://github.com/hydephp/develop/pull/1583
+- Upgrade path: Move the `sidebar_order` option's array in the `config/docs.php` file into the `sidebar` array in the same file.
+
+- Changed configuration option `docs.table_of_contents` to `docs.sidebar.table_of_contents` in https://github.com/hydephp/develop/pull/1584
+- Upgrade path: Move the `table_of_contents` option's array in the `config/docs.php` file into the `sidebar` array in the same file.
+
+
## General impact
### Documentation search page changes
@@ -49,26 +78,55 @@ The documentation search page and search index have been changed to be generated
The main impact noticeable to most users by this is the implicit changes, like the pages showing up in the dashboard and route list command.
-In case you have customized the `GenerateSearch` post-build task you may, depending on what you were trying to do,
+In case you have customized the `GenerateSearch` post-build task you may, depending on what you were trying to do,
want to adapt your code to interact with the new `InMemoryPage`, which is generated in the `HydeCoreExtension` class.
For more information, see https://github.com/hydephp/develop/pull/1498.
## Low impact
+### Navigation internal changes
+
+The navigation system has been rewritten into a new Navigation API. This change is breaking for custom navigation implementations.
+
+If you have previously in your custom code done any of the following, or similar, you will need to adapt your code to use the new Navigation API:
+- Created custom navigation menus or Blade components
+- Extended or called the navigation related classes directly
+- Customized the navigation system in any way beyond the standard configuration
+
+
+#### Upgrade guide
+
+Due to the scope of the rewrite, the easiest and fastest way to upgrade your code is to recreate it using the new Navigation API.
+
+- For a full comparison of the changes, you may see the PR that introduced the new API: https://github.com/hydephp/develop/pull/1568/files
+- For information on how to use the new Navigation API, see the documentation: https://hydephp.com/docs/2.x/navigation-api
+
+### HTML ID changes
+
+Some HTML IDs have been renamed to follow a more consistent naming convention.
+
+If you have used any of the following selectors in custom code you wrote yourself, you will need to update to use the new changed IDs.
+
+#### https://github.com/hydephp/develop/pull/1622
+- Rename HTML ID `#searchMenu` to `#search-menu`
+- Rename HTML ID `#searchMenuButton` to `#search-menu-button`
+- Rename HTML ID `#searchMenuButtonMobile` to `#search-menu-button-mobile`
+
+
### New documentation search implementation
As the new documentation search implementation brings changes to their code API you may need to adapt your code
according to the information below in case you wrote custom code that interacted with these parts of the codebase.
-- The `GenerateSearch` post-build task has been removed. If you have previously extended or customized this class,
+- The `GenerateSearch` post-build task has been removed. If you have previously extended or customized this class,
you will need to adapt your code, as the search index files are now handled implicitly during the standard build process,
as the search pages are now added to the kernel page and route collection. (https://github.com/hydephp/develop/pull/1498)
- If your site has a custom documentation search page, for example `_docs/search.md` or `_pages/docs/search.blade.php`,
- that page will no longer be built when using the specific `build:search` command. It will, of course,
+ that page will no longer be built when using the specific `build:search` command. It will, of course,
be built using the standard `build` command. https://github.com/hydephp/develop/commit/82dc71f4a0e7b6be7a9f8d822fbebe39d2289ced
-
+
- In the highly unlikely event your site customizes any of the search pages by replacing them in the kernel route collection,
you would now need to do that in the kernel page collection due to the search pages being generated earlier in the lifecycle.
https://github.com/hydephp/develop/commit/82dc71f4a0e7b6be7a9f8d822fbebe39d2289ced
diff --git a/_ide_helper.php b/_ide_helper.php
index 7d868d7bbb5..8cc231f850f 100644
--- a/_ide_helper.php
+++ b/_ide_helper.php
@@ -22,6 +22,11 @@
/** @var string $routeKey The route key for the page being compiled/previewed */
$routeKey = \Hyde\Support\Facades\Render::getRouteKey();
+// Variables available only to some page types
+
+/** @var \Hyde\Framework\Features\Navigation\DocumentationSidebar $sidebar */
+$sidebar = app('navigation.sidebar');
+
// Facades (aliased in app/config.php)
/** @mixin \Hyde\Foundation\HydeKernel */
diff --git a/app/config.php b/app/config.php
index 9af0e0cdf05..627c80c2d13 100644
--- a/app/config.php
+++ b/app/config.php
@@ -73,6 +73,7 @@
Hyde\Foundation\Providers\ConfigurationServiceProvider::class,
Hyde\Framework\HydeServiceProvider::class,
Hyde\Foundation\Providers\ViewServiceProvider::class,
+ Hyde\Foundation\Providers\NavigationServiceProvider::class,
Hyde\Console\ConsoleServiceProvider::class,
],
diff --git a/config/docs.php b/config/docs.php
index fab400e973d..4ac1dd70706 100644
--- a/config/docs.php
+++ b/config/docs.php
@@ -30,49 +30,49 @@
// When using a grouped sidebar, should the groups be collapsible?
'collapsible' => true,
- // Should the sidebar footer be shown? You can also set this to a string
- // of Markdown to show in the footer. Set to `false` to disable.
- 'footer' => true,
- ],
-
- /*
- |--------------------------------------------------------------------------
- | Sidebar Page Order
- |--------------------------------------------------------------------------
- |
- | In the generated Documentation pages the navigation links in the sidebar
- | default to sort alphabetically. You can reorder the page identifiers
- | in the list below, and the links will get sorted in that order.
- |
- | The items will get a priority of 500 plus the order its found in the list.
- | Pages without a priority will fall back to the default priority of 999.
- |
- | You can also set explicit priorities in front matter or by specifying
- | a value to the array key in the list to override the inferred value.
- |
- */
-
- 'sidebar_order' => [
- 'readme',
- 'installation',
- 'getting-started',
- ],
-
- /*
- |--------------------------------------------------------------------------
- | Table of Contents Settings
- |--------------------------------------------------------------------------
- |
- | The Hyde Documentation Module comes with a fancy Sidebar that, by default,
- | has a Table of Contents included. Here, you can configure its behavior,
- | content, look and feel. You can also disable the feature completely.
- |
- */
+ // A string of Markdown to show in the footer. Set to `false` to disable.
+ 'footer' => '[Back to home page](../)',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Sidebar Page Order
+ |--------------------------------------------------------------------------
+ |
+ | In the generated Documentation pages the navigation links in the sidebar
+ | default to sort alphabetically. You can reorder the page identifiers
+ | in the list below, and the links will get sorted in that order.
+ |
+ | The items will get a priority of 500 plus the order its found in the list.
+ | Pages without a priority will fall back to the default priority of 999.
+ |
+ | You can also set explicit priorities in front matter or by specifying
+ | a value to the array key in the list to override the inferred value.
+ |
+ */
+
+ 'order' => [
+ 'readme',
+ 'installation',
+ 'getting-started',
+ ],
+
+ /*
+ |--------------------------------------------------------------------------
+ | Table of Contents Settings
+ |--------------------------------------------------------------------------
+ |
+ | The Hyde Documentation Module comes with a fancy Sidebar that, by default,
+ | has a Table of Contents included. Here, you can configure its behavior,
+ | content, look and feel. You can also disable the feature completely.
+ |
+ */
+
+ 'table_of_contents' => [
+ 'enabled' => true,
+ 'min_heading_level' => 2,
+ 'max_heading_level' => 4,
+ ],
- 'table_of_contents' => [
- 'enabled' => true,
- 'min_heading_level' => 2,
- 'max_heading_level' => 4,
],
/*
diff --git a/config/hyde.php b/config/hyde.php
index 9cbbe1cceb3..c91370adce7 100644
--- a/config/hyde.php
+++ b/config/hyde.php
@@ -350,7 +350,7 @@
// To get started quickly, you can uncomment the defaults here.
// See the documentation link above for more information.
'custom' => [
- // NavItem::forLink('https://github.com/hydephp/hyde', 'GitHub', 200),
+ // NavigationItem::create('https://github.com/hydephp/hyde', 'GitHub', 200),
],
// How should pages in subdirectories be displayed in the menu?
diff --git a/docs/advanced-features/navigation-api.md b/docs/advanced-features/navigation-api.md
new file mode 100644
index 00000000000..9c5fcad14d2
--- /dev/null
+++ b/docs/advanced-features/navigation-api.md
@@ -0,0 +1,433 @@
+---
+navigation:
+ label: "Navigation API"
+---
+
+# Navigation API
+
+>warning This article covers advanced information that is only relevant if you want to create custom navigation menus. Instead, you may want to read the [Navigation](navigation) article for a general overview.
+
+
+## Abstract
+
+This article describes the Navigation API introduced in HydePHP v2. Both the main navigation menu and the documentation sidebar bundled with HydePHP are built with this API.
+However, if you are interested in creating your own custom navigation menus, you can also utilize this API - and this article will show you how.
+
+This article is intended for advanced users, as most users will not need to create custom navigation menus.
+For this reason, the documentation is very code-driven due to the technical nature of the API.
+We'll also be mixing in some practical examples of Blade and PHP code to illustrate how you can use the API in your own projects.
+
+
+## Overview
+
+The Navigation API consists of a set of classes within the `Hyde\Framework\Features\Navigation` namespace.
+
+Together, these form an object-oriented way to create and interact with navigation menus and their items.
+
+In short, a navigation menu is an instance of the `NavigationMenu` class. Each menu contains a collection of `NavigationItem` or `NavigationGroup` classes.
+The former represents a single item in the menu, while the latter represents a group of items.
+
+### Visualisation
+
+Here is a visual representation of the structure of a navigation menu:
+
+```php
+namespace Hyde\Framework\Features\Navigation;
+
+class NavigationMenu {
+ protected Collection $items = [
+ new NavigationItem(destination: 'index.html', label: 'Home'),
+ new NavigationItem(destination: 'posts.html', label: 'Blog'),
+ new NavigationGroup(label: 'About', items: [
+ new NavigationItem(destination: 'about.html', label: 'About Us'),
+ new NavigationItem(destination: 'team.html', label: 'Our Team'),
+ ]),
+ ];
+}
+```
+
+### Built-in Menus
+
+HydePHP comes with two built-in menus: the main navigation menu and the documentation sidebar, both represented as child classes of the `NavigationMenu` class.
+They are bound into the service container as singletons and can be accessed through dependency injection.
+
+```php
+use Hyde\Framework\Features\Navigation\MainNavigationMenu;
+use Hyde\Framework\Features\Navigation\DocumentationSidebar;
+
+/** @var \Hyde\Framework\Features\Navigation\MainNavigationMenu $menu */
+$menu = app('navigation.main')
+
+/** @var DocumentationSidebar $sidebar */
+$sidebar= app('navigation.sidebar')
+```
+
+You can also get them through the static `get` helpers on the menu classes themselves.
+
+```php
+use Hyde\Framework\Features\Navigation\MainNavigationMenu;
+use Hyde\Framework\Features\Navigation\DocumentationSidebar;
+
+$menu = MainNavigationMenu::get();
+$sidebar = DocumentationSidebar::get();
+```
+
+>info Developer tip: The menus are only generated *after* the Hyde Kernel is booted. If you are getting BindingResolutionExceptions, ensure that you are not trying to access the menus too early in the application lifecycle. (Consider using the `booted` event.)
+
+
+## Creating Custom Menus
+
+### Introduction Overview
+
+When creating a custom menu, there are two ways to go about it:
+
+1. You can construct a NavigationMenu instance directly and add items to it. This works great for smaller menus that don't need any special logic, for example a footer menu or social media links.
+2. You can create a custom class that extends the NavigationMenu class. This is useful for larger menus that require more complex logic, or that you want to reuse in multiple places in your application or in a package.
+
+In both cases, the underlying API is the same, and you can use the helper methods and features provided by the APIs.
+
+In this section, you will first see some high level overviews of how the API can be used, then we'll dive in deeper and take a look at each class and method in detail.
+
+### High Level Example
+
+To illustrate how you can create a custom menu, let's make something useful: A footer menu with social media links.
+
+#### Step 1: Create the Menu
+
+To create our menu, we start by constructing a new NavigationMenu instance.
+We can then add our social media links as NavigationItem instances to the menu.
+
+```php
+$menu = new NavigationMenu();
+
+$menu->add([
+ // The first parameter is the URL, and the second is the label.
+ NavigationItem::create('https://twitter.com/hydephp', 'Twitter'),
+ NavigationItem::create('https://github.com/hydephp', 'GitHub'),
+ NavigationItem::create('https://hydephp.com', 'Website'),
+]);
+```
+
+#### Step 2: Display the Menu
+
+We can now iterate over the menu items to render them in our footer.
+
+```blade
+
+```
+
+This will result in the following HTML:
+
+```html
+
+```
+
+#### Next Steps & Tips
+
+Of course, this is an incredibly simplistic example to illustrate the core concepts.
+Where the Navigation API really shines is in more complex scenarios where you want to utilize things like
+HydePHP Routes to resolve dynamic relative urls, and to use features like groups, priorities, and active states helpers to check if a menu item is the current page being viewed.
+
+The object-oriented nature of the API also makes this perfect for package developers wanting to create dynamic and reusable navigation menus that even can be further extended and customized by the end user.
+
+Here are some general tips to keep in mind when working with the Navigation API:
+- You can use the `add` method to add single items or arrays of items. You can also pass an array of items directly to the menu constructor.
+- The navigation menu items is stored in a Laravel Collection, and is type safe to support both `NavigationItem` and `NavigationGroup` instances.
+- You can also construct NavigationItem instances directly, but the `create` method is a convenient shorthand, and can fill in data from routes, if you use them.
+- It's also possible to set an item's priority as the third parameter, but here we don't need it, as they default to the order they are added.
+
+
+## Class Reference
+
+Below is a reference of the classes and methods available in the Navigation API.
+
+
+## NavigationMenu
+
+The `NavigationMenu` class represents a navigation menu. It contains a collection of items, which can be either `NavigationItem` or `NavigationGroup` instances.
+
+### Quick Reference
+
+Here is a quick reference of the methods available on the NavigationMenu class:
+
+```php
+use Hyde\Framework\Features\Navigation\NavigationMenu;
+
+// Create a new NavigationMenu instance, optionally providing an array of items.
+$menu = new NavigationMenu($items = []);
+
+// Add a single item or an array of items to the menu.
+$menu->add(new NavigationItem());
+$menu->add([new NavigationItem()]);
+
+// Get all items in the menu as a sorted Collection.
+$menu->getItems(): Collection
+```
+
+### Creating Navigation Menus
+
+You can create a new NavigationMenu instance by simply calling the constructor, optionally providing an array of items.
+
+```php
+use Hyde\Framework\Features\Navigation\NavigationMenu;
+
+$menu = new NavigationMenu($items = []);
+```
+
+Here is how to provide an array or Collection of `NavigationItem` and/or `NavigationGroup` instances directly to the constructor.
+
+```php
+use Hyde\Framework\Features\Navigation\NavigationMenu;
+use Hyde\Framework\Features\Navigation\NavigationItem;
+use Hyde\Framework\Features\Navigation\NavigationGroup;
+
+$menu = new NavigationMenu([
+ new NavigationItem('index.html', 'Home'),
+ new NavigationItem('posts.html', 'Blog'),
+ new NavigationGroup('About', [
+ new NavigationItem('about.html', 'About Us'),
+ new NavigationItem('team.html', 'Our Team'),
+ ]),
+]);
+```
+
+### Adding Items to the Menu
+
+You can also add items to the menu after it has been created by using the `add` method which can take a single item or an array of items, and can be fluently chained.
+
+```php
+$menu = (new NavigationMenu())
+ ->add(new NavigationItem('contact.html', 'Contact Us'))
+ ->add([
+ new NavigationItem('privacy.html', 'Privacy Policy'),
+ new NavigationItem('terms.html', 'Terms of Service'),
+ ]);
+```
+
+### Accessing Items in the Menu
+
+You can access all items in the menu by calling the `getItems` method, which will return a `Collection` of all items in the menu.
+
+```php
+$items = $menu->getItems();
+```
+
+The items will automatically be sorted by their priority, with lower numbers coming first, defaulting to the order they were added if no priority is set.
+
+## NavigationItem
+
+The `NavigationItem` class is an abstraction for a navigation menu item containing useful information like the destination, label, and priority.
+
+### Quick Reference
+
+Here is a quick reference of the methods available on the `NavigationItem` class:
+
+```php
+use Hyde\Framework\Features\Navigation\NavigationItem;
+
+// Create a new NavigationItem instance.
+$item = NavigationItem::create($destination, $label, $priority): NavigationItem;
+$item = new NavigationItem($destination, $label, $priority); // Same as above.
+
+// Get the link of the item.
+$item->getLink(): string;
+
+// Get the label of the item.
+$item->getLabel(): string;
+
+// Get the priority of the item.
+$item->getPriority(): int;
+
+// Check if the item is active. (Only works when the destination is a route)
+$item->isActive(): bool;
+```
+
+### Blade Example
+
+Here is an example of how you can put it all together in a Blade template:
+
+```blade
+ $item->isActive()])>
+ {{ $item->getLabel() }}
+
+```
+
+This will output an anchor tag with the correct link and label, and if the item is active, it will add an `active` class to the tag.
+
+### Creating Navigation Items
+
+There are two syntaxes for creating `NavigationItem` instances, you can use a standard constructor or the static create method.
+Both options provide the exact same signature and functionality, so it's just a matter of preference which one you use.
+
+The constructors take three parameters: the destination, the label, and the optional priority.
+The destination can be a `Route` instance, a route key string, or an external URL.
+
+```php
+use Hyde\Framework\Features\Navigation\NavigationItem;
+
+$item = new NavigationItem($destination, $label, $priority);
+$item = NavigationItem::create($destination, $label, $priority);
+```
+
+#### Using Routes
+
+Using the HydePHP routing system is the recommended way to create navigation items leading to pages within your project,
+as they will automatically have links resolved to the correct URL, and Hyde can check if the items are active.
+Additionally, Hyde will use the page data as the label and priority defaults unless you override them.
+
+You can create routed navigation items by providing either a `Route` instance or a route key string as the destination.
+
+```php
+// Using a route key string.
+new NavigationItem('index');
+
+// Using the Routes facade to get a Route instance.
+new NavigationItem(Routes::get('index'));
+
+// Setting the label and/or priorities will override inferred data.
+new NavigationItem(Routes::get('index'), 'Custom Label', 25);
+```
+
+Using a route key is more concise, but will not provide type safety as it will be treated as a link if the route does not exist,
+whereas providing an invalid route key to the `Routes` facade will throw an exception. It's up to you which one you prefer.
+
+#### Using External URLs
+
+You can also create navigation items that link to external URLs by providing a full URL as the destination.
+
+If you do not set a label for links, the label will default to the URL, and if you do not set a priority, it will default to `500`.
+
+```php
+// This will lead directly to the link, and use it as the label with a priority of 500.
+new NavigationItem('https://example.com');
+
+// You can also set a custom label and priority to override the defaults.
+new NavigationItem('https://example.com', 'External Link', 25);
+```
+
+While it is discouraged to use external URLs for internal pages, as Hyde won't be able to resolve relative links or check active states,
+they are excellent for any time you want an absolute link to an external site or resource.
+
+Note that Hyde will not validate or modify the URL, so you are responsible for ensuring it's correct.
+
+### Accessing the resolved links
+
+The `getLink` method is designed to return a link that can be used in the `href` attribute of an anchor tag.
+
+If the destination is a route, the link will be resolved to the correct URL, using relative paths if possible. It will also respect the pretty URL setting.
+
+```php
+$item = new NavigationItem(Routes::get('index'));
+$item->getLink(); // Outputs 'index.html'
+
+$item = new NavigationItem('https://example.com');
+$item->getLink(); // Outputs 'https://example.com'
+```
+
+**Tip:** The item instances automatically turns into the resolved link when cast to a string. Perfect for your Blade templates!
+
+```blade
+{{ $item->getLabel() }}
+```
+
+### Accessing the label
+
+The `getLabel` method returns the label of the item. This is the text that will be displayed in the navigation menu.
+
+```php
+$item = new NavigationItem('index', 'Home');
+$item->getLabel(); // Outputs 'Home'
+```
+
+### Accessing the priority
+
+The `getPriority` method returns the priority of the item. This is a number that determines the order in which the items are displayed in the menu, where lower numbers come first.
+
+```php
+$item = new NavigationItem('index', 'Home', 25);
+$item->getPriority(); // Outputs 25
+```
+
+### Checking if the item is active
+
+The `isActive` method checks if the item is active (by comparing it to the Hyde page being compiled at the moment). This is useful for highlighting the current page in the navigation menu.
+
+```php
+$item = new NavigationItem('index');
+$item->isActive(); // Outputs true if the item is the current page, otherwise false.
+```
+
+
+
+
+## NavigationGroup
+
+The `NavigationGroup` class represents a group of items in a navigation menu. It contains a label, priority, and a collection of navigation items.
+This class is often used to create submenus or dropdowns in a navigation menu.
+
+The `NavigationGroup` class extends the `NavigationMenu` class, and thus inherits the same base methods and functionality,
+while also having shared methods with the `NavigationItem` class to render the groups in a Blade view.
+
+### Quick Reference
+
+Here is a quick reference of the methods available on the `NavigationGroup` class:
+
+```php
+use Hyde\Framework\Features\Navigation\NavigationGroup;
+
+// Create a new NavigationGroup instance.
+$group = new NavigationGroup($label, $items = [], $priority = 500);
+
+// Add a single item or an array of items to the group.
+$group->add(new NavigationItem());
+$group->add([new NavigationItem()]);
+
+// Get all items in the group as a Collection sorted by priority.
+$group->getItems(): Collection
+
+// Get the label of the group.
+$group->getLabel(): string;
+
+// Get the priority of the group.
+$group->getPriority(): int;
+
+// Get the group key, which is a normalized kebab-case version of the label.
+$group->getGroupKey(): string;
+```
+
+As the `NavigationGroup` class extends the `NavigationMenu` class, please see the `NavigationMenu` section for detailed information of the methods available.
+
+### Usage Scenarios
+
+HydePHP uses the `NavigationGroup` class to create dropdowns in the main navigation menu and the category groups in the documentation sidebar.
+
+In your own custom menus, you can use this class for the same types of functionality, and you can even nest groups within groups to create complex navigation structures.
diff --git a/docs/creating-content/documentation-pages.md b/docs/creating-content/documentation-pages.md
index c1f0cdfdbd0..1e9839e8539 100644
--- a/docs/creating-content/documentation-pages.md
+++ b/docs/creating-content/documentation-pages.md
@@ -223,10 +223,12 @@ To quickly arrange the order of items in the sidebar, you can reorder the page i
Link items without an entry here will fall back to the default priority of 999, putting them last.
```php
-'sidebar_order' => [
- 'readme',
- 'installation',
- 'getting-started',
+'sidebar' => [
+ 'order' => [
+ 'readme',
+ 'installation',
+ 'getting-started',
+ ],
]
```
@@ -256,10 +258,12 @@ In the `config/docs.php` file you can configure the behaviour, content, and the
You can also disable the feature completely.
```php
-'table_of_contents' => [
- 'enabled' => true,
- 'min_heading_level' => 2,
- 'max_heading_level' => 4,
+'sidebar' => [
+ 'table_of_contents' => [
+ 'enabled' => true,
+ 'min_heading_level' => 2,
+ 'max_heading_level' => 4,
+ ],
],
```
diff --git a/docs/digging-deeper/customization.md b/docs/digging-deeper/customization.md
index 8f8c455bc60..0ec2b9c934d 100644
--- a/docs/digging-deeper/customization.md
+++ b/docs/digging-deeper/customization.md
@@ -259,7 +259,7 @@ Learn more in the [Navigation Menu](navigation) documentation.
#### Customizing the documentation sidebar
-- To customize the sidebar, use the setting `sidebar_order` in the `docs.php` config.
+- To customize the sidebar, use the setting `sidebar.order` in the `docs.php` config.
- When customizing the sidebar, can use the route key, or just the [page identifier](core-concepts#page-identifiers) of the page.
Learn more in the [Documentation Pages](documentation-pages) documentation.
diff --git a/docs/digging-deeper/navigation.md b/docs/digging-deeper/navigation.md
index a9d865d45df..ff515caf30b 100644
--- a/docs/digging-deeper/navigation.md
+++ b/docs/digging-deeper/navigation.md
@@ -122,12 +122,12 @@ Next up, let's look at how to customize the navigation menus using the config fi
- To customize the navigation menu, use the setting `navigation.order` in the `hyde.php` config.
- When customizing the navigation menu, you should use the [route key](core-concepts#route-keys) of the page.
-- To customize the sidebar, use the setting `sidebar_order` in the `docs.php` config.
+- To customize the sidebar, use the setting `sidebar.order` in the `docs.php` config.
- When customizing the sidebar, can use the route key, or just the [page identifier](core-concepts#page-identifiers) of the page.
### Changing the priorities
-The `navigation.order` and `sidebar_order` settings allow you to customize the order of the pages in the navigation menus.
+The `navigation.order` and `sidebar.order` settings allow you to customize the order of the pages in the navigation menus.
#### Basic syntax for changing the priorities
@@ -149,10 +149,12 @@ The offset is added to make it easier to place pages earlier in the list using f
```php
// filepath: config/docs.php
-'sidebar_order' => [
- 'readme', // Gets priority 500
- 'installation', // Gets priority 501
- 'getting-started', // Gets priority 502
+'sidebar' => [
+ 'order' => [
+ 'readme', // Gets priority 500
+ 'installation', // Gets priority 501
+ 'getting-started', // Gets priority 502
+ ]
]
```
@@ -175,10 +177,12 @@ You can also specify explicit priorities by adding a value to the array key:
```php
// filepath: config/docs.php
-'sidebar_order' => [
- 'readme' => 10, // Gets priority 10
- 'installation' => 15, // Gets priority 15
- 'getting-started' => 20, // Gets priority 20
+'sidebar' => [
+ 'order' => [
+ 'readme' => 10, // Gets priority 10
+ 'installation' => 15, // Gets priority 15
+ 'getting-started' => 20, // Gets priority 20
+ ]
]
```
@@ -226,18 +230,18 @@ To remove items from being automatically added, simply add the page's route key
### Adding Custom Navigation Menu Links
-You can easily add custom navigation menu links similar to how we add Authors. Simply add a `NavItem` model to the `navigation.custom` array.
+You can easily add custom navigation menu links similar to how we add Authors. Simply add a `NavigationItem` model to the `navigation.custom` array.
-When linking to an external site, you should use the `NavItem::forLink()` method facade. The first two arguments are the
+When linking to an external site, you should use the `NavigationItem::create()` method facade. The first two arguments are the
destination and label, both required. The third argument is the priority, which is optional, and defaults to `500`.
```php
// filepath config/hyde.php
-use Hyde\Framework\Features\Navigation\NavItem;
+use Hyde\Framework\Features\Navigation\NavigationItem;
'navigation' => [
'custom' => [
- NavItem::forLink('https://github.com/hydephp/hyde', 'GitHub', 200),
+ NavigationItem::create('https://github.com/hydephp/hyde', 'GitHub', 200),
]
]
```
@@ -290,30 +294,41 @@ For example: `_docs/getting-started/installation.md` will be placed in a group c
>info Tip: When using subdirectory-based dropdowns, you can set their priority using the directory name as the array key.
+#### Dropdown menu notes
+
+Here are some things to keep in mind when using dropdown menus, regardless of the configuration:
+- Dropdowns take priority over standard items. So 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.
+ - For example: With this file structure: `_pages/foo.md`, `_pages/foo/bar.md`, `_pages/foo/baz.md`, the link to `foo` will be lost.
## Digging Deeper into the internals
-While not required to know, you may find it interesting to learn more about how the navigation is handled internally.
-The best way to learn about this is to look at the source code, so here is a high-level overview with details on where to look in the source code.
+While not required to know, you may find it interesting to learn more about how the navigation is handled internally. Here is a high level overview,
+but you can find more detailed information in the [Navigation API](navigation-api) documentation.
-The main navigation menu is the `NavigationMenu` class, and the documentation sidebar is the `DocumentationSidebar` class.
-Both extend the same `BaseNavigationMenu` class:
+The main navigation menu is the `MainNavigationMenu` class, and the documentation sidebar is the `DocumentationSidebar` class. Both extend the same base `NavigationMenu` class.
```php
-use Hyde\Framework\Features\Navigation\NavigationMenu;
+use Hyde\Framework\Features\Navigation\MainNavigationMenu;
use Hyde\Framework\Features\Navigation\DocumentationSidebar;
-use Hyde\Framework\Features\Navigation\BaseNavigationMenu;
+use Hyde\Framework\Features\Navigation\NavigationMenu;
```
-Within the `BaseNavigationMenu` class, you will find the main logic for how the menus are generated,
+Within the base `NavigationMenu` class, you will find the main logic for how the menus are generated,
while the child implementations contain the extra logic tailored for their specific use cases.
-All the navigation menus store the menu items in their `$items` array containing instances of the `NavItem` class.
+All the navigation menus store the menu items in their `$items` collection containing instances of the `NavigationItem` class.
-The `NavItem` class is a simple class that contains the label and URL of the menu item and is used to represent each item in the menu.
-Dropdowns are represented by `DropdownNavItem` instances, which extend the `NavItem` class and contain an array of additional `NavItem` instances.
+The `NavigationItem` class is a simple class that contains the label and URL of the menu item and is used to represent each item in the menu.
+Dropdowns are represented by `NavigationGroup` instances, which extend the `NavigationMenu` class and contain a collection of additional `NavigationItem` instances.
```php
-use Hyde\Framework\Features\Navigation\NavItem;
-use Hyde\Framework\Features\Navigation\DropdownNavItem;
+use Hyde\Framework\Features\Navigation\NavigationItem;
+use Hyde\Framework\Features\Navigation\NavigationGroup;
```
+
+## The Navigation API
+
+If you want to interact with the site navigation programmatically, or if you want to create complex custom menus, you can do so through the new Navigation API.
+For most cases you don't need this, as Hyde creates the navigation for you. But it can be useful for advanced users and package developers.
+
+The Navigation API consists of a set of PHP classes, allowing you to fluently interact with the navigation menus. You can learn more about the API in the [Navigation API](navigation-api) documentation.
diff --git a/packages/framework/config/docs.php b/packages/framework/config/docs.php
index fab400e973d..93bbc751dc2 100644
--- a/packages/framework/config/docs.php
+++ b/packages/framework/config/docs.php
@@ -33,46 +33,47 @@
// Should the sidebar footer be shown? You can also set this to a string
// of Markdown to show in the footer. Set to `false` to disable.
'footer' => true,
- ],
-
- /*
- |--------------------------------------------------------------------------
- | Sidebar Page Order
- |--------------------------------------------------------------------------
- |
- | In the generated Documentation pages the navigation links in the sidebar
- | default to sort alphabetically. You can reorder the page identifiers
- | in the list below, and the links will get sorted in that order.
- |
- | The items will get a priority of 500 plus the order its found in the list.
- | Pages without a priority will fall back to the default priority of 999.
- |
- | You can also set explicit priorities in front matter or by specifying
- | a value to the array key in the list to override the inferred value.
- |
- */
-
- 'sidebar_order' => [
- 'readme',
- 'installation',
- 'getting-started',
- ],
- /*
- |--------------------------------------------------------------------------
- | Table of Contents Settings
- |--------------------------------------------------------------------------
- |
- | The Hyde Documentation Module comes with a fancy Sidebar that, by default,
- | has a Table of Contents included. Here, you can configure its behavior,
- | content, look and feel. You can also disable the feature completely.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Sidebar Page Order
+ |--------------------------------------------------------------------------
+ |
+ | In the generated Documentation pages the navigation links in the sidebar
+ | default to sort alphabetically. You can reorder the page identifiers
+ | in the list below, and the links will get sorted in that order.
+ |
+ | The items will get a priority of 500 plus the order its found in the list.
+ | Pages without a priority will fall back to the default priority of 999.
+ |
+ | You can also set explicit priorities in front matter or by specifying
+ | a value to the array key in the list to override the inferred value.
+ |
+ */
+
+ 'order' => [
+ 'readme',
+ 'installation',
+ 'getting-started',
+ ],
+
+ /*
+ |--------------------------------------------------------------------------
+ | Table of Contents Settings
+ |--------------------------------------------------------------------------
+ |
+ | The Hyde Documentation Module comes with a fancy Sidebar that, by default,
+ | has a Table of Contents included. Here, you can configure its behavior,
+ | content, look and feel. You can also disable the feature completely.
+ |
+ */
+
+ 'table_of_contents' => [
+ 'enabled' => true,
+ 'min_heading_level' => 2,
+ 'max_heading_level' => 4,
+ ],
- 'table_of_contents' => [
- 'enabled' => true,
- 'min_heading_level' => 2,
- 'max_heading_level' => 4,
],
/*
diff --git a/packages/framework/config/hyde.php b/packages/framework/config/hyde.php
index 9cbbe1cceb3..c91370adce7 100644
--- a/packages/framework/config/hyde.php
+++ b/packages/framework/config/hyde.php
@@ -350,7 +350,7 @@
// To get started quickly, you can uncomment the defaults here.
// See the documentation link above for more information.
'custom' => [
- // NavItem::forLink('https://github.com/hydephp/hyde', 'GitHub', 200),
+ // NavigationItem::create('https://github.com/hydephp/hyde', 'GitHub', 200),
],
// How should pages in subdirectories be displayed in the menu?
diff --git a/packages/framework/resources/views/components/docs/search-widget.blade.php b/packages/framework/resources/views/components/docs/search-widget.blade.php
index b44d81327c0..43f3ee46928 100644
--- a/packages/framework/resources/views/components/docs/search-widget.blade.php
+++ b/packages/framework/resources/views/components/docs/search-widget.blade.php
@@ -1,4 +1,4 @@
-
-