65 lines
1.7 KiB
Bash
65 lines
1.7 KiB
Bash
|
#!/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"
|