§2023-06-30
- [caddy-markdown-site[(https://github.com/dbohdan/caddy-markdown-site/tree/main)
- Serve Markdown files as HTML pages with CSS using just Caddy
¶Requirements
- Caddy 2.4 or later.
- Optional:
- Deno 1.11 or later to run the tests (make test).
- deno x86_64 depositry
- entr for development (make dev).
- sudo pacman -S entr
- Clone
$ git clone https://github.com/dbohdan/caddy-markdown-site.git
$ cd caddy-markdown-site
[alexlai@orangepi5 caddy-markdown-site]$ tree
.
├── Caddyfile
├── demo
│ ├── another.md
│ ├── index-html
│ │ └── index.html
│ ├── index-md
│ │ ├── 30日-アクティビストの戦術.md
│ │ ├── BeginnerGuide.md
│ │ ├── index.md
│ │ └── munetakaJupyt3erHub -> /opt/munetakaJupyterHub/
│ ├── index.md
│ ├── index-txt
│ │ └── index.txt
│ ├── media
│ │ └── photo.jpg
│ ├── munetakaJupyterHu -> /opt/munetakaJupyterHub/
│ └── templates -> ../templates
├── index.md
├── LICENSE
├── Makefile
├── README.md
├── screenshot.png
├── templates
│ ├── axist.min.css
│ ├── error.html
│ ├── footer.html
│ ├── header.html
│ ├── head.html
│ └── index.html
└── test.ts
10 directories, 21 files
[alexlai@orangepi5 caddy-markdown-site]$ B
- Caddyfile changed as
# https://github.com/dbohdan/caddy-markdown-site
# Copyright (c) 2021 D. Bohdan. License: MIT.
http://orangepi5.yushei.net:43888 {
root * demo
# root * /opt/munetakaJupyterHub
encode gzip
file_server browse
# browse
templates
@media {
path /favicon.ico
path /media/*
}
@templates {
path /templates/*
not path /templates/*.css /templates/*.js
}
@markdown {
path_regexp \.md$
}
@markdown_exists {
file {path}.md
}
handle @media {
file_server
}
handle @templates {
error 403
}
handle @markdown {
rewrite * /templates/index.html
}
handle @markdown_exists {
map {path} {caddy_markdown_site.append_to_path} {
default extension
}
rewrite * /templates/index.html
}
handle_errors {
file_server
templates
@markdown_index_exists_404 {
file {path}/index.md
expression `{http.error.status_code} == 404`
}
handle @markdown_index_exists_404 {
map {path} {caddy_markdown_site.append_to_path} {
default index
}
file_server {
status 200
}
rewrite * /templates/index.html
}
handle {
rewrite * /templates/error.html
}
}
}
- Makefile
CADDY ?= caddy
dev:
find . -type f | entr -r $(CADDY) run
test:
deno test \
--allow-env \
--allow-net \
--allow-read=Caddyfile \
--allow-run \
--allow-write=Caddyfile.test \
test.ts \
.PHONY: dev test
The default behavior of the make command, in the absence of a target name, will execute the first target defined in the Makefile. In this case, the first target is dev.
$ make
find . -type f | entr -r caddy run
2023/06/30 12:00:56.731 INFO using adjacent Caddyfile
2023/06/30 12:00:56.739 INFO admin admin endpoint started {"address": "localhost:2019", "enforce_origin": false, "origins": ["//localhost:2019", "//[::1]:2019", "//127.0.0.1:2019"]}
2023/06/30 12:00:56.740 INFO tls.cache.maintenance started background certificate maintenance {"cache": "0x40004822a0"}
2023/06/30 12:00:56.748 INFO http.log server running {"name": "srv0", "protocols": ["h1", "h2", "h3"]}
2023/06/30 12:00:56.748 INFO autosaved config (load with --resume flag) {"file": "/opt/xfs/home/alexlai/.local/share/caddy/autosave.json"}
2023/06/30 12:00:56.748 INFO serving initial configuration
2023/06/30 12:00:56.748 INFO tls cleaning storage unit {"description": "FileStorage:/opt/xfs/home/alexlai/.local/share/caddy"}
2023/06/30 12:00:56.753 INFO tls finished cleaning storage units
$ caddy run
2023/06/30 11:52:17.252 INFO using adjacent Caddyfile
2023/06/30 11:52:17.262 INFO admin admin endpoint started {"address": "localhost:2019", "enforce_origin": false, "origins": ["//localhost:2019", "//[::1]:2019", "//127.0.0.1:2019"]}
2023/06/30 11:52:17.263 INFO tls.cache.maintenance started background certificate maintenance {"cache": "0x40004cecb0"}
2023/06/30 11:52:17.273 INFO tls cleaning storage unit {"description": "FileStorage:/opt/xfs/home/alexlai/.local/share/caddy"}
2023/06/30 11:52:17.273 INFO tls finished cleaning storage units
2023/06/30 11:52:17.273 INFO http.log server running {"name": "srv0", "protocols": ["h1", "h2", "h3"]}
2023/06/30 11:52:17.274 INFO autosaved config (load with --resume flag) {"file": "/opt/xfs/home/alexlai/.local/share/caddy/autosave.json"}
2023/06/30 11:52:17.274 INFO serving initial configuration
^C2023/06/30 11:59:37.507 INFO shutting down {"signal": "SIGINT"}
2023/06/30 11:59:37.512 WARN exiting; byeee!! 👋 {"signal": "SIGINT"}
2023/06/30 11:59:37.518 INFO tls.cache.maintenance stopped background certificate maintenance {"cache": "0x40004cecb0"}
2023/06/30 11:59:37.523 INFO admin stopped previous server {"address": "localhost:2019"}
2023/06/30 11:59:37.525 INFO shutdown complete {"signal": "SIGINT", "exit_code": 0}
[alexlai@orangepi5 caddy-markdown-site]$ make
find . -type f | entr -r caddy run
2023/06/30 11:59:40.497 INFO using adjacent Caddyfile
2023/06/30 11:59:40.507 INFO admin admin endpoint started {"address": "localhost:2019", "enforce_origin": false, "origins": ["//localhost:2019", "//[::1]:2019", "//127.0.0.1:2019"]}
2023/06/30 11:59:40.507 INFO tls.cache.maintenance started background certificate maintenance {"cache": "0x40004e02a0"}
2023/06/30 11:59:40.517 INFO http.log server running {"name": "srv0", "protocols": ["h1", "h2", "h3"]}
2023/06/30 11:59:40.517 INFO tls cleaning storage unit {"description": "FileStorage:/opt/xfs/home/alexlai/.local/share/caddy"}
2023/06/30 11:59:40.517 INFO tls finished cleaning storage units
2023/06/30 11:59:40.517 INFO autosaved config (load with --resume flag) {"file": "/opt/xfs/home/alexlai/.local/share/caddy/autosave.json"}
2023/06/30 11:59:40.517 INFO serving initial configuration
- entr example
$ ls temp | enter echo "temp file changed"
Then edit the temp and save it will print "temp file changed"