StaticBuilder - Kirby as a static site generator


(One person has reported that it doesn’t work for them, but in my tests it always worked. :stuck_out_tongue:)


You can decide to not copy the content directory:

c::set('staticbuilder.assets', ['assets', 'thumbs']);

But if you’re referencing files from the content folder directly in your HTML, for example if you have some pages that output <img src="/content/2-my-page/1-sub-page/cool-image.jpg" alt="…">, not copying the content folder is going to be an issue.

StaticBuilder does not include an option to only copy images from the content folder because Kirby pages can have all sorts of associated files that are referenced publicly in the HTML, in any format: image, PDF, SVG, audio or video, and even plain text.

Alternatively, you could use the withfiles option, but note that files will be copied to a different location than the URL produced by the (image: …) KirbyText syntax (or $file->url()), so this only works for files you’re linking to yourself using HTML or Markdown syntax (for example: <img src="cool-image.jpg" alt="…">).


Uploading files with the content extension (txt or md) is not possible, it will also break the CMS because Kirby will determine the template based on the first text file it finds.
So you could filter out content text files by default without breaking anything in the site (please use the content.file.extension option as the file extension is configurable).


I am no PHP coder, where should this be added in the code of this great plugin?


To copy the content folder file-by-file while excluding some files (for example *.txt files), one would have to rewrite the code that copies folders defined in the staticbuilder.assets config:

But maybe filtering out *.txt files for all folders is not great, so I could keep this implementation for copying folders but special-case copying the content folder.

But I don’t think I want to delve into that kind of complexity; StaticBuilder is already very complex as it is. So my proposed solution would be to avoid putting confidential information in your .txt files (that’s a good practice for when using Kirby to serve your site; confidential information should only go in your site/config/config(.*).php files, if not in an even more secure location).


Hello there. I’ve worked a bit on a v3.0 of this plugin, and would appreciate if some people watching this thread wanted to test it and report any issues.

There’s a bit of a changelog here:

Install can be done by downloading the v3 branch, or require "fvsch/kirby-staticbuilder": "^3.0.0-beta.1" with Composer. Please report issues in GitHub if possible. Many thanks!