Skip to content

Commit

Permalink
Remote data: Add activities section for matrix, mail and github
Browse files Browse the repository at this point in the history
  • Loading branch information
Lino committed Feb 13, 2024
1 parent 38a53a4 commit fd36221
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
- name: Build
env:
HUGO_ENV: production
HUGO_MATRIX_ACCESS_TOKEN: ${{ secrets.HUGO_MATRIX_ACCESS_TOKEN }}
HUGO_MATRIX_HOME_SERVER: ${{ secrets.HUGO_MATRIX_HOME_SERVER }}
URL_DEVELOPMENT: ${{ vars.URL_DEVELOPMENT }}
run: hugo --minify -b "$URL_DEVELOPMENT/$GITHUB_REF_NAME" --destination "branch/$GITHUB_REF_NAME"

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
- name: Build
env:
HUGO_ENV: production
HUGO_MATRIX_ACCESS_TOKEN: ${{ secrets.HUGO_MATRIX_ACCESS_TOKEN }}
HUGO_MATRIX_HOME_SERVER: ${{ secrets.HUGO_MATRIX_HOME_SERVER }}
URL_PRODUCTION: ${{ vars.URL_PRODUCTION }}
run: hugo --minify -b "$URL_PRODUCTION"

Expand Down
2 changes: 2 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ defaultContentLanguageInSubdir = true
SectionPagesMenu = "main"
enableRobotsTXT = true

timeout = "100s"

disableKinds = ['taxonomy', 'term']

[languages]
Expand Down
12 changes: 12 additions & 0 deletions content/_index.de.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@ Die Grundlage von Freifunk bildet ein sogenanntes Mesh-Netzwerk. Alle WLAN-Route
## Wie kann ich mitmachen?

Mach mit und werde FreifunkerIn! Komm zu den Treffen oder geh direkt zum HowTo und mach deinen Router fit für Freifunk! Gibt es noch keine weiteren Freifunker_innen in deiner Gegend? Dann bist du die oder der Erste und andere werden dir bald folgen!

## Aktivitäten

{{< matrix-activity >}}

---

{{< github-activity >}}

---

{{< mail-subjects >}}
34 changes: 34 additions & 0 deletions layouts/partials/github-activity.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{/* Number of repos in the organization.
Private and archived repos are included. */}}
{{ $repo_list_json := getJSON "https://api.github.com/orgs/freifunk-berlin/repos?per_page=100&sort=pushed"}}
{{ $repo_count := len $repo_list_json}}

{{/* Top three active repos.
Based on latest push. */}}
{{ $top_repos := slice }}
{{ range $index, $element := $repo_list_json }}
{{ if eq $index 3 }}
{{ break }}
{{ end }}
{{ $top_repos = $top_repos | append $element.name }}
{{ end }}

{{/* Number of commits of the last seven days in the most active repos.
Checking all repos would take to long. This only represents a a part of the total commits. A plus gets always appended to the counter. */}}
{{ $past_seven_days_date := now.AddDate 0 0 -7 }}
{{ $past_seven_days := $past_seven_days_date.Format "2006-01-02T15:04:05Z" }}
{{ $commit_count := 0 }}

{{ range $element := $top_repos }}
{{ $commit_url := printf "https://api.github.com/repos/freifunk-berlin/%s/commits?per_page=100&since=%s" $element $past_seven_days }}
{{ $commit_json := getJSON $commit_url }}
{{ $commit_count = add $commit_count (len $commit_json) }}
{{ end }}
{{ $commit_count = printf "%d+" $commit_count }}

{{/* Return map with the github activity data:
- repo_count
- top_repos
- commit_count */}}
{{ $github_activity := dict "repo_count" $repo_count "top_repos" $top_repos "commit_count" $commit_count }}
{{ return $github_activity}}
50 changes: 50 additions & 0 deletions layouts/partials/mail-subjects.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{{/* Return the five latest subjects from the mailing list.
Only checks the current and previous month. Duplicates are removed, when they follow each other directly. */}}
{{ $current_month := now.Format "2006-January" }}
{{ $current_month_url := printf "https://lists.berlin.freifunk.net/pipermail/berlin/%s/subject.html" $current_month }}
{{ $current_month_response := resources.GetRemote $current_month_url }}
{{ $current_month_html := $current_month_response.Content }}
{{ $current_month_subjects := findRE "\\[Berlin-wireless\\] (.*?)\n" $current_month_html }}
{{ $current_month_reversed_subjects := slice }}
{{ $array_length := len $current_month_subjects }}
{{- range $index, $element := $current_month_subjects -}}
{{ $current_month_reversed_subjects = $current_month_reversed_subjects | append (index $current_month_subjects (sub $array_length (add $index 1))) }}
{{- end }}

{{ $previous_month_date := now.AddDate 0 -1 0 }}
{{ $previous_month := $previous_month_date.Format "2006-January" }}
{{ $previous_month_url := printf "https://lists.berlin.freifunk.net/pipermail/berlin/%s/subject.html" $previous_month }}
{{ $previous_month_response := resources.GetRemote $previous_month_url }}
{{ $previous_month_html := $previous_month_response.Content }}
{{ $previous_month_subjects := findRE "\\[Berlin-wireless\\] (.*?)\n" $previous_month_html }}
{{ $previous_month_reversed_subjects := slice }}
{{ $array_length := len $previous_month_subjects }}
{{- range $index, $element := $previous_month_subjects -}}
{{ $previous_month_reversed_subjects = $previous_month_reversed_subjects | append (index $previous_month_subjects (sub $array_length (add $index 1))) }}
{{- end }}

