-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 My friend has an API that if called will return a picture of an anime girl, and will return a new one every 24 hours (I think that's how it works, truthfully I've never curl'd it). Thinking about that combined with a rant Luke Smith once made about fixing pull requests on his GitHub, I wish there was an API I could call to give me a random picture of a Pink Wojack every 24 hours. It would help me get across my current... mood? Is mood the right word? I've made progress - I am even at a point where I could have this finished tonight. Needless to say, the route we were taking has changed. ## Previous plan For more details on this, I would recommend reading the post before this *but* for a summary... The plan was to use Hugo OutputFormats to generate two outputs from the same markdown file, one regular and one plaintext. I would then use a Python script to strip the PGP artefacts from the content. This made a series of stupid *stupid* assumptions, all of which I have had to make some cringe/genius solutions for - - You can create separate `text/html` outputs, and apply a different theme to them - - That I can deploy a Python script to filter out the `. Content` data during the build process from within the `single.html` template. I will detail how I have-fixed/am-going-to-fix these in the sections below. I would like to mention, however, that as much as I want to lobotomise myself right now as a relaxation exercise, this experience has been fun and informative. ## Applying separate themes to `text/html` outputs Is this possible? No. I'm sure with enough fiddling it is possible, however, I ideally wanted to do this with minimal edits to the theme I am using. I have been avoiding learning HTML and CSS for 25 years, and I want to have a long happy life without ever breaking this streak. What I did instead of using separate themes is read the documentation (and reach out for help on one or two Discord servers). So as I mentioned before, Hugo can support separate OutputFormats. By default, it uses `text/html` for pages, but within the `text` category there is also `text/plain`. Now I made the mistake originally of assuming declaring `isPlainText = false` in my `hugo.toml` file would have the same effect - I was wrong (I don't know what that flag does). Given this, I edited my `hugo.toml` file so it now looks like this ```toml [outputFormats] [outputFormats.standardFormat] name = "standard-format" baseName = "index" isPlainText = false mediaType = "text/html" path = "" permalinkable = true weight = 1 [outputFormats.sigFormat] name = "sig-format" baseName = "index" isPlainText = true mediaType = "text/plain" path = "sigs" permalinkable = true weight = 2 ``` What also needs to be done is you need to make a template for this `.txt` file. So I made a file called `layouts/_default/single.sig-format.txt` which contained the following ```html {{ .Plain }} ``` With these changes theoretically, these two pages should be made - The top one being regular, and the second being a plaintext version with the signature. - - https://eddiequinn.xyz/test/ - - https://eddiequinn.xyz/sigs/test/index.txt Of course, it wasn't that simple. You see `.Plain` is meant to return the rendered content of the given page, removing all HTML tags... This is not what I wanted, and even if it was it still doesn't remove all the html *artefacts* i.e. `Microsoft’s` will appear rather than `Microsoft's`. Encountering this problem I did some googling and encountered [this post](https://discourse.gohugo.io/t/generating-custom-text-output-from-markdown-with-regular-expressions/27707) which detailed how she was having a similar issue, with [a link to GH](https://github.com/Princeton-CDH/startwords/blob/main/themes/startwords/layouts/article/single.txt) and how she solved it. So I used her code, and `single.sig-format-txt` became the following ```html {{- $rawContent := .RawContent -}} {{- range .Site.Data.article_txt_replace.args -}} {{- if not .skip -}} {{- $rawContent = $rawContent | replaceRE .pattern .replacement -}} {{- end -}} {{- end -}} {{ $rawContent }} ``` Following this I signed a post using `gpg --clearsign`, and used `hugo server` to generate it. I then `curl`'d down the content, and used `gpg --verify` to confirm it works - No errors, so looks like *for now* are good. I should probably initiate an automated test to confirm the sig checks out, but that will be a job for once this is done. ## `.Content` filter So this one is a tad annoying, but not as much as it could have been. The original plan was to use something like this to filter out the `Content` data during the build process, by editing the theme. See if you can spot the issue. ```html {{ $content := .Content }} {{ $filteredContent := printf "%s" $content | exec "python filter.py" }}