GuavaCZ / filament-knowledge-base

MIT License
139 stars 21 forks source link

[Request]: The knowledge base panel needs to be registered with a custom vite theme. #25

Closed dmb-220 closed 3 months ago

dmb-220 commented 5 months ago

What feature would you like to add?

The knowledge base panel needs to be registered with a custom vite theme. new install laraavel new versio 11.10 new filament 3.2.85 press documentation button get error

Notes

No response

dmb-220 commented 5 months ago

http://new.test/kb/\prologue\getting-started get Not Found

The requested URL was not found on this server.

cooljet84 commented 5 months ago

You should configure the custom theme in you AppServiceProvider (app/Providers/AppServiceProvider.php) not in your Panel ServiceProvider

use Guava\FilamentKnowledgeBase\Filament\Panels\KnowledgeBasePanel;

KnowledgeBasePanel::configureUsing(
    fn(KnowledgeBasePanel $panel) => $panel
        ->viteTheme('resources/css/filament/admin/theme.css') // your filament vite theme path here
);
damms005 commented 5 months ago

@dmb-220 I can almost bet that you are registering this in your boot() method like every other Filament setup plugin. The docs, unusual of most filament plugins, instructs that it should be registered in the register method.

I have a good number of filament plugins in my app, and this is the first and only plugin that registerd in register method of service provider. @cooljet84 any ideas why this design decision please?

eelco2k commented 4 months ago

@cooljet84 i've got the same problem. i've added the configureUsing() function to my AppServiceProvider.php

