1. Caddy version (caddy version
):
very latest 2.2.1
2. How I run Caddy:
from build via xcaddy then
/opt/caddy/bin/linux-amd64 run --config /opt/caddy/conf/example.conf --adapter caddyfile
a. System environment:
linux amd64
d. My complete Caddyfile or JSON config:
#!/bin/bash
(r53) {
tls {
dns route53 {
max_retries 10
}
}
}
(errors) {
handle_errors {
rewrite * /{http.error.status_code}.html
file_server
}
}
https://example.domain.net {
import r53
root * /opt/caddy/example-web
templates
file_server
redir / /index.md
redir /index.html /index.md
@mdcheck path *.md
rewrite @mdcheck /template.html
import errors
}
3. The problem I’m having:
I’ve been playing around with templates and markdown processing working from other posts here to have caddy serve .md files through a template. I seem to have got that working but then strangely if I add a fenced code block to the markdown it stops rendering the other markdown and the only renders a pre
tag block around the fenced content.
Here is the template file
{{$markdownFilePath := printf .OriginalReq.URL.Path}}
{{$markdownFile := (include $markdownFilePath | splitFrontMatter)}}
{{$meta := $markdownFile.Meta }}
<!DOCTYPE html>
<html>
<head>
<title>{{ $meta.title }}</title>
<link rel="stylesheet" href="/css/default.css">
</head>
<body>
<main>
{{markdown $markdownFile.Body }}
</main>
</body>
</html>
Here is some simple markdown being rendered
---
title: Example
---
# Example Rendered Markdown
This is an example markdown file rendered via a template by Caddy2
`some code`
here is what the browser inspector shows for html
<html><head>
<title>Example</title>
<link rel="stylesheet" href="/css/default.css">
</head>
<body>
<main>
<h1 id="example-rendered-markdown">Example Rendered Markdown</h1>
<p>This is an example markdown file rendered via a template by Caddy2</p>
<p><code>some code</code></p>
<!-- ```
Fenced Code Block
``` -->
</main>
</body></html>
Now I added a fenced code block
---
title: Example
---
# Example Rendered Markdown
This is an example markdown file rendered via a template by Caddy2
`some code`
```
Fenced Code Block
```
and the inspector html is
<html><head>
<title>Example</title>
<link rel="stylesheet" href="/css/default.css">
</head>
<body><pre id="_markdown">Fenced Code Block
</pre></body></html>
so you see the prior markdown render is gone. Before I get this on refresh I see the other rendered markdown and then it is replaced.
I suppose it must be with my template (i.e.)
{{markdown $markdownFile.Body }}
or maybe my caddyfile stanza isn’t quite right.
https://example.domain.net {
import r53
root * /opt/caddy/example-web
templates
file_server
redir / /index.md
redir /index.html /index.md
@mdcheck path *.md
rewrite @mdcheck /template.html
import errors
}
Anyway strange behavior and I am stuck.
FYI caddy itself is not showing any errors rendering this.
my directory structure is
my default.css is
body {
font-size: 10pt;
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
color: red;
background-color: blue;
line-height: 14pt;
/* display: block; */
display: flex;
}
main {
margin: 100px;
font-size: 2em;
flex-direction: column
}
h1 {
font: 30pt Verdana, Geneva, Arial, Helvetica, sans-serif;
font-weight: bold;
line-height: 20pt;
}
p {
color: white;
margin-bottom: 1em;
line-height: 1.2em;
}
code {
padding: .3em;
background-color: yellow;
color: blue;
}
pre#_markdown {
background-color: black;
color: white;
}
a {
text-decoration: none;
}
a:link, a:visited {
color: #8094d6;
}
a:hover, a:active {
color: #FF9933;
}