diff options
author | davidovski <david@davidovski.xyz> | 2023-06-12 03:57:18 +0100 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2023-06-12 03:57:18 +0100 |
commit | 52e9c3aeea18d5750fea8704711a113adae93903 (patch) | |
tree | f8a9d31de26ed8d0b2ffe6515f2302c0d1374ea1 /example/entries/entries.sh | |
parent | af75a700c52aaca66ffe6db42c4448c2070be21a (diff) |
create example site where every page is executed to generate itself
Diffstat (limited to 'example/entries/entries.sh')
-rwxr-xr-x | example/entries/entries.sh | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/example/entries/entries.sh b/example/entries/entries.sh new file mode 100755 index 0000000..0479d96 --- /dev/null +++ b/example/entries/entries.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +# add a special header to all entries +cat << EOF +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <title>$1</title> +</head> +<body> +<h1>my blog</h1> +EOF + +# make this page be the index if it is called with no arguments +[ -z "$1" ] && { + cat << EOF + <h2>blog entries</h2> + <ul> +EOF + # list all the files in the directory + for file in *.md; do + printf "<li><a href=\"%s\">%s</a></li>" "${file%.*}.html" "$file" + done + + cat << EOF + </ul> +EOF + +} || { + # convert the markdown page to html text + md2html $1 + + # add a back button + cat << EOF +<span><a href="entries.html">go back to list</a></span> +EOF +} + +# and a footer +cat << EOF +</body> +</html> +EOF + |