From 0e0fcec7287f4d87985a3cfbcdef4c5570b19aa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Thu, 27 Feb 2025 13:50:01 +0100 Subject: [PATCH] Blog: add post on static site generation. --- .../2025-02-27-static-site-generation.cfg.php | 6 ++ ...2025-02-27-static-site-generation.html.php | 57 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/blog/2025-02-27-static-site-generation.cfg.php create mode 100644 src/blog/2025-02-27-static-site-generation.html.php diff --git a/src/blog/2025-02-27-static-site-generation.cfg.php b/src/blog/2025-02-27-static-site-generation.cfg.php new file mode 100644 index 0000000..b14dd03 --- /dev/null +++ b/src/blog/2025-02-27-static-site-generation.cfg.php @@ -0,0 +1,6 @@ + diff --git a/src/blog/2025-02-27-static-site-generation.html.php b/src/blog/2025-02-27-static-site-generation.html.php new file mode 100644 index 0000000..3e71be0 --- /dev/null +++ b/src/blog/2025-02-27-static-site-generation.html.php @@ -0,0 +1,57 @@ + + +

+Over the course of the decade (maybe more) that this website has been around +I've gone through a few different frameworks and infrastructure for it. Although +usually this would be going back-and-forth between PHP and some static site +generator. For a while I've used Saait,[1] which +was perfect for my goal of simplicity, but was not at all flexible enough for +what I wanted. It seems to be intended for a website that contains a single page +and then a bunch of blog posts (not my setup), and so for a while I had a +somewhat jury-rigged setup. +

+ +

+Seeing this as an issue, I decided to try my hand at writing my own static site +generator. There were a few failed projects like this, but I normally ran into a +few errors normally because of the language I would try to write the program in. +There was a time where I would try in Rust just for the heck of it, but I would +get bogged down by the compiler whining at me. Later I would try again in Bash, +but that was silly because of all the limitations that Bash presents (even Saait +isn't written completely in Bash). I finally started working on one in C (in a +private repository at the moment), but at this point in my life I'm much too +busy to actually work much on it. +

+ +

+Ultimately, with all this going on, I decided it was time to try out static site +generation with PHP. Confused? Just run the PHP program on one of your PHP +scripts. It outputs the exact same thing. All I needed to do really was to write +a script that would go through all the PHP code in my website and output it as +an HTML file (or XML in the case of RSS and Atom feeds). The only caveat was +going to be my blog, which could get messy because of how I would need to access +certain metadata about my blog posts (e.g. title or date) in order to generate +both the blog page (to generate the page automatically) or the RSS and Atom +feeds. This I solved by simply having files suffixed with .cfg.php +which would not be processed. +

+ +

+All this added up to the phpsg.sh script[2], +which I had added to my repository. It's licensed under the Zlib license, if you +want to use it for your own websites. Hopefully I may continue to develop my +static site generator in C, but until that's done, this is a decent substitute. +

+ +
    +
  1. Saait: a boring HTML page generator - Codemadness
  2. +
  3. themusicinnoise-site/phpsg.sh at 07527f8e33aa6ed2ffc303c971f383190a7925aa - themusicinnoise-site - Ortega Code
  4. +
+ +