Initial commit

This commit is contained in:
Midgard 2024-11-23 14:51:27 +01:00
commit acf86c3e6a
Signed by: midgard
GPG key ID: 511C112F1331BBB4
4 changed files with 81 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
mattermost_channels.html

6
footer.html Normal file
View file

@ -0,0 +1,6 @@
<footer>
<div>Last updated $lastupdated</div>
<div>Created by Midgard</div>
</footer>
</body>
</html>

64
gen.sh Executable file
View file

@ -0,0 +1,64 @@
#!/bin/sh
set -euo pipefail
out=mattermost_channels.html
substitute_vars() {
sed 's/$lastupdated/'"$(date '+%Y-%m-%d %H:%M')"/g
}
jqo() {
json="$1"
shift 1
printf '%s' "$json" | jq -cr "$@" || { printf 'jq errored performing %s on this input: %s\n' "$*" "$json" >&2; }
}
htmlescape() {
sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g'
}
format_timestamp() {
format_str="$1"
xargs -Ixxx date --date "@xxx" "+$format_str"
}
substitute_vars < header.html > "$out"
mmcli ls zeus | \
jq -cs 'sort_by(- .last_post_at) | .[]' | \
while IFS="" read -r chan || [ -n "$chan" ]; do
if [ "$(jqo "$chan" '.type')" != O ]; then continue; fi
name="$(jqo "$chan" '.name' | htmlescape)"
display_name="$(jqo "$chan" '.display_name' | htmlescape)"
purpose="$(jqo "$chan" '.purpose' | htmlescape)"
header="$(jqo "$chan" '.header' | htmlescape)"
create_at="$(jqo "$chan" '.create_at / 1000' | format_timestamp '%Y-%m-%d')"
last_post_at="$(jqo "$chan" '.last_post_at / 1000' | format_timestamp '%Y-%m-%d %H:%M')"
total_msg_count="$(jqo "$chan" '.total_msg_count')"
cat >> "$out" <<HERE
<div class="channel" id="channel_$name">
<h3><a href="https://mattermost.zeus.gent/zeus/$name">$display_name</a></h3>
<dl>
<dt>Channel purpose</dt>
<dd class="purpose">$purpose</dd>
<dt>Channel header</dt>
<dd class="header">$header</dd>
<dt>Channel created on</dt>
<dd class="create_at">$create_at</dd>
<dt>Last message</dt>
<dd class="last_post_at">$last_post_at</dd>
<dt>Total amount of messages</dt>
<dd class="total_msg_count">$total_msg_count</dd>
</dl>
</div>
HERE
done
substitute_vars < footer.html >> "$out"

10
header.html Normal file
View file

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Zeus Mattermost channels</title>
</head>
<body>
<h1>Zeus Mattermost channels</h1>
<p>As of $lastupdated</p>