Transparent rendering of markdown files

I have a use case where a bunch of data is curated by a process which uses a markdown file to describe the data, collect notes, etc. We didn’t want to compilcate that process by requiring these to be part of a complex site or use templates, CSS or any other normal things a site might do, but did like the way Apache has been silently rendering the markdown files, which I think was like the v1 markdown functionality. I found this post: Markdown support in v2 which shows a solution that looks great for a formal website, but wasn’t a good fit for our use. So starting from the examples in that post and after a dive into the docs, or given my newbie caddy status, more like a drowning person splashing around, I came up with this config:

http://:8080 {
	log {
		output stderr
		level DEBUG
		format console
	}

	encode zstd gzip
	file_server browse
	root * /home/griznog/webserver

	templates
	@markdown path *.md
	header @markdown Content-Type text/html
	respond @markdown "{{ include .OriginalReq.URL.Path | markdown }}"
}

Two goals from posting this: first while this is working great as far as I can tell, I’d appreciate feedback if I’m doing something wrong or inefficient here. Second, I wanted to share it in case someone else is looking to restore/recreate the previous v1 markdown functionality as this might be a worthwhile starting point.

caddy is pretty awesome, a big thanks to everyone working on it!

griznog

3 Likes

Awesome, thanks for sharing this!

1 Like