mirror of
https://github.com/almet/notmyidea.git
synced 2025-04-28 19:42:37 +02:00
98 lines
No EOL
4.7 KiB
HTML
98 lines
No EOL
4.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<title>
|
|
Creating an online space to share markdown files - Alexis Métaireau </title>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link rel="stylesheet"
|
|
href="https://blog.notmyidea.org/theme/css/main.css?v2"
|
|
type="text/css" />
|
|
<link href="https://blog.notmyidea.org/feeds/all.atom.xml"
|
|
type="application/atom+xml"
|
|
rel="alternate"
|
|
title="Alexis Métaireau ATOM Feed" />
|
|
</head>
|
|
<body>
|
|
<div id="content">
|
|
<section id="links">
|
|
<ul>
|
|
<li>
|
|
<a class="main" href="/">Alexis Métaireau</a>
|
|
</li>
|
|
<li>
|
|
<a class=""
|
|
href="https://blog.notmyidea.org/journal/index.html">Journal</a>
|
|
</li>
|
|
<li>
|
|
<a class="selected"
|
|
href="https://blog.notmyidea.org/code/">Code, etc.</a>
|
|
</li>
|
|
<li>
|
|
<a class=""
|
|
href="https://blog.notmyidea.org/weeknotes/">Notes hebdo</a>
|
|
</li>
|
|
<li>
|
|
<a class=""
|
|
href="https://blog.notmyidea.org/lectures/">Lectures</a>
|
|
</li>
|
|
<li>
|
|
<a class=""
|
|
href="https://blog.notmyidea.org/projets.html">Projets</a>
|
|
</li>
|
|
</ul>
|
|
</section>
|
|
|
|
<header>
|
|
<h1 class="post-title">Creating an online space to share markdown files</h1>
|
|
<time datetime="2023-09-17T00:00:00+02:00">17 septembre 2023</time>
|
|
|
|
|
|
</header>
|
|
<article>
|
|
|
|
<p>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.</p>
|
|
<p>I stumbled on <a href="https://github.com/ukarim/ngx_markdown_filter_module">the markdown module for nginx</a> 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)</p>
|
|
<p>I then thought that the <a href="https://caddyserver.com/">Caddy</a> 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.</p>
|
|
<p>It also, <a href="https://caddyserver.com/docs/automatic-https">setups automatically and transparently <span class="caps">SSL</span> certificates</a> for you (using Let’s Encrypt!), so I wanted to have a look.</p>
|
|
<p>Here is the Caddy configuration file I’m now using :</p>
|
|
<div class="highlight"><pre><span></span><code>md.notmyidea.org {
|
|
root <span class="gs">* /home/caddy/md.notmyidea.org</span>
|
|
<span class="gs"> rewrite *</span> /index.html
|
|
file_server
|
|
templates
|
|
encode zstd gzip
|
|
|
|
}
|
|
</code></pre></div>
|
|
|
|
<p>And the template:</p>
|
|
<div class="highlight"><pre><span></span><code>{{$pathParts := splitList "/" .OriginalReq.URL.Path}}
|
|
{{$markdownFilename := default "index" (slice $pathParts 1 | join "/")}}
|
|
|
|
{{if not (fileExists $markdownFilename)}}
|
|
{{httpError 404}}
|
|
{{end}}
|
|
|
|
{{$markdownFile := (include $markdownFilename | splitFrontMatter)}}
|
|
<span class="cp"><!DOCTYPE html></span>
|
|
<span class="p"><</span><span class="nt">html</span><span class="p">></span>
|
|
<span class="p"><</span><span class="nt">head</span><span class="p">></span>
|
|
<span class="p"><</span><span class="nt">title</span><span class="p">></span>{{ $markdownFilename }}<span class="p"></</span><span class="nt">title</span><span class="p">></span>
|
|
<span class="p"></</span><span class="nt">head</span><span class="p">></span>
|
|
<span class="p"><</span><span class="nt">body</span><span class="p">></span>
|
|
{{ markdown $markdownFile.Body }}
|
|
<span class="p"></</span><span class="nt">body</span><span class="p">></span>
|
|
<span class="p"></</span><span class="nt">html</span><span class="p">></span>
|
|
</code></pre></div>
|
|
|
|
<p>This is a minimalistic version, but it works :-)</p>
|
|
</article>
|
|
<footer>
|
|
<a id="feed" href="/feeds/all.atom.xml">
|
|
<img alt="RSS Logo" src="/theme/rss.svg" />
|
|
</a>
|
|
</footer>
|
|
</div>
|
|
</body>
|
|
</html> |