Static Site Update

This site has been static for a few days now, and one of the things I have been working on today is dealing with exports. I write many blog posts in advance and drip feed them to meet my video releases, for example.

On WordPress, this was 100% reliable; it’s all there. I host with GridPane, so I have GP Cron, too, to handle the scheduling, but now that I’ve gone static, this wasn’t possible.

Project Criteria

Now, the criteria of this project were clear to me almost immediately.

  • It should be automatic
  • It should automatically post and export for scheduled posts or pages
  • It should also automatically run if I save a bricks template
  • It should have a delay built in if I am making lots of small changes to prevent too many exports
  • I wanted to know if it had run and with logging

As with my Gridpane, Server Avatar, Main WP Updates, and Repo, I wanted to use my Discord group, where I get these sorts of notifications, so it should use a bot’s webhook to tell me.

Hooks & Post Types

In the end, I settled on reading post types and selecting the ones I wanted to trigger the plugin. This means this was going to need an admin area, and before that, I needed to find a way to know when the updates happened.

Update Happened: this was easy, using the post types above and wp_after_insert_post to check it isn’t an autosave or a revision. We could then look to see if it was a post status of Publish And from there, if it were in my selected post types

Running our Export: running our export was achieved by checking if simply_static is installed and then pulling it into an instance $plugin = Simply_Static\Plugin::instance(); and then from there running a static export $plugin->run_static_export()

Knowing when our export has completed: I couldn’t find a documented hook or item for this one so l looked through the code and found a few for testing, but given the base plugin is on GitHub I decided to look through issues and commits I then found the following pull request and from there this commit which gave me the answer I was looking for ss_completed This runs once the upload is completed, too, which means in my case with Bunny.net, I am actually completely exported when this runs.

Debugging: I added a debug switch and a custom log file in the code to allow me to view the output and comments to check for debugging.

Building a Plugin

So now I began putting this all together first into several small snippets and testing each individual part to check how it would work and refining it but I quickly had a working concept and then a began converting this to a plugin I could use and test.

Our Admin Screen:

Simply static export and notify admin page

This is what I’ve settled on for an admin screen, it is nested directly under the Simply Static menu, which is simply-static-generate And it is a new export/notify menu item

  1. This is my debug toggle
  2. This is the time to wait before exporting on the trigger. I’ve defaulted this to 5 mins, which allows for lots of small changes to be uploaded together,r but depending on how time-sensitive your posts are, this could be reduced or significantly increased. I am starting at 5 minutes and will review regularly.
  3. These are the post types I want to apply the trigger to
  4. Destination Domain: This is the site that will be showing the static output in my case https://techarticles.co.uk (this is used in the Discord notification)
  5. Our Discord Webhook URL
  6. Notification logo, I’ve defaulted this to the Simply Static logo included in the plugin I am building, but my site is behind basic auth, so it can’t be reached, so what I have done in this case is upload it to my site and linked to that you may also want to use your sites fav icon
  7. Modification of the message sent to Discord
  8. Custom log File location
  9. A link to the log file will show here when there is something to see. If debug is enabled, the log file is automatically removed. If you disable logging

Discord Notification

I then worked on the Discord notification using the details from the admin screen below, and have a finalised notification that looks like this

Simply static export and notify discord

The top link is to the exported site, and the bottom link is to the WordPress site; this allows me to quickly check the export and the site from my device as soon as an export takes place.

Why not use the built-in filters?

This is really easy. They didn’t do what I wanted. This site is built up of dozens of categories and posts, and as such, each published post shows up in more than one place.

Some Example – I change the bricks template for the archives, they all need to be regenerated ssp_single_auto_export doesn’t facilitate this. As an example, I also don’t think it generates the category archives on export of single posts.

Add in the fact that this will stack edits to export. Sometimes, I make a lot of edits at once with the flexibility of the lead. In time, I could even modify this before an editing session to make sure a single generation and update is handled using this methodology, which I couldn’t do with ssp_single_auto_export.

As far as the documentation shows, there are no external notification settings, i.e Discord.

Future Plans

I have a few more hours of development ahead of me today, but my hope is to release this plugin over the Bank Holiday Weekend. I will use my drop-in automatic updater, which has been heavily revised for updates. I still want to get the logging correct—not too much but also not too little. I will do some more testing, but I hope to have an initial release version, likely 1.1, as I am already using it internally by the end of the Bank Holiday Monday. I will record a video and another article for release.

Support the Author

buy me a coffee
Really Useful Plugin Logo
Wpvideobank temp
Appoligies for any spelling and grammer issue. As a dyslexic i need to rely on tools for this they like me are not perfect but I do try my best