From 4291fc5f1c992a499fbc82decc3fe8090d4dff68 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Thu, 4 Jul 2024 12:33:45 +0200 Subject: Improve and clean up the example config for templates --- example/Caddyfile | 36 +++++++++++++------- example/static/cheatsheet.gmi | 62 ----------------------------------- example/static/gemtext/cheatsheet.gmi | 62 +++++++++++++++++++++++++++++++++++ example/static/gemtext/index.gmi | 5 +++ example/static/index.html | 9 ++++- example/tpl/render_gemtext.html | 7 ++-- 6 files changed, 103 insertions(+), 78 deletions(-) delete mode 100644 example/static/cheatsheet.gmi create mode 100644 example/static/gemtext/cheatsheet.gmi create mode 100644 example/static/gemtext/index.gmi diff --git a/example/Caddyfile b/example/Caddyfile index aa12136..8d9dd50 100644 --- a/example/Caddyfile +++ b/example/Caddyfile @@ -8,22 +8,36 @@ http://template.localhost { root example/static - # If the path exists in the static directory then serve it directly - @static file {path} {path}/ - route @static { - file_server - } + # If a directory has an index.gmi file, then that file will be served when + # the directory is requested. + try_files {path} {path}/index.gmi + + @gmi path_regexp \.gmi$ + + # Handle all requests for .gmi files specially. + route @gmi { - # Otherwise send it through the template, which will look for a matching gmi - # file to render. - route { - rewrite * /tpl/render_gemtext.html - root example templates { + # The templates directive is given a different root, so that other + # template snippets within the tpl directory could theoretically be + # used within render_gemtext.html. + root example + + # Include the gemtext extention to make the gemtext function + # available within the template. extensions { gemtext } } - file_server + + # We "respond" with a template body here, which will be processed by the + # templates directive above. This body simply imports the template we + # actually want. Setting Content-Type is required because there's no + # actual file for Caddy to determine the value from. + header Content-Type text/html + respond `{{ include "tpl/render_gemtext.html" }}` } + + # All other files are handled directly by the file_server. + file_server } diff --git a/example/static/cheatsheet.gmi b/example/static/cheatsheet.gmi deleted file mode 100644 index e7c9286..0000000 --- a/example/static/cheatsheet.gmi +++ /dev/null @@ -1,62 +0,0 @@ -# Gemtext cheatsheet - -This is a quick "cheatsheet" intended for people who haven't been writing Gemtext for long or who need their memory refreshed after a break. If you're completely new to Gemtext and you need things explained in a more detail, you should check out the full length introduction: - -=> gemini://geminiprotocol.net/docs/gemtext.gmi A quick introduction to "gemtext" markup - -## Text - -Here's the basics of how text works in Gemtext: - -* Long lines get wrapped by the client to fit the screen -* Short lines *don't* get joined together -* Write paragraphs as single long lines -* Blank lines are rendered verbatim - -## Links - -At the bare minimum, a link line consists of just the characters `=>` and a URL. Here's a link to this page: - -``` -=> gemini://geminiprotocol.net/docs/cheatsheet.gmi -``` - -But you can include labels with links, and probably should most of the time. Labels are separated from the URL by one or more spaces or tabs: - -``` -=> gemini://geminiprotocol.net/docs/cheatsheet.gmi Gemtext cheatsheet -``` - -## Headings - -You get three levels of heading: - -``` -# Heading - -## Sub-heading - -### Sub-subheading -``` - -## Lists - -You get one kind of list and you can't nest them: - -``` -* Mercury -* Gemini -* Apollo -``` - -## Quotes - -Here's a quote from Maciej Cegłowski: - -``` -> I contend that text-based websites should not exceed in size the major works of Russian literature. -``` - -## Pre-fromatted text - -Lines which start with ``` will cause clients to toggle in and out of ordinary rendering mode and preformatted mode. In preformatted mode, Gemtext syntax is ignored so links etc. will not be rendered, and text will appear in a monospace font. diff --git a/example/static/gemtext/cheatsheet.gmi b/example/static/gemtext/cheatsheet.gmi new file mode 100644 index 0000000..e7c9286 --- /dev/null +++ b/example/static/gemtext/cheatsheet.gmi @@ -0,0 +1,62 @@ +# Gemtext cheatsheet + +This is a quick "cheatsheet" intended for people who haven't been writing Gemtext for long or who need their memory refreshed after a break. If you're completely new to Gemtext and you need things explained in a more detail, you should check out the full length introduction: + +=> gemini://geminiprotocol.net/docs/gemtext.gmi A quick introduction to "gemtext" markup + +## Text + +Here's the basics of how text works in Gemtext: + +* Long lines get wrapped by the client to fit the screen +* Short lines *don't* get joined together +* Write paragraphs as single long lines +* Blank lines are rendered verbatim + +## Links + +At the bare minimum, a link line consists of just the characters `=>` and a URL. Here's a link to this page: + +``` +=> gemini://geminiprotocol.net/docs/cheatsheet.gmi +``` + +But you can include labels with links, and probably should most of the time. Labels are separated from the URL by one or more spaces or tabs: + +``` +=> gemini://geminiprotocol.net/docs/cheatsheet.gmi Gemtext cheatsheet +``` + +## Headings + +You get three levels of heading: + +``` +# Heading + +## Sub-heading + +### Sub-subheading +``` + +## Lists + +You get one kind of list and you can't nest them: + +``` +* Mercury +* Gemini +* Apollo +``` + +## Quotes + +Here's a quote from Maciej Cegłowski: + +``` +> I contend that text-based websites should not exceed in size the major works of Russian literature. +``` + +## Pre-fromatted text + +Lines which start with ``` will cause clients to toggle in and out of ordinary rendering mode and preformatted mode. In preformatted mode, Gemtext syntax is ignored so links etc. will not be rendered, and text will appear in a monospace font. diff --git a/example/static/gemtext/index.gmi b/example/static/gemtext/index.gmi new file mode 100644 index 0000000..9ff3d82 --- /dev/null +++ b/example/static/gemtext/index.gmi @@ -0,0 +1,5 @@ +# Gemtext Directory Index + +This is the index of the gemtext directory. In here are various gemtext files useful for testing. + +=> cheatsheet.gmi Gemtext cheatsheet diff --git a/example/static/index.html b/example/static/index.html index db924d5..7badec1 100644 --- a/example/static/index.html +++ b/example/static/index.html @@ -1,11 +1,18 @@ Root Index +

Root Index

- This is the root page of the example site. + This is the root page of the example site. From here you can explore the + various files useful for testing and exploring the functionality of the + plugins in this project.

+ diff --git a/example/tpl/render_gemtext.html b/example/tpl/render_gemtext.html index 0cfdec6..34a8c7c 100644 --- a/example/tpl/render_gemtext.html +++ b/example/tpl/render_gemtext.html @@ -1,7 +1,6 @@ -{{ $pathSplit := splitList "/" .OriginalReq.URL.Path }} -{{ $base := last $pathSplit | default "index.html" }} -{{ $newBase := trimSuffix (ext $base) $base | printf "%s.gmi" }} -{{ $filePath := append (initial $pathSplit) $newBase | join "/" | printf "static%s" }} +{{ $pathSplit := splitList "/" .Req.URL.Path }} +{{ $base := last $pathSplit | default "index.gmi" }} +{{ $filePath := append (initial $pathSplit) $base | join "/" | printf "static%s" }} {{ if not (fileExists $filePath) }}{{ httpError 404 }}{{ end }} -- cgit v1.2.3