but i still get the error that i need to use custom theme.

 KnowledgeBasePanel::configureUsing(function (KnowledgeBasePanel $panel) {
            return
                $panel
                    ->brandName('Knowledge base')
                    ->guestAccess(true)
                    ->disableBackToDefaultPanelButton()
                    // ->syntaxHighlighting() // Needs nodeJs on server
                    ->viteTheme('resources/css/filament/portal/theme.css')
                    ->middleware([
                        'requestlog',
                    ]);
            }

i'm using the same custom viteTheme as in my Portal filament admin panel.

I've also run the npm run build and double checked the manual as stated here: https://filamentphp.com/docs/3.x/panels/themes#creating-a-custom-theme

if i just hardcode $this->viteTheme('resources/css/filament/portal/theme.css'); at the KnowledgeBasePanel.php in ```php function getTheme(): Theme { $this->viteTheme('resources/css/filament/portal/theme.css');



  everything works...
eelco2k commented 4 months ago

Also when i set breakpoints with XDebug.

 KnowledgeBasePanel::configureUsing(function (KnowledgeBasePanel $panel) {
            $test = $panel ; // added breakpoint here.... 

the debugger does not execute the function in ::configureUsing... so it looks like it's not correctly registered... as ComponentManager::resolve() should resolve the plugin...???

agruenberg commented 4 months ago

@damms005 You saved my evening ;)

OlyaK95 commented 3 months ago

Can somebody help me?

I placed this code in AppServiceProvider.php 2024-07-28_15-49-32

And I can open my Knowledge Base 2024-07-28_15-51-33

But I have 404 error 2024-07-28_15-52-08

OlyaK95 commented 3 months ago

@lukas-frey I think I need your help..

eelco2k commented 3 months ago

@OlyaK95 I don’t understand why your url get encoded with \ also visible in your address bar with: %5C

\ are for namespaces, not paths in url. Not sure it is related to that. Just wild guessing

OlyaK95 commented 3 months ago

@OlyaK95 I don’t understand why your url get encoded with \ also visible in your address bar with: %5C

\ are for namespaces, not paths in url. Not sure it is related to that. Just wild guessing

I tried manually change path to http://filament.test/kb\prologue\getting-started and to http://filament.test/kb/prologue/getting-started Nothing changes... 404

I tried also change my locale to en but I have %5C too.

eelco2k commented 3 months ago

What does the CLI command php artisan route:list --name=knowledge-base say for the kb urls?

OlyaK95 commented 3 months ago

What do the PHP artisan route:list say for the kb urls?

Routes about kb

 GET|HEAD   kb ............................................................................................................................................................................................................................. filament.knowledge-base.pages.dashboard › Filament\Pages › Dashboard  
  POST       kb/logout .................................................................................................................................................................................................................... filament.knowledge-base.auth.logout › Filament\Http › LogoutController  
  GET|HEAD   kb/{record?} ................................................................................................................................................................................ filament.knowledge-base.resources.documentations.view › Guava\FilamentKnowledgeBase › ViewDocumentation
eelco2k commented 3 months ago

and your config ?

OlyaK95 commented 3 months ago

and your config ?

default

<?php

// config for Guava/KnowledgeBasePanel
return [
    "panel" => [
        "id" => env("FILAMENT_KB_ID", "knowledge-base"),
        "path" => env("FILAMENT_KB_PATH", "kb"),
    ],

    "docs-path" => env("FILAMENT_KB_DOCS_PATH", "docs"),

    "model" => \Guava\FilamentKnowledgeBase\Models\FlatfileDocumentation::class,

    "cache" => [
        "prefix" => env("FILAMENT_KB_CACHE_PREFIX", "filament_kb_"),
        "ttl" => env("FILAMENT_KB_CACHE_TTL", "forever"),
    ],
];
eelco2k commented 3 months ago

you're caching infinite so try to clear cache php artisan cache:clear and the docs folder in is your root project folder with

docs (folder) -> en (folder) -> proloque (folder) getting-started.md (file)

Scherm­afbeelding 2024-07-28 om 18 43 47

OlyaK95 commented 3 months ago

you're caching infinite so try to clear cache php artisan cache:clear and the docs folder in is your root project folder with

docs (folder) -> en (folder) -> proloque (folder) getting-started.md (file)

Scherm­afbeelding 2024-07-28 om 18 43 47

I did php artisan optimize:clear I also tried delete Chrome cache Then I deleted my docs/ru directory and recreated it

Now I have error image

eelco2k commented 3 months ago

And I assume you also registered the plugin in you PanelProvider of you filament panel? as otherwise it would not show up in routes list.


->plugins( [KnowledgeBasePlugin::make() ])

If this does not work i'm also out of options as here v1.9.0 it works, with same config (except for the "forever")
OlyaK95 commented 3 months ago

And I assume you also registered the plugin in you PanelProvider of you filament panel? as otherwise it would not show up in routes list.

->plugins( [KnowledgeBasePlugin::make() ])

If this does not work i'm also out of options as here v1.9.0 it works, with same config (except for the "forever")

Of course 2024-07-28_19-49-38

eelco2k commented 3 months ago

i see that the FlatfileDocumentation class uses Sushi package which uses by default an sqlite db (which is just a binary file in the project) it tries to insert the data into this sqlite file but the syntax is incorrect. So you haven't edited the the vendor/guava/filament-knowledge-base/ files?

perhaps also remove calebporzio/sushi from vendor folder.

to be sure: remove this folder, and run composer install again. it will redownload the whole package. furthermore you are sure you don't use any special characters in the *.md files?

eelco2k commented 3 months ago

also make sure sushi works correctly and it meets your requirements: https://github.com/calebporzio/sushi

eelco2k commented 3 months ago

sqlite file should be in folder : storage/framework/cache/sushi-xxxxxx.sqlite

eelco2k commented 3 months ago

as written in de readme of sushi, if it cant create an sqlite file it will use in-memory. you'll then have to check whether there are any .env requirements needed for that or that it just works out of the box (the fallback with in-memory)

OlyaK95 commented 3 months ago

i see that the FlatfileDocumentation class uses Sushi package which uses by default an sqlite db (which is just a binary file in the project) it tries to insert the data into this sqlite file but the syntax is incorrect. So you haven't edited the the vendor/guava/filament-knowledge-base/ files?

perhaps also remove calebporzio/sushi from vendor folder.

to be sure: remove this folder, and run composer install again. it will redownload the whole package. furthermore you are sure you don't use any special characters in the *.md files?

No, I don't edit any files in this folder.

I did it, reinstall package 2024-07-28_20-23-31

OlyaK95 commented 3 months ago

sqlite file should be in folder : storage/framework/cache/sushi-xxxxxx.sqlite

I have no file sqlite(

eelco2k commented 3 months ago

I think you have to debug further. as normally it should work. try dd() instead of the return statement of the FlatfileDocumentation.php Models file in the public function getRows() {

return collect(.....)->toArray();

change temporary to:

dd(collect(....)->toArray());

you should get something like this:

array:1 [▼ // vendor/guava/filament-knowledge-base/src/Models/FlatfileDocumentation.php:35
  0 => array:9 [▼
    "id" => 
Illuminate\Support
\
Stringable {#5526 ▶}
    "slug" => "proloque/getting-started"
    "path" => "/projectdir/docs/en/proloque/getting-started.md"
    "content" => """

<h1 class="text-3xl mb-2 [&amp;:first-child]:mt-0 mt-10 relative"><a id="introduction" href="#content-introduction" class="gu-kb-anchor md:absolute md:-left-8 m
 ▶

      <p class="mb-4 [&amp;:last-child]:mb-0 leading-relaxed">Lorem ipsum dolor ...</p>

      """
    "title" => "Getting Started"
    "group" => "Proloque"
    "icon" => "heroicon-o-book-open"
    "parent" => null
    "order" => null
  ]
]

DON'T FORGET TO REVERT THE dd() ...!!!

OlyaK95 commented 3 months ago

@eelco2k I got this

2024-07-28_20-31-52

eelco2k commented 3 months ago

I think i know the issue: it's in windows right? as the path is D:\

it uses all \ instead of /

those will not get replaced...

i think because \SplFileInfo $file works in windows differently...

some sort of

 ->replace('\\', '/')

has to be added

eelco2k commented 3 months ago

So not fully related to the package.... but GuavaCZ could do some find and replace...

for now i would suggest run the laravel project in laravel sail with WSL. you'll have linux containers for php etc. and you don't have the issue i bet

OlyaK95 commented 3 months ago

I think i know the issue: it's in windows right? as the path is D:\

it uses all \ instead of /

those will not get replaced...

i think because \SplFileInfo $file works in windows differently...

some sort of

 ->replace('\\', '/')

has to be added

You are right, it is Windows OS.

OlyaK95 commented 3 months ago

So not fully related to the package.... but GuavaCZ could do some find and replace...

for now i would suggest run the laravel project in laravel sail with WSL. you'll have linux containers for php etc. and you don't have the issue i bet

I am so grateful to you, thank you. I will wait GuavaCZ answer now.

lukas-frey commented 3 months ago

Yeah, sorry, I will have to recheck all the classes and fix the path separators for all OSes. Thanks for the info.

@eelco2k Not sure if you fixed your issue, but as @damms005 suggested, the part where you configure your knowledge base panel (KnowledgeBasePanel::configureUsing(...)) has to be done in the register method, not in the boot method.

This is because Filament registers all panels in the register phase. If you run it during boot, the panel will already be registered and all your customisations will not be applied by then yet.

eelco2k commented 3 months ago

@lukas-frey Yes fixed it 👍