From f22af1bf6ec7d1a7cafbbc6f37b7791b4a56fef5 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Fri, 1 Jan 2021 08:39:09 +0100 Subject: Support drafts via _ prefix in filename --- scripts/build_content.sh | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'scripts') diff --git a/scripts/build_content.sh b/scripts/build_content.sh index 4e1b396..fcabf9f 100755 --- a/scripts/build_content.sh +++ b/scripts/build_content.sh @@ -85,20 +85,14 @@ get_subpages_meta() { child_pages=() if [ -d "$basedir" ]; then - mapfile -d $'\0' child_pages_1 < <(find $basedir/ \ - -type f \ - -name "*.md" ! -name "index.md" \ - -maxdepth 1 \ - -print0) - - mapfile -d $'\0' child_pages_2 < <(find $basedir/ \ - -type f \ - -name "index.md" \ - -mindepth 2 \ + mapfile -d $'\0' child_pages < <(find "$basedir" \ -maxdepth 2 \ + -type f \ + -name "*.md" \ + ! -name "_*.md" \ + ! -wholename "${basedir}index.md" \ + \( -wholename "$basedir*/index.md" -o ! -wholename "$basedir*/*.md" \) \ -print0) - - child_pages=("${child_pages_1[@]}" "${child_pages_2[@]}") fi pages=$(echo "{}" | jq ". + { \ @@ -115,7 +109,6 @@ get_subpages_meta() { #echo -e "\033[0;90m[////////]\033[0m - $file" metadata=$(get_metadata "$file") - content=$(get_content "$file") section=$(get_section "$file") @@ -145,9 +138,11 @@ get_subpages_meta() { category_name="" if [ "$section" != "" ] && [ "$category" != "" ]; then - category_name=$(echo "$CATEGORIES" | jq -r .$section.$category) + category_name=$(echo "$CATEGORIES" | jq -r ".$section.$category") fi + content=$(get_content "$file") + metadata=$(echo "$metadata" | jq ". + { \ content: \"$(echo "$content" | sed -z 's/\\/\\\\/g;s/\n/\\n/g;s/"/\"/g')\", \ date: { \ @@ -202,13 +197,11 @@ handle () { if [ "${1#*.}" = "md" ]; then echo -e "\033[0;32m[COMPILE ]\033[0m $1 -> $target_file" - meta_file=$(mktemp) - echo -e "\033[0;90m[COMPILE ]\033[0m Getting metadata" included_metadata=$(get_metadata "$1") - create_feed=$(echo "$included_metadata" | jq -r ".create_feed") + create_feed=$(echo "$included_metadata" | jq -r .create_feed) url_abs=$(get_url_abs "$1" "html") url_full="${SITE%/}$url_abs" @@ -248,6 +241,8 @@ handle () { }") fi + meta_file=$(mktemp) + echo "$added_metadata" > "$meta_file" if [ "$create_feed" = "true" ]; then @@ -291,6 +286,7 @@ handle () { if [ -z "$1" ]; then find "$CONTENT_DIR" \ -type f \ + ! -name "_*.md" \ | while read file do handle "$file" @@ -299,6 +295,7 @@ elif [ "$1" = "all_md" ]; then find "$CONTENT_DIR" \ -type f \ -name "*.md" \ + ! -name "_*.md" \ | while read file do handle "$file" @@ -307,15 +304,20 @@ elif [ "$1" = "single" ]; then if [ -z "$2" ]; then echo -e "\033[0;31m[ERROR ]\033[0m \"single\" operation requires file argument" else - handle "$2" + filename=$(basename "$2") + if [ "${filename:0:1}" != "_" ]; then + handle "$2" + fi fi elif [ "$1" = "delete" ]; then if [ -z "$2" ]; then echo -e "\033[0;31m[ERROR ]\033[0m \"delete\" operation requires file argument" else target_file=$(get_target_filename "$2") - echo -e "\033[0;32m[DELETE ]\033[0m $2 -> $target_file" - rm -rf $target_file + if [ -f "$target_file" ] || [ -d "$target_file" ]; then + echo -e "\033[0;32m[DELETE ]\033[0m $2 -> $target_file" + rm -rf $target_file + fi fi else echo -e "\033[0;31m[ERROR ]\033[0m Unknown operation: \"$1\"" -- cgit v1.2.3-70-g09d2