From 35b57b07f63804ecf07b5c471a656a646b9d460a Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sat, 19 Aug 2023 19:29:04 +0200 Subject: New blog index; improved build script --- build.sh | 81 +++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 37 deletions(-) (limited to 'build.sh') diff --git a/build.sh b/build.sh index 8f3034a..e3b18bf 100755 --- a/build.sh +++ b/build.sh @@ -1,14 +1,14 @@ #!/bin/sh recursivebuild() { - local destdir=$(echo $1 | sed 's|^src|http|') + local destdir=$(echo "$1" | sed 's|^src|http|') mkdir -p "$destdir" - for file in $(ls $1); do - if [ -d "$1/$file" ]; then - mkdir -p "$destdir/$file" - recursivebuild "$1/$file" + for file in "$1"/*; do + if [ -d "$file" ]; then + mkdir -p "$destdir/$(basename "$file")" + recursivebuild "$file" else - copyfile "$1/$file" "$destdir" + copyfile "$file" "$destdir" fi done } @@ -20,63 +20,70 @@ copyfile() { extension=$(echo "$file" | sed 's/.*\.//') case "$extension" in md) - t="$(markdowntitle $file)" + t="$(markdowntitle "$file")" sed "s/TITLE/$t/" < top.html > "$ind" lowdown "$file" >> "$ind" cat bottom.html >> "$ind" ;; html) - t="$(htmltitle $file)" + t="$(htmltitle "$file")" cat top.html "$file" bottom.html | sed "s/TITLE/$t/" > "$ind" ;; *) - cp "$file" "$dest/$(basename $file)" + cp "$file" "$dest/$(basename "$file")" esac } markdowntitle() { - grep '^# ' $1 | head -n 1 | sed 's/^# //' + grep '^# ' "$1" | head -n 1 | sed 's/^# //' } htmltitle() { grep '$//' } -makeblog() { - bf=src/blog/blog.md - ff=src/blog/feed.xml +makeblogindexandfeed() { + mkdir -p http/blog + bf=http/blog/index.html + ff=http/blog/feed.xml - printf "# Blog\n\n[RSS Feed](feed.xml)\n\n" > $bf - cp feed-top.xml $ff + sed "s/TITLE/Blog/" < top.html > "$bf" + { echo '

Blog

'; + echo ''; + echo 'RSS feed'; } >> "$bf" - for i in $(ls src/blog | sort -r); do - if [ -d src/blog/$i ]; then - f="src/blog/$i/*.md" - d=$(echo $i | grep -oE '^[0-9]{4}-[0-9]{2}-[0-9]{2}') - t=$(head -n 1 $f | sed 's/# //') + cp feed-top.xml "$ff" - thisyear=$(echo $d | sed 's/-.*//') - if [ "$thisyear" != "$lastyear" ]; then - printf "\n## $thisyear\n\n" >> $bf - lastyear=$thisyear - fi + for i in $(ls src/blog | sort -r); do + [ -d "src/blog/$i" ] || continue - echo "* $d [$t]($i)" >> $bf + f="src/blog/$i/*.md" + d="$(echo "$i" | grep -oE '^[0-9]{4}-[0-9]{2}-[0-9]{2}')" + t="$(head -n 1 $f | sed 's/# //')" - echo "" >> $ff - echo "$t" >> $ff - echo "https://sebastiano.tronto.net/blog/$i" >> $ff - echo "$t" >> $ff - echo "$d" >> $ff - echo "" >> $ff - echo "" >> $ff + thisyear="$(echo "$d" | sed 's/-.*//')" + if [ "$thisyear" != "$lastyear" ]; then + echo "" >> "$bf" + lastyear=$thisyear fi + + { echo ""; + echo ""; } >> "$bf" + + { echo ""; + echo "$t"; + echo "https://sebastiano.tronto.net/blog/$i"; + echo "$t"; + echo "$d"; + echo ""; + echo ""; } >> $ff done - echo "" >> $ff - echo "" >> $ff - echo "" >> $ff + echo '

$thisyear

$d$t
' >> "$bf" + cat bottom.html >> "$bf" + + { echo ""; echo ""; echo ""; } >> "$ff" } -makeblog +makeblogindexandfeed recursivebuild src -- cgit v1.3