From 517fc58cf46595990fd5af64a1bd647ee5ac3c08 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sun, 27 Dec 2020 22:03:42 +0100 Subject: Added stylelint, generate some metadata automatically --- scripts/build_content.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++--- scripts/metadata_tpl.json | 4 ++++ 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 scripts/metadata_tpl.json (limited to 'scripts') diff --git a/scripts/build_content.sh b/scripts/build_content.sh index b7d0c24..5b4bb85 100755 --- a/scripts/build_content.sh +++ b/scripts/build_content.sh @@ -1,6 +1,7 @@ #!/bin/bash CONTENT_DIR="content/" +TEMPLATES_DIR="templates/" OUTPUT_DIR="output/" target_filename () { @@ -23,6 +24,22 @@ target_url_rel () { echo "$filename" } +target_url_abs () { + url=$(target_url_rel "$CONTENT_DIR" "$1") + echo "/$url" +} + +get_section() { + filename=$1 + filename=${filename#"$CONTENT_DIR"} + filename=${filename%.md} + filename=$(echo "$filename" | cut -f1 -d /) + if [ "$filename" = "index.md" ]; then + filename="home" + fi + echo "$filename" +} + get_subpages_basedir() { filename=$1 if [ "${filename##*/}" = "index.md" ]; then @@ -55,20 +72,45 @@ get_subpages() { if [ ${#child_pages[@]} -ne 0 ]; then echo -e "\033[0;90m[////////]\033[0m Child pages:" + collected_metadata="[]" + for file in "${child_pages[@]}"; do - link=$(target_url_rel "$basedir" "$file") - echo -e "\033[0;90m[////////]\033[0m - $file -> rel. URL: $link" + echo -e "\033[0;90m[////////]\033[0m - $file" + + url_rel=$(target_url_rel "$basedir" "$file") + url_abs=$(target_url_abs "$file") + + metadata=$(pandoc "$file" \ + -f markdown \ + -t plain \ + --template scripts/metadata_tpl.json) + + metadata=$(echo "$metadata" | jq ". + { url_rel: \"$url_rel\", url_abs: \"$url_abs\" }") + + collected_metadata=$(echo "$collected_metadata" | jq ". + [ $metadata ]") done + + collected_metadata=$(echo "$collected_metadata" | jq "sort_by(.date)") + + echo "$collected_metadata" fi } handle () { target=$(target_filename "$1") + mkdir -p $(dirname "$target") if [ "${1#*.}" = "md" ]; then echo -e "\033[0;32m[COMPILE ]\033[0m $1 -> $target" + is_home=false + section=$(get_section "$1") + + if [ "$target" = "${OUTPUT_DIR}index.html" ]; then + is_home=true + fi + subpages_meta=$(mktemp) # $(get_subpages "$1") > "$subpages_meta" @@ -78,8 +120,10 @@ handle () { pandoc "$1" \ -f markdown \ -t html5 \ - --template templates/base.html \ + --template "${TEMPLATES_DIR}base.html" \ -o "$target" \ + --metadata isHome=$is_home \ + --metadata section=$section \ --metadata-file metadata/metadata.yaml \ --metadata-file "$subpages_meta" diff --git a/scripts/metadata_tpl.json b/scripts/metadata_tpl.json new file mode 100644 index 0000000..eeda341 --- /dev/null +++ b/scripts/metadata_tpl.json @@ -0,0 +1,4 @@ +{ + "title": "$title$", + "date": "$date$" +} -- cgit v1.2.3-70-g09d2