hydephp / develop

The HydePHP Source Code Monorepo
https://hydephp.com
MIT License
13 stars 6 forks source link

Consider merging the sidebar configuration location to be alongside the main menu navigation #1835

Closed caendesilva closed 3 months ago

caendesilva commented 3 months ago

Proposal: Configure all sidebars in the hyde configuration file to keep related options together

 'menus' => [
     NavigationMenu::configure('main')
         ->doStuff()

     NavigationMenu::configure('docs')
         ->doStuff()

     NavigationMenu::create('footer')
          ->defineCustomStuff()
 ],

From: https://github.com/hydephp/develop/pull/1538#issuecomment-1936359331

Wondering if this API could be used in the config to initialize menus. It's kinda Filamenty. Since we don't cache configs (except for in the standalone which uses a caching hack) it should not be a problem. Worst case, that can be serialized in our configuration loader.

   'menus' => [
        NavigationMenu::create('main')
            ->withPageTypes('all', except: [DocumentationPage::class])
            ->withoutPages('404')
            ->withLabels([
                'home' => 'Start',
                'about' => 'About Us',
            ])
            ->withPriorities([
                'home' => 100,
                'about' => 200,
            ]),

        NavigationMenu::create('docs')
            ->withPageTypes(DocumentationPage::class)
            ->withLabels([
                'readme' => 'Readme',
                'installation' => 'Installation',
                'getting-started' => 'Getting Started',
            ])
            ->withPriorities([
                'readme' => 100,
                'installation' => 200,
                'getting-started' => 300,
            ])
            ->withoutPages([
                '404',
                'changelog'
            ]),
    ],

They can be accessed like this:

$main = NavigationMenu::get('main'); // Main menu
$docs = NavigationMenu::get('docs'); // Sidebar
$foo = NavigationMenu::get('foo'); // Throws with message stating menu must be specified in config

We could of course add the defaults to the base classes, so only overwrites would be needed.

NavigationMenu::main()
NavigationMenu::docs()
NavigationMenu::create() // For custom ones

And users could easily add their own navigation menus.

    NavigationMenu::create('footer')
        ->withRoutes(routeKeys: [
            'privacy-policy',
            'terms-of-service',
        ])
        ->withNavItems([
            NavItem::create(...['some data']),
            NavItem::create(...['some data']),
        ])
        ->withLinks([
            'External Link' => 'https://example.com',
        ])

        // Or shorthand
        ->with(routeKeys: [
            'privacy-policy',
            'terms-of-service',
        ], links: [
            'External Link' => 'https://example.com',
        ]),

We could also have subdirectory configuration on a per menu basis

    NavigationMenu::create('docs')
        ->useSubdirectoriesAs('dropdown')
caendesilva commented 3 months ago

The creator is interesting, but I'm not sure if it works having the sidebar here as many of it's features are so different, so we'd almost want a dedicated builder, leading to a ton of complexity.

Not applicable to main menus:

// The title in the sidebar header
'header' => env('SITE_NAME', 'HydePHP').' Docs',

// When using a grouped sidebar, should the groups be collapsible?
'collapsible' => true,

// A string of Markdown to show in the footer. Set to `false` to disable.
'footer' => '[Back to home page](../)',

'table_of_contents' => ...