diff options
author | Romain Gonçalves <me@rgoncalves.se> | 2021-08-12 16:43:58 +0200 |
---|---|---|
committer | Romain Gonçalves <me@rgoncalves.se> | 2021-08-12 16:43:58 +0200 |
commit | 1a533812e1a32af573e803032788a27fa593a020 (patch) | |
tree | 0959e62a38499ab473126f15a364aeec115f170c /bin | |
parent | a677748e19cc2e490ffcdbd5799755e67ab4ff02 (diff) | |
download | rgoncalves.se-1a533812e1a32af573e803032788a27fa593a020.tar.gz |
ssg: Force local variable
Diffstat (limited to 'bin')
-rw-r--r-- | bin/ssg-template | 28 |
1 files 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 "<ul class=\"metadata\">" for key in ${_ENABLED_METADATA}; do @@ -127,6 +144,10 @@ _render_metadata() { echo "<li>${key}: ${value}</li>" done echo "</ul>" + + if [ "${title}" ]; then + echo "<h1>${title}</h1>" + 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})") |