site

bvnf.space sources
Log | Files | Refs

gen-index.sh (2488B)


      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
#!/bin/sh

# some of this was taken from june's feed.sh
# (https://git.causal.agency/src/plain/www/text.causal.agency/feed.sh)

exec > "${1:-index.html}"

cat << EOF
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1" />
	<title>Ben's blog</title>
	<link rel="stylesheet" href="../style.css" type="text/css" />
	<link rel="icon" href="data:image/gif;base64,R0lGODlhEAAQAPH/AAAAAP//AAD/AP8AACH/C0NSTkcAAAAAMS4wSAAAAAIwPwAAAAJATwAAAAJQXwAAAAJgbwAAAAJwfwAAAAKAjwAAAAKQnwAAAAKgrwAAAAKwvwAAAALAzwAAAALQ3wAAAALg7wAh+QQF//8EACwAAAAAEAAQAAACOJQFqTp9j5p00IApq8X0rTtBSQCQYIeUZGBmh7qyp8fGpGvV8PyqPt9bJUKiBUYT4SBPRMuH0SgAADs="/>
    <link rel="alternate" type="application/rss+xml" href="/blog/rss.xml"/>
    <style type="text/css">
    .left { float: left;}
    .right { float: right;}
    </style>
</head>
<body>
	<header><nav>
	<a href="../">[Home]</a>
	<a>[Blog]</a>
	<a href="//git.bvnf.space/">[Git]</a>
	<a href="../books/">[Books]</a>
	</nav></header>
	<p>
	<table>
EOF

ls -r -- *.txt *.gmi *.html | while read -r f; do
    unset date title desc link in
    case "$f" in
        index.html) continue ;;
        *.txt)
            link="$f"
            in="${f%.txt}.7"
            date="$(grep '^[.]Dd' "$in" | cut -c 5-)"
            title="$(grep '^[.]Nm' "$in" | cut -c 5-)"
            desc=" - $(grep '^[.]Nd' "$in" | cut -c 5-)"
        ;;
        *.gmi)
            link="gemini://gemini.bvnf.space/blog/${f#[0-9][0-9][0-9]-}"
            title="$(sed 1q "$f")"
            date="$(sed 1d "$f")"
        ;;
        *.html)
            link="$f"
            title="$(sed -n 's/.*<title>\(.*\)<\/title>.*/\1/p' "$f")"
            date="$(date -j +"%B %d, %Y" "$(sed -n 's/^.*written \([0-9]\{4\}\)-\([0-9]\{2\}\)-\([0-9]\{2\}\).*$/\1\2\30000/p' "$f")")"
        ;;
        *) continue ;;
    esac


    cat <<EOF
	<tr>
		<td align="left" class="index-post">
			<a href="$link">$title</a>$desc
		</td>
		<td align="right" class="index-date">$date</td>
	</tr>
EOF

done

cat << EOF
</table>
</p>
<br />
<hr />
<footer>
<div class="left">
<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="CC-BY 4.0" src="/media/cc-by.png" /></a>
</div>
<div class="right">
<img alt="Feed icon" src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/43/Feed-icon.svg/16px-Feed-icon.svg.png" width="16" height="16"/>
<a href="/blog/rss.xml">RSS feed</a>
</div>
</footer>
</body>
</html>
EOF