1

I want to serve a single markdown file with Caddy v2, rendered as html. The old Caddy v1 had the markdown directive, which is gone. Instead I found the template directive, but it does not render the markdown files served.

Caddyfile

:80
templates
encode zstd gzip
root * /static  
file_server browse

Starting caddy with

docker run -it --rm --name caddy -p 8080:80 -v $PWD/Caddyfile:/etc/caddy/Caddyfile -v $PWD/static:/static -v caddy_data:/data caddy:2.1.1-alpine

I was only able to manage to serve a html file, that contained {{markdown "Some _markdown_ text"}} to be rendered, but not a whole index.md.

How to serve simple markdown files with Caddy v2, or is it not longer possible?

Dag
  • 10,079
  • 8
  • 51
  • 74

1 Answers1

1

According to https://caddy.community/t/markdown-support-in-v2/6984 this should do:


You can do it a few ways. The easiest way is your first example:

{{markdown "whole Markdown file here"}}

You can also bring in a file by name:

{{include "file.md" | markdown}}

Here’s another example, it’s how we serve the docs on the Caddy site: https://github.com/caddyserver/website/blob/master/src/docs/index.html

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77