~zenomat/tinywiki

cfd3bfdb99a27028d77ab474be9761e814015e13 — zeno 3 months ago f0b948f
Parse yaml frontmatter
2 files changed, 11 insertions(+), 3 deletions(-)

M README.md
M build.sh
M README.md => README.md +1 -0
@@ 22,6 22,7 @@ Tinywiki is a simple bash script, which converts a folder into a static html wik
- bash (not posix yet)
- pandoc
- coreutils
- shyaml (`pip install shyaml`)

# Installation
``` bash

M build.sh => build.sh +10 -3
@@ 1,5 1,12 @@
#!/bin/sh -e

function parse_yml()
{
	yml="$(awk 'f{ if (/---/){printf "%s", buf; f=0; buf=""} else buf = buf $0 ORS}; /---/{f=1}' "$1")"
	yml_data[0]="$(echo "$yml" | shyaml get-value title 2>/dev/null || echo "No title provided")"
	yml_data[1]="$(echo "$yml" | shyaml get-value desc 2>/dev/null || echo "No description provided")"
}

workdir="$(readlink -f "$1")"
if ! [ -z "$2" ]; then
	basepath="$2"


@@ 29,9 36,6 @@ find . -name "*.md" | while read -r file; do
		title="$name"
	fi

	# TODO(zeno): Make this webserver ready
	# only works on local machine, because absolute path,
	# on webserver with domain, we shoudl support basepath
	if ! [ "$basepath" = "" ]; then
		echo "["$title"]("$basepath/$path/$name".html)" >> "$outdir/tmp/index-ins.md"
	else 


@@ 51,6 55,9 @@ find . -name "*.md" ! -name "index-ins.md" | while read -r file; do
	fi
	escaped_path_to_root=$(printf '%s\n' "$path_to_root" | sed -e 's/[\/&]/\\&/g')

	declare -a yml_data
	parse_yml "$file"

	cp $workdir/$file $outdir/tmp
	awk -v S="$(cat $outdir/tmp/index-ins.md)" '/\[\[index\]\]/{$0=S}1' "$file" > "$outdir/tmp/$name.md"