Creating an online space to share markdown files

I wanted to create a space on my server where I can upload markdown files and have them rendered directly, for them to be shared with other people.

I stumbled on the markdown module for nginx which does exactly what I want, but seemed to ask for compilation of nginx, which wasn’t exactly what I wanted in terms of maintainability (it would make it complicated to update it)

I then thought that the Caddy server does that by default, and so I’ve tested it out. Turns out it’s not, but it offers ways to do this thanks to its template mecanism.

It also, setups automatically and transparently SSL certificates for you (using Let’s Encrypt!), so I wanted to have a look.

Here is the Caddy configuration file I’m now using : {
        root * /home/caddy/
        rewrite * /index.html
        encode zstd gzip


And the template:

{{$pathParts := splitList "/" .OriginalReq.URL.Path}}
{{$markdownFilename := default "index" (slice $pathParts 1 | join "/")}}

{{if not (fileExists $markdownFilename)}}
    {{httpError 404}}

{{$markdownFile := (include $markdownFilename | splitFrontMatter)}}
<!DOCTYPE html>
        <title>{{ $markdownFilename }}</title>
        {{ markdown $markdownFile.Body }}

This is a minimalistic version, but it works :-)