From 1a533812e1a32af573e803032788a27fa593a020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Gon=C3=A7alves?= Date: Thu, 12 Aug 2021 16:43:58 +0200 Subject: ssg: Force local variable --- bin/ssg-template | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/bin/ssg-template b/bin/ssg-template index 4da4364..eacf2ae 100644 --- a/bin/ssg-template +++ b/bin/ssg-template @@ -28,7 +28,15 @@ _get_value_date() { _get_out_path() { # 1: filename # stdout: filename - echo "${1}" | sed -e 's/^src/out/g' -e 's/.md$/.html/g' -e 's/_//g' + local path + + path=$(echo "${1}" | sed -e 's/^src/out/g' -e 's/.md$/.html/g' -e 's/_//g') + + if _get_value "${1}" "draft" >/dev/null; then + path="$(dirname ${path})/$(echo ${path} | sha1).html" + fi + + echo "${path}" } _get_final_path() { @@ -39,7 +47,13 @@ _get_final_path() { _get_title() { # 1: filename - basename "${1}" | sed 's/\..*//g' | tr - " " + local title + local file_title + + file_title=$(basename "${1}" | sed 's/\..*//g' | tr - " ") + title=$(_get_value "${1}" "title" "${file_title}") + + echo "${title}" } _get_date_human() { @@ -115,9 +129,12 @@ _parse_metadata() { _render_metadata() { # 1: filename # 2: output - _ENABLED_METADATA="date author" local key local value + local title + + # _ENABLED_METADATA="date author" + title=$(_get_value "${1}" "title") echo "" + + if [ "${title}" ]; then + echo "

${title}

" + fi } _render_index() { @@ -141,6 +162,7 @@ _render_index() { for file in $(_sort_index_per_date "${1}"); do path=$(_get_final_path "${file}") [ "${path}" = "$(_get_final_path ${1})" ] && continue + _get_value "${file}" "draft" >/dev/null && continue title=$(_get_value "${file}" "title" "$(_get_title ${file})") -- cgit v1.2.3