diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2023-08-19 19:29:04 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2023-08-19 19:29:04 +0200 |
| commit | 35b57b07f63804ecf07b5c471a656a646b9d460a (patch) | |
| tree | 761d970dfb629afa440c1654c16e60e52db02665 /build.sh | |
| parent | 3a2940a9648a4a6e3b47b5a55643f357fc7e6790 (diff) | |
| download | sebastiano.tronto.net-35b57b07f63804ecf07b5c471a656a646b9d460a.tar.gz sebastiano.tronto.net-35b57b07f63804ecf07b5c471a656a646b9d460a.zip | |
New blog index; improved build script
Diffstat (limited to 'build.sh')
| -rwxr-xr-x | build.sh | 81 |
1 files changed, 44 insertions, 37 deletions
| @@ -1,14 +1,14 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | 2 | ||
| 3 | recursivebuild() { | 3 | recursivebuild() { |
| 4 | local destdir=$(echo $1 | sed 's|^src|http|') | 4 | local destdir=$(echo "$1" | sed 's|^src|http|') |
| 5 | mkdir -p "$destdir" | 5 | mkdir -p "$destdir" |
| 6 | for file in $(ls $1); do | 6 | for file in "$1"/*; do |
| 7 | if [ -d "$1/$file" ]; then | 7 | if [ -d "$file" ]; then |
| 8 | mkdir -p "$destdir/$file" | 8 | mkdir -p "$destdir/$(basename "$file")" |
| 9 | recursivebuild "$1/$file" | 9 | recursivebuild "$file" |
| 10 | else | 10 | else |
| 11 | copyfile "$1/$file" "$destdir" | 11 | copyfile "$file" "$destdir" |
| 12 | fi | 12 | fi |
| 13 | done | 13 | done |
| 14 | } | 14 | } |
| @@ -20,63 +20,70 @@ copyfile() { | |||
| 20 | extension=$(echo "$file" | sed 's/.*\.//') | 20 | extension=$(echo "$file" | sed 's/.*\.//') |
| 21 | case "$extension" in | 21 | case "$extension" in |
| 22 | md) | 22 | md) |
| 23 | t="$(markdowntitle $file)" | 23 | t="$(markdowntitle "$file")" |
| 24 | sed "s/TITLE/$t/" < top.html > "$ind" | 24 | sed "s/TITLE/$t/" < top.html > "$ind" |
| 25 | lowdown "$file" >> "$ind" | 25 | lowdown "$file" >> "$ind" |
| 26 | cat bottom.html >> "$ind" | 26 | cat bottom.html >> "$ind" |
| 27 | ;; | 27 | ;; |
| 28 | html) | 28 | html) |
| 29 | t="$(htmltitle $file)" | 29 | t="$(htmltitle "$file")" |
| 30 | cat top.html "$file" bottom.html | sed "s/TITLE/$t/" > "$ind" | 30 | cat top.html "$file" bottom.html | sed "s/TITLE/$t/" > "$ind" |
| 31 | ;; | 31 | ;; |
| 32 | *) | 32 | *) |
| 33 | cp "$file" "$dest/$(basename $file)" | 33 | cp "$file" "$dest/$(basename "$file")" |
| 34 | esac | 34 | esac |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | markdowntitle() { | 37 | markdowntitle() { |
| 38 | grep '^# ' $1 | head -n 1 | sed 's/^# //' | 38 | grep '^# ' "$1" | head -n 1 | sed 's/^# //' |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | htmltitle() { | 41 | htmltitle() { |
| 42 | grep '<!--TITLE: ' "$1" | sed 's/^<!--TITLE: //' | sed 's/-->$//' | 42 | grep '<!--TITLE: ' "$1" | sed 's/^<!--TITLE: //' | sed 's/-->$//' |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | makeblog() { | 45 | makeblogindexandfeed() { |
| 46 | bf=src/blog/blog.md | 46 | mkdir -p http/blog |
| 47 | ff=src/blog/feed.xml | 47 | bf=http/blog/index.html |
| 48 | ff=http/blog/feed.xml | ||
| 48 | 49 | ||
| 49 | printf "# Blog\n\n[RSS Feed](feed.xml)\n\n" > $bf | 50 | sed "s/TITLE/Blog/" < top.html > "$bf" |
| 50 | cp feed-top.xml $ff | 51 | { echo '<h1 id="blog">Blog</h1>'; |
| 52 | echo '<table id="blog">'; | ||
| 53 | echo '<a href="feed.xml">RSS feed</a>'; } >> "$bf" | ||
| 51 | 54 | ||
| 52 | for i in $(ls src/blog | sort -r); do | 55 | cp feed-top.xml "$ff" |
| 53 | if [ -d src/blog/$i ]; then | ||
| 54 | f="src/blog/$i/*.md" | ||
| 55 | d=$(echo $i | grep -oE '^[0-9]{4}-[0-9]{2}-[0-9]{2}') | ||
| 56 | t=$(head -n 1 $f | sed 's/# //') | ||
| 57 | 56 | ||
| 58 | thisyear=$(echo $d | sed 's/-.*//') | 57 | for i in $(ls src/blog | sort -r); do |
| 59 | if [ "$thisyear" != "$lastyear" ]; then | 58 | [ -d "src/blog/$i" ] || continue |
| 60 | printf "\n## $thisyear\n\n" >> $bf | ||
| 61 | lastyear=$thisyear | ||
| 62 | fi | ||
| 63 | 59 | ||
| 64 | echo "* $d [$t]($i)" >> $bf | 60 | f="src/blog/$i/*.md" |
| 61 | d="$(echo "$i" | grep -oE '^[0-9]{4}-[0-9]{2}-[0-9]{2}')" | ||
| 62 | t="$(head -n 1 $f | sed 's/# //')" | ||
| 65 | 63 | ||
| 66 | echo "<item>" >> $ff | 64 | thisyear="$(echo "$d" | sed 's/-.*//')" |
| 67 | echo "<title>$t</title>" >> $ff | 65 | if [ "$thisyear" != "$lastyear" ]; then |
| 68 | echo "<link>https://sebastiano.tronto.net/blog/$i</link>" >> $ff | 66 | echo "<tr><td><h2>$thisyear</h2></td></tr>" >> "$bf" |
| 69 | echo "<description>$t</description>" >> $ff | 67 | lastyear=$thisyear |
| 70 | echo "<pubDate>$d</pubDate>" >> $ff | ||
| 71 | echo "</item>" >> $ff | ||
| 72 | echo "" >> $ff | ||
| 73 | fi | 68 | fi |
| 69 | |||
| 70 | { echo "<tr><td>$d</td>"; | ||
| 71 | echo "<td><a href=\"$i\">$t</a></td></tr>"; } >> "$bf" | ||
| 72 | |||
| 73 | { echo "<item>"; | ||
| 74 | echo "<title>$t</title>"; | ||
| 75 | echo "<link>https://sebastiano.tronto.net/blog/$i</link>"; | ||
| 76 | echo "<description>$t</description>"; | ||
| 77 | echo "<pubDate>$d</pubDate>"; | ||
| 78 | echo "</item>"; | ||
| 79 | echo ""; } >> $ff | ||
| 74 | done | 80 | done |
| 75 | 81 | ||
| 76 | echo "" >> $ff | 82 | echo '</table>' >> "$bf" |
| 77 | echo "</channel>" >> $ff | 83 | cat bottom.html >> "$bf" |
| 78 | echo "</rss>" >> $ff | 84 | |
| 85 | { echo ""; echo "</channel>"; echo "</rss>"; } >> "$ff" | ||
| 79 | } | 86 | } |
| 80 | 87 | ||
| 81 | makeblog | 88 | makeblogindexandfeed |
| 82 | recursivebuild src | 89 | recursivebuild src |
