- More categories are displayed - Change the URL Scheme for categories - Add a view for weeknotes, readings and code.
1.5 KiB
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 :
md.notmyidea.org {
root * /home/caddy/md.notmyidea.org
rewrite * /index.html
file_server
templates
encode zstd gzip
}
And the template:
{{$pathParts := splitList "/" .OriginalReq.URL.Path}}
{{$markdownFilename := default "index" (slice $pathParts 1 | join "/")}}
{{if not (fileExists $markdownFilename)}}
{{httpError 404}}
{{end}}
{{$markdownFile := (include $markdownFilename | splitFrontMatter)}}
<!DOCTYPE html>
<html>
<head>
<title>{{ $markdownFilename }}</title>
</head>
<body>
{{ markdown $markdownFile.Body }}
</body>
</html>
This is a minimalistic version, but it works :-)