Code can be found in Github:
In general there are couple of main points why use static site generator like Eleventy:
Netlify have good article about what are the benefits of using static site generators.
For me it’s the freedom to be in charge about everything in front-end. And it’s also like going back to roots when serving static HTML.
And it’s also like a breath of fresh air to check something new once and for a while. Eleventy is perfect fit for me for that. It’s simple enough but yet powerful.
I want to simulate real world needs where solid CMS is needed for content editors. Clients have been happy with the block editor for getting their rich content published.
And I have been playing around with WordPress for a long time. It saves me back-end developing time. I’ve been pretty happy about block editor myself.
I’ll try to write more detailed articles in key concepts later on but here are the development process in general.
After that we repeat the same pattern for every peace of data we need from REST API.
It makes no sense to fetch data from WordPress REST API every time you make a tiny change in your template file. It would be super slow experience when developing the site in Eleventy.
So let’s cache the results locally! There is great NPM package flat-cache for that.
There is also eleventy cache assets, which also uses flat-cache.
WordPress is installed in subdomain. Although I have a little weird setup when WordPress is under different main domain in
Because nothing needs to render in front-end from WordPress theme
style.css are basically empty.
Other than that it’s just setting some Gutenberg block editor theme supports. And whatever you might need in the admin or in the editor.
Note that I enqueue editor styles from the live site directly.
wp_enqueue_style( 'editor-style', 'https://foxland.fi/assets/editor.css', null, null );
This is handy because Eleventy can handle editor styles at the same time it handles front-end styles. And I get to enjoy same styles in the editor. Nice!
Custom Plugin registers some post types and custom blocks. In this case they could have been in theme also since theme doesn’t really handle anything else than admin related stuff.
Only other plugin is Headless Mode.
But this really isn’t going to scale, is it. There needs to be some kind of automated process for deploys when new content get published.
One solution is to trigger Netlify build automatically using Netlify build hook and IFTTT. This could be set every day or in every hour (or whatever frequency you’d like).
It would also be handy to call
https://api.netlify.com/build_hooks/YOUR_ID_HERE directly from WordPress admin when needed. It could happen automatically when new content is Published or manually clicking “Build site” button when there have been updates on content.
I need to play around with this but for now once per day using IFTTT is enough for me. Build time can also be minutes or even more if the site is big. In my case it’s just 1-2min. This is something to consider if client want to publish content pretty much immediately.
Here are couple of links where I have learnt Eleventy: