commit acf86c3e6ad4d634304563aa4b0695b99d1432f7 Author: Midgard Date: Sat Nov 23 14:51:27 2024 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4a54bac --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +mattermost_channels.html diff --git a/footer.html b/footer.html new file mode 100644 index 0000000..d57f538 --- /dev/null +++ b/footer.html @@ -0,0 +1,6 @@ + + + diff --git a/gen.sh b/gen.sh new file mode 100755 index 0000000..1902d3d --- /dev/null +++ b/gen.sh @@ -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' +} + +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" < +

$display_name

+
+
Channel purpose
+
$purpose
+ +
Channel header
+
$header
+ +
Channel created on
+
$create_at
+ +
Last message
+
$last_post_at
+ +
Total amount of messages
+
$total_msg_count
+
+ +HERE + done + +substitute_vars < footer.html >> "$out" diff --git a/header.html b/header.html new file mode 100644 index 0000000..d0a71eb --- /dev/null +++ b/header.html @@ -0,0 +1,10 @@ + + + + + + Zeus Mattermost channels + + +

Zeus Mattermost channels

+

As of $lastupdated