mirror of
https://github.com/almet/notmyidea.git
synced 2025-04-28 19:42:37 +02:00
- More categories are displayed - Change the URL Scheme for categories - Add a view for weeknotes, readings and code.
47 lines
1.5 KiB
Markdown
47 lines
1.5 KiB
Markdown
# Creating an online space to share markdown files
|
|
|
|
I wanted to create a space on my server where I can upload markdown files and have them rendered directly, for them to be shared with other people.
|
|
|
|
I stumbled on [the markdown module for nginx](https://github.com/ukarim/ngx_markdown_filter_module) which does exactly what I want, but seemed to ask for compilation of nginx, which wasn't exactly what I wanted in terms of maintainability (it would make it complicated to update it)
|
|
|
|
I then thought that the [Caddy](https://caddyserver.com/) server does that by default, and so I've tested it out. Turns out it's not, but it offers ways to do this thanks to its template mecanism.
|
|
|
|
It also, [setups automatically and transparently SSL certificates](https://caddyserver.com/docs/automatic-https) for you (using Let's Encrypt!), so I wanted to have a look.
|
|
|
|
Here is the Caddy configuration file I'm now using :
|
|
|
|
```Caddyfile
|
|
md.notmyidea.org {
|
|
root * /home/caddy/md.notmyidea.org
|
|
rewrite * /index.html
|
|
file_server
|
|
templates
|
|
encode zstd gzip
|
|
|
|
}
|
|
|
|
```
|
|
|
|
And the template:
|
|
|
|
```HTML
|
|
{{$pathParts := splitList "/" .OriginalReq.URL.Path}}
|
|
{{$markdownFilename := default "index" (slice $pathParts 1 | join "/")}}
|
|
|
|
{{if not (fileExists $markdownFilename)}}
|
|
{{httpError 404}}
|
|
{{end}}
|
|
|
|
{{$markdownFile := (include $markdownFilename | splitFrontMatter)}}
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>{{ $markdownFilename }}</title>
|
|
</head>
|
|
<body>
|
|
{{ markdown $markdownFile.Body }}
|
|
</body>
|
|
</html>
|
|
```
|
|
|
|
This is a minimalistic version, but it works :-)
|