Stage one separation

Posted 2019-04-10 02:44:38 UTC

Series: blog_webserver

Part 1

Turning bugs into features


Before even starting back up on blog_webserver, I had an idea. Earlier, Benjamin and I were discussing how to implement regular image serving. I had gotten it to work in a weird way which allows viewing non-.md files both with and without their extensions visible in the browser. The extensionless viewing is considered a bug, so I've been thinking about how to fix this issue.

The way post loading currently works is (approximately) this:

  1. Take the web url
  2. Prepend /home/
  3. Insert /blog after blogger
  4. Append .*
  5. Glob search for files, grab the first successful path
  6. Load that, process it, serve the result to the browser

It's not too hard to see how this introduced the above bug. The issue is, how can it be fixed without breaking links? I do have the option to ignore this issue, given nobody knows about me, but I don't want to have to go through the few posts I have and update all the links. It would also be nice to get rid of the globbing, because it's a rather messy method of doing things and the only reason it's done this way is because it's how the python script did it.

So, finally, my idea to squish two bugs with one shoe is to require the poster to write some metadata about their post. This would come in the form of a post.toml file inside the directory you want your post to be named. Next to this file would be... whatever you want, I guess. The post.toml will look like this:

# Both of these would be required
file = "path/to/file.md"
format = "markdown"

The process for post loading would now look like this:

  1. Take the web url
  2. Prepend /home/
  3. Insert /blog after blogger
  4. Check to see if it has an extension, and if so:
    • Try to serve the raw file directy
    • If it doesn't work, 404
  5. If not, append /post.toml and load the contents
  6. Load the file pointed to by the file key
  7. Process it according to format, and serve the result

It's a few extra steps, but the main concern is fixing a bug, not speed (yet). I think that this is a good idea, because not only does it require non-renderable files to be requested with the filename, but it also:

# This one would be required
date = "2019-04-09"

# Everything below here would be optional
edited = "2019-04-09"
title = "Stage 1 separation"
desc = "Part two of Blog Page: RIIR Edition"
topics = ["rust", "web programming", "software architecture"]

[series]
name = "blog_webserver"
# Zero-indexed :P
part = 1

... which would eventually lead to more frontend features, like letting readers sort, search, or filter posts by topic, series, and date. This metadata could also be used to build Open Graph Protocol meta tags, which are used for generating link previews.