Garfieldtech

Technical thoughts, tutorials, and musings

GarfieldTech version 3, now on MiDy

Posted:

You may notice some style changes around here. Like, a lot of style changes. That's not all that's changed, in fact.

This is the official launch of the third iteration of my personal website. This time, it is built almost entirely from scratch using my own tooling: MiDy. Which is, incidentally, now available for public use.

I've been working on MiDy for just about two years, on and off. (It didn't take 2 years to write; I have an almost-2-year-old. You do the math.) The first alpha was posted last year, though for various reasons I couldn't get back to it until more recently. But it is now ready for public beta.

But... why?

I'm a software engineer. Why not?

But more seriously, I have wanted to migrate my website off of Drupal for a long time. It's been on Drupal for (checks notes) 19 years and 10 months, and before that it was an unthemed WordPress site. So why move away from Drupal after 20 years?

  1. Modern Drupal is serious overkill for a personal site, and I wanted something simpler.
  2. In particular, something completely managed via Git and files-on-disk.
  3. Theming Drupal is a pain, but the default theme I've been using has serious bugs that I never figured out how to address (and were never fixed upstream as far as I can tell).
  4. I didn't want to keep supporting a project lead by a known cheater, liar, autism-shamer, and biggot.

But wait, aren't there lots of other static site generators on the market already? And flat-file CMSes? There are, but none of them offered the features I wanted. I did spend time looking into them. Really. :-) But eventually I decided that what I wanted would be easier to build myself.

Of course...

We do these things not because they were easy, but because we thought they would be easy.

The engineers' curse...

So what is MiDy?

MiDy is a tool for building Mildly Dynamic websites. It is in concept inspired by this blog post, which is where the name came from.

The goal of MiDy is to get as close as possible to "just edit web pages on disk" without losing dynamic content, or runtime capabilities. Many static site generators already exist of varying quality, but none allow actual logic to run on the server once the site is generated. MiDy does.

There are many flat-file CMSes on the market, but none that I know of support mapping paths-on-disk to URLs in a non-1:1 way with custom ordering. MiDy does, because I needed that for my blog archive.

MiDy does not require site rebuilds or a watch process or anything like that for testing and development. By default, it just renders and serves pages like any other PHP application. However, you can pre-render static files if you wish in production, for better performance. Dynamic POST requests will still work, even then.

MiDy lets you build pages in several ways. The main ones are Markdown files (like everyone else) or a raw Latte template. I know Twig is more popular, but having worked with both, I greatly prefer Latte as a template engine. It's much easier to use if you're used to PHP (like, say, me), but still works on largely the same principles as Twig or most other template engines. That multi-type support makes it really easy to have most pages follow a standard template, but some then do something completely different. Want a regular blog or event or product listing? Cool cool, Markdown is easy. Want a paginated listing page? Build it exactly how you want in a template. They'll both look perfect together.

In particular, aside from the "current page," templates in MiDy are able to query (but not write to) the database, through a dedicated API. (See the MiDy readme for more details.)

OMG, templates that are reading data instead of having it all passed to them, spaghetti code!

Yes. Exactly that. But it's not spaghetti. If anything, it's vastly easier. MiDy has a very simple data model that is easy to expose, which makes building "pull-based" queries in templates trivially easy, and still completely safe.

For example, that "related posts" block on the side? That's all populated right from the template. There is no controller to figure out if it needs to be preloaded and on what pages and forward it through and hope that it's not missing when the template needs it. The template just takes the current page, runs a query, and loops over the result. It's all view logic, so it belongs in the view layer.

We used to build sites this way, until Ruby on Rails and DHH told us it was wrong. We listened. We perhaps should not have. This is an area I am going to explore further, both in MiDy and separately.

The built-in theming is extremely light. Just a few structural bits to make life easier, all of which you can override if you'd prefer. Pluggable themes are something I'd like to add in the future, but for now, all sites are custom-themed.

Oh yes. And MiDy is 100% Organic. Every single line of first-party code in it was written by a human. (I cannot vouch for all dependencies, but the ones with my name on them are AI-free.) If that matters to you, know that MiDy is ethically-sourced. If that doesn't matter to you, please go read my earlier post on Selfish AI.

So what's with this site?

The new Garfieldtech was hand-crafted and hand themed. There is no Tailwind, no Bootstrap, no framework of any kind. Just the web. Modern HTML and CSS are absolutely banger. Really, the age of CSS frameworks has come to an end, and it's time more people realized that. CSS itself can do almost everything you need, and the few things it can't can be handled by web components. I know people that would build a site like this with React. Those people are wrong.

At this time, there is exactly zero Javascript on this site. It's just a straightforward responsive dark-mode-enabled CSS file. Not even a particularly large one. That may change in the future if I add a self-hosted analytics system or stuff like that, but at least for now, Javascript is simply not needed.

I will almost certainly continue to evolve the design, now that it's so much easier for me to own it fully.

Oh, and did you notice that Atom feed on the right? Go ahead and subscribe to see my latest thoughts, tutorials, and musings. It's dynamically generated, too. Latte is cool like that.

What does the future hold?

For this site, hopefully more frequent posts. I've been holding off on a lot of posts for a while, waiting for the relaunch. That... may not have been the smartest thing I ever did, but meh. I want to write more, and I've now removed technical blockers for doing so. No more excuses, Larry!

For MiDy, there's definitely stuff I still want to work on. There's a few bugs left to squish. I want to add support for Djot and Carve files in addition to Markdown. I'd like to add support for installable themes and other extension points. And make sure it will run under FrankenPHP.

Please do give MiDy a try! It should be pretty stable and is good enough for non-mission-critical sites already. If something is unclear in the documentation, file an issue or talk to me in the PHPC Discord (I'm Crell). If you want to help out (yay, Open Source!), do the same. (Please don't open a PR for a new feature without talking to me first.)

In these times, we should all be focused on maintaining our digital autonomy. Consider this my contribution to the cause.