Last Month I Made a Website
Last month (or two) I made a website. This website! It’s nothing too fancy, just a static site that’ll serve as a blog and a playground for any CSS or javascript magic I want to try.
I’ve made stuff like this before, all powered by Jekyll. One was a template for Jekyll (that is desperately in need of a facelift,) that was designed for event information and locked behind a password. That project was part of removing myself from social media platforms, but also not wanting to descend completely into hermit-hood.
This site however, is built by a static site generator written in Elixir that used this tutorial as a jumping off point. So far I’m a fan of doing this all bespoke. Extending the code to fit my own needs has been relatively straight-forward and when it’s not, I know that’s my fault.
Beyond The Basics
So what did I add on top of converting markdown files to HTML? A few things!
- Sitemap and RSS generation on deploy
- Different page styles and layouts for a post index, page not found, about page, and posts.
- Local server and router to preview the site before deploy
- Github actions to deploy to a specific branch, which my host pulls from
- Formatting and linter configs to keep me honest.
mix
tasks to generate posts, run site, etc.- Comments powered by bluesky skeets.
So far the most challenging part was trying to massage the output of older packages into my own XML files for the RSS feed or the Sitemap. Luckily, xml_builder
was easy enough to use that building from scratch worked pretty well.
For the time being this code is too messy to release. Plus I don’t know if there’s any value in another static site generator existing. Kind of feels like starting another podcast about bad movies. Maybe after I re-learn how to do testing in elixir, and set up file watching so local development doesn’t involve so much manual rebuilding.
But what’s a dev’s blog post without a code example? Here’s my generate/2
function, which creates the markdown file with the necessary timestamps for me to start writing a new post.
@spec generate(String.t(), String.t()) :: :ok
def generate(title, tags) do
{_, generated_at} = DateTime.now("America/Chicago")
formatted_title =
title
|> String.downcase()
|> String.replace(~r/\s+/, "-")
formatted_tags =
tags
|> String.split(",")
|> Enum.map_join(" ", fn tag ->
tag
|> String.trim()
|> String.replace(~r/\s+/, "_")
|> String.downcase()
end)
datetime_string = Calendar.strftime(generated_at, "%m-%d")
filename =
"#{datetime_string}-#{formatted_title}.md"
headmatter = """
%{
title: "#{title}",
author: "#{Sancho.author()}",
tags: ~w(#{formatted_tags}),
description: "",
published_at: "#{DateTime.to_iso8601(generated_at)}",
updated_at: "#{DateTime.to_iso8601(generated_at)}",
}
---
"""
File.write!(
Path.join([
posts_dir(),
Integer.to_string(generated_at.year), filename
]),
headmatter
)
end
Checking for comments…