From d235de268e26015020562daa46dee1e53f8f6308 Mon Sep 17 00:00:00 2001 From: Niklas Sombert Date: Fri, 29 May 2020 02:22:57 +0200 Subject: [PATCH] Substitute Freitagsfoo template if Event template isn't present --- extern/current_events | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/extern/current_events b/extern/current_events index 09e4f42..c6ded9e 100755 --- a/extern/current_events +++ b/extern/current_events @@ -351,9 +351,26 @@ sub get_data_from_template { my @lines = split( /\n/, mw_get($pagename) ); my $in_template = 0; + my $has_seen_template = 0; for my $line (@lines) { if ( $line =~ m/ ^ \s* \{\{ \s* Event \s* /ox ) { $in_template = 1; + $has_seen_template = 1; + } + if ($line =~ m/ ^ \s* \{\{ \s* Freitagsfoo \s* /ox and not $has_seen_template ) { + print $line; + my $content = join( "\n", @lines ); + $content =~ s/\{\{\s*Freitagsfoo/\{\{subst:Freitagsfoo /; + if ( my $ref = $mw->api( { + action => 'parse', + title => $pagename, + text => $content, + pst => 1, + onlypst => 1 + } ) ) { + $content = $ref->{parse}->{text}->{"*"}; + @lines = split( /\n/, $content); + } } if ( $in_template and ( $line =~ m{ \| \s* date \s* = \s* (? .+ ) $ }ix ) )