From 78b32f8fa039192d7d66a04abaab58244af720d0 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Thu, 5 Dec 2024 20:42:23 +0800 Subject: build.sh: add comment block --- www/scripts/build.sh | 55 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/www/scripts/build.sh b/www/scripts/build.sh index a0c971d..cec10fd 100755 --- a/www/scripts/build.sh +++ b/www/scripts/build.sh @@ -13,13 +13,35 @@ template_dir=${template_dir:-`pwd`/templates} # functions {{{ -# add indent for each line except
+# add indent for each line except 
 {{{
+
 indent() {
   indent="$(printf "%${1}s")"
-  sed "s/^/${indent}/; /
/!b; :pre; N; /<\/pre>/!b pre"
+  sed "/^$/ !s/^/${indent}/; /
/!b; :pre; N; /<\/pre>/!b pre"
 }
 
-# use heredoc to generate html from .md file and templates
+# }}}
+# print comment block {{{
+comment_block() {
+  [ "$comment" = true ] || return 0
+  <<-COMMENT cat
+	
+ [Comment on this page] + + +
+ COMMENT +} + +# }}} +# use heredoc to generate html from .md file and templates {{{ html() { <<-END_OF_HTML sed '1d;$d' @@ -32,6 +54,7 @@ html() {
$(${markdown_bin} | indent 4)
+ $(comment_block | indent 2)

${footer} @@ -40,19 +63,25 @@ html() { END_OF_HTML } -# list of latest posts in markdown format +# }}} +# list of latest posts in markdown format {{{ + latest_posts() { (IFS=$'\n'; echo "${index_list[*]}") | sort -r | head -20 | while read date path title; do echo "- [$title](/$path)" done } -# print frontmatter from markdown file with format: " " +# }}} +# print frontmatter from markdown file with format: " " {{{ + get_frontmatter() { sed -n '1 {//q; s/"//g; s/://p' } -# process frontmatter +# }}} +# process frontmatter {{{ + add_index() { unset title public index date draft @@ -76,12 +105,16 @@ add_index() { index_list+=("$iso8601 $path $title") } -# remove SGML comments but keep the top one as frontmatter +# }}} +# remove SGML comments but keep the top one as frontmatter {{{ + ignore_comment() { sed '1 !{ /^$/ d }' } -# Generate the feed file +# }}} +# Generate the feed file {{{ + make_rss() { echo -n "Making RSS " @@ -125,6 +158,7 @@ make_rss() { chmod 644 "$blog_feed" } +# }}} # }}} # prepare directory for outputs {{{ @@ -150,7 +184,7 @@ declare -i counter for file in $files; do # set variables path=$(<<<"$file" sed "s#^${input_dir}/##; s/\.md$//").html; mkdir -p $(dirname $output_dir/$path) - content="$(cat ${file} | ignore_comment)" + content="$(<${file} ignore_comment)" # use frontmatter to decide making html file or not <<<"$content" add_index || continue @@ -160,10 +194,13 @@ for file in $files; do # make html file for draft h1="$(<<<"$content" get_frontmatter | sed -n 's/^title *//p')" + comment="$(<<<"$content" get_frontmatter | sed -n 's/^comment *//p')" echo "$content" \ | tee $output_dir/${file#${input_dir}/} \ | { [ -n "$h1" ] && echo "# $h1"; cat; } \ | html >$output_dir/$path + + unset h1 comment done echo -- cgit v1.2.3-70-g09d2