diff --git a/footer.html b/footer.html index fdeaaf2..9b44319 100644 --- a/footer.html +++ b/footer.html @@ -1,6 +1,7 @@ + diff --git a/gen.sh b/gen.sh index f9163f0..b04e59b 100755 --- a/gen.sh +++ b/gen.sh @@ -1,7 +1,10 @@ #!/bin/sh set -euo pipefail -export MM_SERVER=zeus.mattermost.gent +if [ -z "$MM_SERVER" ]; then + echo "Set environment variable MM_SERVER to e.g. mattermost.example.com" + exit 1 +fi mattermost_name="Zeus Mattermost" team_name="zeus" @@ -10,6 +13,9 @@ dir="$(dirname "$0")" out="$dir/dist/channels/index.html" mkdir -p "$(dirname "$out")" +cp go_to_channel.png dist/ +cp main.css dist/ + custom_emoji_file="$(mktemp --tmpdir custom_emoji.XXXXXXXXXX.json)" mmcli listcustomemoji | jq -s > "$custom_emoji_file" @@ -30,11 +36,20 @@ emoji() { markdown() { htmlescape | \ - { pandoc --from=markdown --to=html || printf "Markdown conversion failed\n" >&2; } | \ - sed 's/src="\(.*\)"/src=""/g' | \ + { pandoc --from=markdown+autolink_bare_uris+emoji --to=html || printf "Markdown conversion failed\n" >&2; } | \ + sed -E ' + s|<(h[0-6])[^>]*>|
|g + s||
|g + s/src="\(.*\)"/src=""/g + ' | \ + sed -f "$channels_sed_file" | \ emoji } +format_number() { + awk '{printf "%'\''d\n", $1}' +} + format_timestamp() { format_str="$1" xargs -Ixxx date --date "@xxx" "+$format_str" @@ -42,6 +57,9 @@ format_timestamp() { channels="$(mmcli ls "$team_name" | jq -cs 'sort_by(- .last_post_at) | .[]')" channel_count="$(jqo "$channels" -s 'length')" +channels_sed_file="$(mktemp --tmpdir "mattermost_channels.XXXXXXXXX.sed")" +jqo "$channels" -s 'map(.name) | sort_by(length) | reverse | .[]' | sed 's|.*|s/~&/CHANNEL[&]<\\/a>/g|' > "$channels_sed_file" +printf 's/CHANNEL\\[\\([^]]*\\)\\]/~\\1/g\n' >> "$channels_sed_file" substitute_vars() { sed ' @@ -63,28 +81,48 @@ printf '%s\n' "$channels" | while IFS="" read -r chan || [ -n "$chan" ]; do header="$(jqo "$chan" '.header' | markdown)" 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')" + total_msg_count="$(jqo "$chan" '.total_msg_count' | format_number)" 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
-
+
+

$display_name Go to channel

+
+HERE + if [ -n "$purpose" ]; then + cat >> "$out" < +
Purpose
+
$purpose
+ +HERE + fi + if [ -n "$header" ]; then + cat >> "$out" < +
Header
+
$header
+ + +HERE + fi + cat >> "$out" < +
+
Created on
+
$create_at
+
+
+
Last message
+
$last_post_at
+
+
+
Amount of messages
+
$total_msg_count
+
+ + + HERE done diff --git a/go_to_channel.png b/go_to_channel.png new file mode 100644 index 0000000..9d525a4 Binary files /dev/null and b/go_to_channel.png differ diff --git a/header.html b/header.html index f922a93..6b18910 100644 --- a/header.html +++ b/header.html @@ -4,14 +4,11 @@ $mattermost_name channels - + -

$mattermost_name channels

-

A list of all $channel_count public channels in the team $team_name on $mattermost_name, as of $lastupdated

+
+

$mattermost_name channels

+

A list of all $channel_count public channels in the team $team_name on $mattermost_name, as of $lastupdated

+
+
diff --git a/main.css b/main.css new file mode 100644 index 0000000..013ccb9 --- /dev/null +++ b/main.css @@ -0,0 +1,102 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body { + font-family: sans-serif; + background-color: #121212; /* Dark background */ + color: #c9c2c0; /* Light text color */ + line-height: 1.6; + padding: 20px; +} + +@media (max-width: 600px) { + body { + padding: 10px; + } +} + +h1 { font-size: 125%; } + +h2 { font-size: 110%; } + +h3 { font-size: 105%; } + +.h1, .h2, .h3, .h4, .h5, .h6 { + font-weight: bold; +} + +a { + color: #ff7000; + text-decoration: none; + transition: color 0.3s; +} +a:hover { + color: #efa76f; +} + +dl { + margin-left: 0.4em; +} + +dt { + font-weight: bold; + color: #8f6254; + margin-top: 0.625em; + text-transform: uppercase; + font-size: 75%; +} + +dd { + margin-left: 0.4em; +} + +@media (min-width: 590px) { + .stats { + display: flex; + } + .stats > * { + flex-grow: 1; + } +} + +header, footer { + text-align: center; + margin: 1em 0; +} + +/* Card Style */ +.channel { + background-color: #1E1E1E; /* Card background */ + border-radius: 1em; + padding: 0.7em 1em 1em; + margin: 1em auto; + max-width: 75em; + box-shadow: 0 0.3em 0.5em rgba(0, 0, 0, 1); +} + +@media (min-width: 1000px) { + header, footer { + margin: 3em 0; + font-size: 125%; + } + + .channel { + margin-bottom: 2em; + } +} + +img.emoji { + width: 1em; + height: 1em; + vertical-align: text-bottom; +} + +img.go_to_channel { + margin-left: 0.3em; + width: 0.8em; + height: 0.8em; + vertical-align: baseline; +}