Initial commit
This commit is contained in:
commit
acf86c3e6a
4 changed files with 81 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
mattermost_channels.html
|
6
footer.html
Normal file
6
footer.html
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<footer>
|
||||||
|
<div>Last updated $lastupdated</div>
|
||||||
|
<div>Created by Midgard</div>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
64
gen.sh
Executable file
64
gen.sh
Executable 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/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/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
10
header.html
Normal 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>
|
Loading…
Reference in a new issue