Initial commit

This commit is contained in:
Gender Demon 2020-12-29 20:56:20 +00:00
commit 09209d2637
2 changed files with 40 additions and 0 deletions

37
render_file Executable file
View File

@ -0,0 +1,37 @@
#!/bin/sh
# render_file.sh: render a markdown file as HTML
# arguments:
# $1: markdown file to render
# Separate metadata and actual markdown in the .md file
frontmatter=$(awk '/!startmeta/,/!endmeta/ {if ($0 != "!startmeta" && $0 != "!endmeta") print;}' "$1")
docbody=$(awk '/!endmeta/ {p=1; next} p' "$1")
title=$(echo "$frontmatter" | awk -F'=' '/title=/ {print $2}')
date=$(echo "$frontmatter" | awk -F'=' '/date=/ {print $2}')
# cmark doesn't create the <head>, doctype declaration or indeed most of the document
# structure for us, so we'll do it ourselves.
# We're going to use single quotes for the strings here too because otherwise we'll have
# to escape all the double quotes in the HTML
printf '<!doctype html>\n'
printf '<html>\n'
printf '<head>\n'
printf '<title>%s</title>\n' "$title"
printf '<link rel="icon" href="favicon.ico" type="image/x-icon">\n'
printf '<link rel="stylesheet" href="cren.css">\n'
printf '<meta charset="utf8">\n'
printf '<meta name="viewport" content="width=device-wdith, initial-scale=1">\n'
printf '</head>\n'
printf '<body>\n'
printf '<header>\n'
printf "<h1>cren's webspace</h1>\n"
printf '</header>\n'
printf '<main>\n'
# Now we insert the main content of the page
printf '%s' "$(echo "$docbody" | cmark)"
printf '</main>\n'
# Finally, the footer
printf '<footer>\n'
printf '<p>Content on this webspace is made available under the <a href="https://creativecommons.org/publicdomain/zero/1.0/legalcode">CC0 licence</a>. You have the right to copy.</p>\n'
printf '</footer>\n'
printf '</body>\n'
printf '</html>\n'

3
render_tree Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
# render_tree: render all the files in a directory tree to html or just copy them
# if they are not markdown