Skip to content

Commit

Permalink
fix(activities): skip empty mailinglist responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Lino authored and FFHener committed Apr 2, 2024
1 parent f6edb46 commit 10fb5d6
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions layouts/partials/activities-mailinglist.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,30 @@
{{ $latest_subjects := slice }}
{{ $previous_subject := "" }}

{{ range $week := (seq 0 -2) }}
{{ $month_date := now.AddDate 0 ($week) 0 }}
{{ range $month := (seq 0 -2) }}
{{ $month_date := now.AddDate 0 ($month) 0 }}
{{ $month := $month_date.Format "2006-January" }}
{{ $mailing_list_url := printf "https://lists.berlin.freifunk.net/pipermail/berlin/%s/subject.html" $month }}
{{ $mailing_list_response := resources.GetRemote $mailing_list_url }}
{{ $mailing_list_html := $mailing_list_response.Content }}
{{ $mailing_list_subjects := findRE "\\[Berlin-wireless\\] (.*?)\n" $mailing_list_html }}
{{ $lastIndex := sub (len $mailing_list_subjects) 1 }}
{{ range $i, $e := $mailing_list_subjects }}
{{ $reverse_index := sub $lastIndex $i}}
{{ $subject := (index $mailing_list_subjects $reverse_index) }}
{{ $subject = trim (strings.TrimPrefix "[Berlin-wireless]" $subject) " " }}
{{ if not (eq $subject $previous_subject) }}
{{ $latest_subjects = $latest_subjects | append $subject }}
{{ if eq (len $latest_subjects) 5 }}
{{ break }}
{{ end }}
{{ end }}
{{ $previous_subject = $subject }}
{{ end }}
{{ if eq (len $latest_subjects) 5 }}
{{ break }}
{{ with $mailing_list_response }}
{{ $mailing_list_html := $mailing_list_response.Content }}
{{ $mailing_list_subjects := findRE "\\[Berlin-wireless\\] (.*?)\n" $mailing_list_html }}
{{ $lastIndex := sub (len $mailing_list_subjects) 1 }}
{{ range $i, $e := $mailing_list_subjects }}
{{ $reverse_index := sub $lastIndex $i}}
{{ $subject := (index $mailing_list_subjects $reverse_index) }}
{{ $subject = trim (strings.TrimPrefix "[Berlin-wireless]" $subject) " " }}
{{ if not (eq $subject $previous_subject) }}
{{ $latest_subjects = $latest_subjects | append $subject }}
{{ if eq (len $latest_subjects) 5 }}
{{ break }}
{{ end }}
{{ end }}
{{ $previous_subject = $subject }}
{{ end }}
{{ if eq (len $latest_subjects) 5 }}
{{ break }}
{{ end }}
{{ end }}
{{ end }}

Expand Down

0 comments on commit 10fb5d6

Please sign in to comment.