Website Version 5
Back to Rust...I rewrote my website again!
TLDR
- PHP → Rust
- Static HTML templating → HTML inside Sqlite
- Writing posts in-repo → Web post creator
- GitHub → Tangled
Whyyyyy?
I'm unemployed. I really hated the previous posting model of having to commit HTML to a git repo, commiting it, pushing it, git pulling on the other end, etc. With this new site, I can edit posts directly into a Sqlite DB.
The Stack
Umm. I'm using Rust now. To "simplify" this, I will present this simple diagram.
I could have probably done this all in PHP. But it would have been a lot messier.
The "Templating Engine"
I like maud a lot. I've been eyeing it up for a future project. Let me explain the appeal.
Most Rust templating languages (minijinja) look like this:
You have to specify this in a separate file, and serialise any types you use. It's kind of annoying and necessitates something like serde to do wizard magic to your structs and enums. Maud looks like this:
html! {
h1 { "Hello, world!" }
p.intro {
"This is an example of the "
a href="https://github.com/lambda-fairy/maud" { "Maud" }
" template language."
}
}
You really can just put this as the return type of a function. It's so much nicer. I don't have to fumble with a bunch of named .html.jinja files and all of your templating is "just there" with the code. It's honestly what I love about PHP so much. As a plus, you can just put any expression and splice it into your templates. Yes, you can nest this. It's ugly.
Ok, but why do you have a HTML rewriter?
Uhhmm. Well so I made a web editor for creating new posts.
So, this necessitated a move from the previous way I was doing the 'speech-box' element (this thing!). Previously, I was using PHP to template-in the begin and end text around it, with a function to alternate between pictures.
I wanted to add a custom element. On web, this is pretty simple. On the server, however, I am just feeding HTML into maud. So, I wrote a rewrite rule in lol-html:
It's somewhat gross, but it means I don't have to run JS just to put funny images on the screen. I don't want to deal with layout shift and FOUC and all the other annoying client rendering issues.
Now I can just do this and not worry about it:
The Web Framework
I have so little to say aboutpoem. Which is really awesome! If you have used axum before, it's basically just that but with everything you want bundled inside. No more tower_sessions!! It's nice. I like it.
Moving to Tangled, and other thoughts
Unsure what to think about 'git forges' in general. Ideally, there would be a perfect code forge that:
- hosts all of you stuff for you, for free, forever
- isn't hosted by a for-profit corporation
This doesn't really exist, but Tangled is a step towards this. It's built on ATProto (which is decentralized), therefore you can log in with your Bluesky account. You can host your own code storage (so if Tangled Corp Inc™ annoys you personally, you can move your data away from them) but I don't care about that too much. I like how the frontend feels much lighter than GitHub. I probably won't move all of my projects to this though (yet?)
Using jj
I decided to try Jujutsu for this project. I like it a lot! It's a version control system that "wraps over Git" and lets you control the underlying data in a different way. My favorite feature is that you can write what you do before you do it, instead of trying to name what you have done after the fact. It's mostly a psychological thing, but I feel like this helps me stay focused on what I set out to do.
I would suggest trying it if this seems interesting to you, or if Git confuses you a lot.
That's all I have to say for now. I did a decent amount of work, and theres a lot of stuff I didn't bother mentioning. (Check out the new footer!) Feel free to look around my code. It's a little bit messy right now, but it's not mission-critical code. Feel free to steal it for your own website if you want, I don't care. (Just respect the LICENSE!)