Static Site Generator Plugin

:wave: With this plugin you can create a directory with assets, media and static html files generated from your pages, which you then could e.g. simply upload to a CDN.

This is from the functionality somewhat similiar to @fvsch 's StaticBuilder plugin, but for Kirby 3.
There might be still smaller quirks to iron out (e.g. sometimes unnecessary media file version creation while no change to the file was made), so I am happy for feedback.

The company I work for uses the plugin when triggering the deployment to production (CMS environment serves kirby and the panel while production just serves the plain html version).

6 Likes

Hello jonathan, in the panel of kirby 3.22, I can’t find the button that shows “Click the button to generate a static version of the website.”
Once I put the plugin into site/plugins/static-site-generator, I will see this build button, isn’t it, or I am missing some steps?

No, you have to add a field to one of your blueprint and there’s also a config setting you have to set, see the steps in the readme.

1 Like

Hello Jonathan,

great plugin so far. Thats almost what I searched for. Do you think, that there is a simple way of making all urls relative?

This is so cool! I finally added it to the plugin directory. Sorry that it took so long.

2 Likes

After submitting the build button, why do I always get the prompt “mkdir(): No such file or directory”?
Kirby v3.2.5
My config.php

'd4l' => [
        'static_site_generator' => [
            'endpoint' => 'kirby-ssr',
            'output_folder' => './static',
            'preserve' => [],
            'base_url' => '/static/',
            'skip_media' => false,
            'skip_templates' => []
        ]

I can generate an HTML file but I am missing a resource file.
I have to manually copy the assets folder to the build directory.

Thanks for adding it to the plugin directory @bastianallgeier ! :slight_smile:

@taoguangc The config you posted works fine for me (tested with starterkit + kirby 3.2.5) - do you have a setup with symlinks? Or is there maybe an issue writing (to) the output folder? (maybe one of the folders within the output folder belongs to another user?) And are you using the latest version of the plugin?

In any case it would be great (unless the issue is already solved) if you could create this as an issue in the github repo so that we have a central place where bugs are collected, thanks!

Thank you @jonathan-reisdorf ! I don’t know coding very much. so I describe my setup process in detail.

  1. I run XAMPP in Windows environment, PHP 7.2.
  2. I downloaded the latest starterkit package and placed it in the root directory.
  3. modified site\blueprints\site.yml, add
...
- width: 1/2
     Fields:
       staticSiteGenerator:
         Label: Generate static stie
         Help: Click the button to generate a static version of the website.
         Progress: Please wait...
         Success: Static site successfully generated
         Error: error
  1. modify site\config\config.php,
return [
	'd4l' => [
        'static_site_generator' => [
            'endpoint' => 'kirby-ssr',
            'output_folder' => './static',
            'preserve' => [],
            'base_url' => '/static/',
            'skip_media' => false,
            'skip_templates' => []
        ]
    ],
    'debug' => true,
];

Windows! I never tested in Windows. I’ll do that one of the next days. I assume the path resolving is not working there (/ vs. \ or sth. the like)

@bastianallgeier DS is set to '/' in https://github.com/getkirby/kirby/blob/master/config/setup.php#L6 which is probably perfect for most of us, but for Windows users wouldn’t

define('DS', DIRECTORY_SEPARATOR);

be better?
But if we don’t want to break existing kirby sites which might rely on DS always being /, I can also convert all DS to DIRECTORY_SEPARATOR in the plugin code.

@taoguangc I use DS a lot in the code for path resolving, which is why the plugin breaks for you when copying the assets.

@taoguangc a PR to solve the issue has been created: https://github.com/d4l-data4life/kirby3-static-site-generator/pull/22

Thanks for the reply, great job! It works fine with Windows.