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).
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?
@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.
I run XAMPP in Windows environment, PHP 7.2.
I downloaded the latest starterkit package and placed it in the root directory.
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
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.
i managed to install the plugin but whenever i click the āgenerate static htmlā button i get an error stating: āThe JSON response from the API could not be parsed. Please check your API connection.ā
i didāt customize the API or anything so iām not sure where to look for the solution of this problem.
my config is setup like this:
'd4l' => [
'static_site_generator' => [
'endpoint' => 'generate-static-site', # set to any string like 'generate-static-site' to use the built-in endpoint (necessary when using the blueprint field)
'output_folder' => './static', # you can specify an absolute or relative path
'preserve' => [], # preserve individual files / folders in the root level of the output folder (anything starting with "." is always preserved)
'base_url' => '/', # if the static site is not mounted to the root folder of your domain, change accordingly here
'skip_media' => false, # set to true to skip copying media files, e.g. when they are already on a CDN; combinable with 'preserve' => ['media']
'skip_templates' => [] # ignore pages with given templates (home is always rendered)
],
],
if something screams āerror!ā to you please help out.
yes debug is set to true and i donāt have multiple return arrays. The only other things in my config are some custom routes as well as the panel install.
As this is just a generic error which says that anything else than a json has been returned, could you please have a look into your network tab and post the output of the generate-static-site call here?
{āstatusā:āerrorā,āmessageā:āNo route found for path: "generate-static-site" and request method: "GET"ā,ācodeā:404,āexceptionā:āExceptionā,ākeyā:null,āfileā:ā/kirby/src/Http/Router.phpā,ālineā:153,ādetailsā:,ārouteā:null}
Yes, thanks. Hm, this is weird. The plugin does not attempt to make a GET call but a POST call, which is why you get this error when making a GET call instead. Iāll see if I can duplicate the issue. The more contextual information I have the better, e.g. what OS do you use, can you post your full config.php, how did you install the plugin (manually / composer), how does the blueprint look like where youāve added the field etc.
iām using mac os, i installed the plugin manually by downloading the zip from github, unziping it, renaming the folder āstatic-site-generatorā and moving it to the plugins folder of my kirby installation. Iām testing everything locally atm by running a php server via terminal.
this is my full config.php:
<?php
return [
'debug' => true,
'routes' => [
[
'pattern' => 'kategorien/(:any)',
'action' => function ($tag) {
if ($page = page('kategorien/' . $tag)) {
return $page;
} else {
return page('inserate')->render([
'tag' => $tag
]);
}
}
],
],
'panel' =>[
'install' => true
],
'd4l' => [
'static_site_generator' => [
'endpoint' => 'generate-static-site', # set to any string like 'generate-static-site' to use the built-in endpoint (necessary when using the blueprint field)
'output_folder' => './static', # you can specify an absolute or relative path
'preserve' => [], # preserve individual files / folders in the root level of the output folder (anything starting with "." is always preserved)
'base_url' => '/', # if the static site is not mounted to the root folder of your domain, change accordingly here
'skip_media' => false, # set to true to skip copying media files, e.g. when they are already on a CDN; combinable with 'preserve' => ['media']
'skip_templates' => [] # ignore pages with given templates (home is always rendered)
],
],
];
this is my sites blueprint:
title: Home
fields:
staticSiteGenerator:
label: generate static html
Bilder:
label: Bilder
type: files