gamelog/bin/html.sh

141 lines
3.3 KiB
Bash
Raw Normal View History

2024-08-05 01:50:30 +00:00
#!/bin/zsh
2024-02-03 22:56:10 +00:00
database="db/games.rec"
## BEGIN: TEMPLATES ##
gameheadertmpl='<article>
<h2 id={{Id}}>{{Module}} ({{System}}) <small><a href="#{{Id}}">#</a></small></h2>
<p>{{Module}} is a game of {{System}} that I started playing on {{Started}} as a {{Role}}. It is a {{Format}} {{Length}} and is currently {{Status}}.</p>
<p>Here is how it went!</p>
'
updatetmpl='<h3 id="u{{Id}}">{{Created}} <small><a href="#u{{Id}}">#</a></small></h3>
{{Text}}
'
2024-08-05 01:50:30 +00:00
updateupdatetmpl='<h3 id="u{{Id}}">{{Created}} {{Game_System}}: {{Game_Module}}<small><a href="#u{{Id}}">#</a></small></h3>
{{Text}}
'
2024-02-03 22:56:10 +00:00
gamefootertmpl='<center>🎲🎲</center>
</article>'
toctmpl='<li><a href="#{{Id}}">{{Module}} ({{System}})</a></li>'
## END: TEMPLATES ##
2024-08-05 01:50:30 +00:00
BEGIN=$(
2024-02-03 22:56:10 +00:00
cat<<EOF
2024-08-05 01:50:30 +00:00
<html>
<head>
<title>The Most Interesting Thing That Happened To Me Today</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="alternate" type="application/rss+xml" href="rss.xml" title="dozens interesting microblog">
<style>
body {
max-width: 80ch;
margin: 0 auto;
padding: 3rem 1rem;
}
h2 {
border-bottom: solid 1px black;
margin-top: 3rem;
}
h2, h3 {
position: relative;
}
h2 a, h3 a {
position: absolute;
left: -1.2rem;
text-decoration: none;
opacity: 0.2;
}
h2 a {
line-height: 1.4;
}
h3 a {
line-height: 1.2;
}
h2:hover a, h3:hover a {
opacity: 1;
}
@media (prefers-color-scheme: dark) {
html, body {
background: #15191d;
color: #ddd;
}
body a, body a:visited {
color: #809fff;
}
h2 {
border-bottom: solid 1px white;
}
}
</style>
</head>
<body>
<header>
<h1>Gamelogs</h1>
<p>All the roleplaying games I\'ve played.</p>
<li>src: <a href="https://git.tilde.town/dozens/gamelog">https://git.tilde.town/dozens/gamelog</a></li>
<li>dozens webring: <a href="https://tilde.town/%7Edozens/webring/dozens/index.html?name=gamelog&amp;dir=prev">previous</a> <a href="https://tilde.town/%7Edozens/webring/dozens/index.html">index</a> <a href="https://tilde.town/%7Edozens/webring/dozens/index.html?name=gamelog&amp;dir=next">next</a></li>
<li><a href="feed.xml">rss</a></li>
<p>
View by:
<a href="index.html">Game</a>
<a href="updates.html">Update</a>
</p>
</header>
<main>
2024-02-03 22:56:10 +00:00
EOF
2024-08-05 01:50:30 +00:00
)
2024-02-03 22:56:10 +00:00
2024-08-05 01:50:30 +00:00
END=$(
cat<<'END-OF-END'
</main>
</body>
</html>
END-OF-END
)
2024-02-03 22:56:10 +00:00
2024-08-05 01:50:30 +00:00
## INDEX (View by Game) ##
exec > dist/index.html
echo $BEGIN
2024-02-03 22:56:10 +00:00
echo '<h2>Contents</h2>'
recsel $database -t Game | recfmt "$toctmpl"
allgames=(`recsel $database -t Game -P Id -C | tr '\n' ' '`)
for idx in "${allgames[@]}"
do
2024-08-05 01:50:30 +00:00
recsel $database -t Game -e "Id = $idx" \
| recfmt "$gameheadertmpl"
recsel $database -t Update -e "Game = $idx" \
| recfmt "$updatetmpl" | markdown
2024-02-03 22:56:10 +00:00
echo $gamefootertmpl
done
2024-08-05 01:50:30 +00:00
echo $END
## UPDATE (View by Update) ##
exec > dist/updates.html
echo $BEGIN
recsel db/games.rec -t Update -j Game \
| awk '
BEGIN { RS="";FS="\n" }
{ rec[NR] = $0 }
END {
for (i=length(rec);i>0;i--) {
print rec[i]; print "";
}
}' \
| recfmt "$updateupdatetmpl" \
| markdown
echo $END