d4l-data4life / kirby3-static-site-generator

Static site generator plugin for Kirby 3+. With this plugin you can create a directory with assets, media and static html files generated from your pages. The result is an even faster site with less potential vulnerabilities.
MIT License
138 stars 7 forks source link

Question: Is it possible to move /error/index.html to /404.html using custom routes? #49

Closed bytesource closed 2 years ago

bytesource commented 2 years ago

This is not a bug report, but a question about what custom routes can do.

For proper error handling, Cloudflare Pages, where I host my static files, looks for a file 404.html in the root folder: https://developers.cloudflare.com/pages/platform/serving-pages/#not-found-behavior

However, after running kirby3-static-site-generator, the actual error page is located at /error/index.html.

Therefore, what I'd like to know is this: Using custom routes, is it possible to move index.html from /error to the root, and renaming it to 404.html (/error/index.html -> /404.html)?

I tried the following, but it didn't work:

'd4l' => [
        'static_site_generator' => [
            'custom_routes' => [
               [ 
                   'path' => '404.html', 
                   'page' => 'error' 
               ],
            ],

            'endpoint' => 'update-static-site',
        ]
    ]

Any suggestions are highly welcome!

Cheers,

Stefan

Expected Behavior

Current Behavior

Possible Solution

Steps to Reproduce

Context

jonathan-reisdorf commented 2 years ago

Hi @bytesource :wave: Sorry for the late response. So far, the static site generator does not yet support this as it always appends /index.html to the generated file path. Technically it seems feasible to detect paths ending in a file name and using that one instead of index.html. I will try this out once I have time this week and let you know when there's progress :)

bytesource commented 2 years ago

Hi @jonathan-reisdorf,

That would be fantastic indeed. Thanks a lot for this project!

jonathan-reisdorf commented 2 years ago

I've created a PR for this which should solve your issue. Hint: Using custom routes, your error page will not be moved to the new url, but copied, so it will be created in both places: 404.html and error/index.html. If you don't want this, you'd have to manually exclude the error page from the static site building, or use a custom page model that will change the error page's url instead of using custom routes.

bytesource commented 2 years ago

Wow, thank you so much! Thanks to your plugin, now I truly have a static site that's blazing fast.