{{ $subjects := $current_month_reversed_subjects | append $previous_month_reversed_subjects }}

{{ $previous_subject := "" }}
{{ $current_subject := "" }}
{{ $subject_count := 0 }}
{{ $latest_subjects := slice }}

{{ range $element := $subjects }}

{{ if eq $subject_count 5 }}
{{ break }}
{{ end }}

{{ $current_subject = trim (strings.TrimPrefix "[Berlin-wireless]" $element) " " }}

{{ if not (eq $previous_subject $current_subject) }}
{{ $subject_count = add $subject_count 1 }}
{{ $latest_subjects = $latest_subjects | append $current_subject }}
{{ end }}

{{ $previous_subject = $current_subject }}

{{ end }}

{{ return $latest_subjects }}
59 changes: 59 additions & 0 deletions layouts/partials/matrix-activity.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{{ $ACCESS_TOKEN := getenv "HUGO_MATRIX_ACCESS_TOKEN" }}
{{ $HOME_SERVER := getenv "HUGO_MATRIX_HOME_SERVER" }}

{{/* Number of members in main chat. */}}
{{ $room_url := printf "%s/_matrix/client/v1/rooms/!zTqqomsFqlyQjqrZpm:matrix.org/hierarchy?access_token=%s" $HOME_SERVER $ACCESS_TOKEN }}
{{ $room_json := getJSON $room_url }}
{{ $room := index $room_json.rooms 0 }}


{{/* Number of rooms in the space.
Only checks the first page. If more rooms exist, a plus gets appended to the counter.
Max rooms per page depends on server configuration. */}}
{{ $space_url := printf "%s/_matrix/client/v1/rooms/!EzZtBKEuKZqxrYSugs:digitale-gesellschaft.ch/hierarchy?access_token=%s" $HOME_SERVER $ACCESS_TOKEN }}
{{ $space_json := getJSON $space_url }}
{{ $room_count := len $space_json.rooms }}
{{ if isset $space_json "next_batch" }}
{{ $room_count = printf "%d+" $room_count}}
{{ end }}


{{/* Number of messages in the past seven days in main chat.
Only checks the first page. If the oldest message on that page is within the seven days, a plus gets appended to the counter.
Max messages per page depends on server configuration. */}}
{{ $messages_url := printf "%s/_matrix/client/v3/rooms/!zTqqomsFqlyQjqrZpm:matrix.org/messages?access_token=%s&limit=100&dir=b" $HOME_SERVER $ACCESS_TOKEN }}
{{ $messages_json := getJSON $messages_url }}

{{ $oneWeekAgoUnixSeconds := now.Unix | sub 604800 }}
{{ $oneWeekAgoUnixMilliseconds := $oneWeekAgoUnixSeconds | mul -1000 }}

{{ $message_array_len := len $messages_json.chunk }}
{{ $message_last_index := sub $message_array_len 1 }}

{{ $message_count := 0 }}
{{ $oneWeekAgoUnixMilliseconds}}

{{ range $index, $element := $messages_json.chunk }}

{{ if gt $element.origin_server_ts $oneWeekAgoUnixMilliseconds }}
{{$element.origin_server_ts}}

{{ $message_count = add $message_count 1 }}

{{ if eq $index $message_last_index }}
{{ $message_count = printf "%d+" $message_count}}
{{ end }}

{{ else }}
{{ break }}
{{ end }}

{{ end }}


{{/* Return map with the matrix activity data:
- message_count
- room_count
- member_count */}}
{{ $matrix_activity := dict "message_count" $message_count "room_count" $room_count "member_count" $room.num_joined_members }}
{{ return $matrix_activity}}
9 changes: 9 additions & 0 deletions layouts/shortcodes/github-activity.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{ $github_activity := partial "github-activity.html" . }}

Zur Versionsverwaltunng der Software nutzen wir <a href="https://github.com/freifunk-berlin/">Github</a>. Dort gab es in den letzten sieben Tagen <b>{{ $github_activity.commit_count }} (commits)</b> Änderungen am Code. Auf der Platform werden insgesamt <b>{{ $github_activity.repo_count }} (repositories)</b> Projekte verwaltet. Die aktivsten sind derzeit:

<ul style="text-align:left;margin-left: auto;margin-right: auto;width: fit-content;">
{{ range $element := $github_activity.top_repos }}
<li><a href="https://github.com/freifunk-berlin/{{ $element }}">{{ $element }}</a></li>
{{ end }}
</ul>
9 changes: 9 additions & 0 deletions layouts/shortcodes/mail-subjects.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{ $mail_subjects := partial "mail-subjects.html" . }}

Auf der <a href="https://lists.berlin.freifunk.net/cgi-bin/mailman/listinfo/berlin">Mailingliste</a> werden gerade folgende Themen diskutiert:

<ul style="text-align:left;margin-left: auto;margin-right: auto;width: fit-content;">
{{ range $element := $mail_subjects }}
<li>{{ $element }}</li>
{{ end }}
</ul>
3 changes: 3 additions & 0 deletions layouts/shortcodes/matrix-activity.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ $matrix_activity := partial "matrix-activity.html" . }}

Im <a href="https://matrix.to/#/#berlin.freifunk.net:matrix.org">Freifunk Berlin Matrix Space</a> gibt es aktuell <b>{{ $matrix_activity.room_count }} Chat-Räume mit {{ $matrix_activity.member_count }} Usern</b>. Im Hauptchat wurden in den letzten sieben Tagen <b>{{ $matrix_activity.message_count }} Nachrichten</b> verschickt.

0 comments on commit fd36221

Please sign in to comment.