Make sure the content-type header is set right, the easiest way to do that is to use a proper file extension. Unfortunately there’s not enough information here to deduce if that’s actually the problem, I can only speculate.
mime are the MIME types the templates middleware will act on; any responses that do not have a qualifying Content-Type will not be evaluated as templates. Default: text/html text/plain .
The syntax for mime subdirective is: mime <types...>, and .md is not a MIME type, so I would remove that.
Since your responses are coming back without a Content-Type header, you either need to use a supported file extension (see mime package - mime - Go Packages) or set the header yourself: header (Caddyfile directive) — Caddy Documentation - I don’t know why changing headers via a Chrome extension would work; the Chrome extension does not run inside Caddy…
Additionally, this:
{{ .Markdown "# hey"}}
Should result in an error once the templates handler starts kicking in. The correct function as documented here is markdown not .Markdown. (Remember, this is v2, not v1.)
Usually, plain Markdown files are not meant to be served directly, even when rendered. In other words, you wouldn’t usually render file.md and serve its resulting HTML, because there would be no proper <!DOCTYPE>...<head>...<body> structure, and there would also be no styling or behavior!
So, I think serving Markdown directly like what you’re trying to do is not very common, because it is not very useful.
Most sites (including the Caddy site!) will serve a regular .html file as a template file, which has this action somewhere in its body:
{{markdown "..."}}
to embed the Markdown file within a proper HTML document with styling and behavior. HTML files get a proper Content-Type without needing to modify the system MIME store, so it just works, and is a lot easier and more useful than rendering Markdown directly.
If you still want to render and serve Markdown files with .md extensions directly, either:
rename them to use .txt (a recognized plaintext extension),
or add a MIME association for .md to your system,
or using something like header index.md Content-Type text/markdown in your Caddyfile.
Because of simplicity: I want my whole site (home page, talks, blog posts, pictures) to be served by Caddy. No more services, dependencies, deploy strategies, compile passes, etc.
So for my (next) blog, if I can find some way to write some markdown files in a directory and have them displayed by Caddy that would be awesome.
That’s basically what we do with the Caddy docs, although we have to maintain the nav links ourselves (for now). This feature can continue to be developed over time!
Hugo is developed in the same Go language as Caddy and consists of common templates. Adding pages is just adding .md files. These two go together well.
I can see his point, though; the goal of Caddy is to have fewer moving parts. Even though I agree hugo is a fine way to do it right now, it’d be better if there was a simpler, more direct way to get a simple static site up and running directly with your web server.
We are used to writing Markdown in .md files. (Eg GitHub, README.md describes really well)
There are many services corresponding to it. That may need to be considered at the Caddy level.
I’m publishing some web and blogs on Hugo, so I’m glad that Caddy recognizes the Hugo directory.
But it might be ideal for a plugin implementation.
For the record, I think hugo is great, and not complex. But it’s quick start has 7 steps with lots of customization, themes etc. Ideally I would like to do the CSS myself without any abstractions. Just render some markdown, add some CSS, profit. No compile step, no theme choosing and customization, no brew install, nothing. Yes I’m very lazy
That sounds great. Not sure how you do that exactly… it’s your html file something like:
<!-- here html, head, body tags -->
{{markdown "here all the page markdown content"}}
<!-- here tags are closed -->
or
<!-- here html, head, body tags -->
{{markdown "here first markdown line"}}
{{markdown "here 2nd markdown line"}}
an so on
<!-- here tags are closed -->
Or is there a way to embed the .md file with the include func? Would be awesome to combine 2 funcs like: {{markdown include "path/to/file.md"}}
(.OriginalReq is the request before rewriting, because all docs pages actually go to this index file with a directive in our Caddyfile: rewrite /docs/* /docs/index.html)
The next line splits the markdown content from its front matter (totally optional, but we wanted some data structure associated with each file for metadata purposes):