orrg

Unnamed repository; edit this file 'description' to name the repository.
git clone git://code.clttr.info/orrg.git
Log | Files | Refs | README | LICENSE

commit f1fa213eb470dbebf16dd42ce165726006a8e352
parent 17fb028c7177296e19bfc4c5ae18b04b5e82a27d
Author: René Wagner <rwagner@rw-net.de>
Date:   Thu, 17 Dec 2020 19:28:50 +0100

add whitespace removal for feed fields as well

Diffstat:
Morrg.pl | 43++++++++++++++++++++++++-------------------
1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/orrg.pl b/orrg.pl @@ -44,10 +44,10 @@ sub create_response return @body; } - push @body, '# '. $feed->title; + push @body, '# '. trim_ws($feed->title); push @body, 'fetched '. strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()); push @body, ''; - $feed->description eq '' or push @body, $feed->description; + $feed->description eq '' or push @body, trim_ws($feed->description); $feed->image eq '' or push @body, '=> '. $feed->image .' feed image'; $feed->link eq '' or push @body, ('=> '.$feed->link.' open website', ''); @@ -63,28 +63,23 @@ sub item my $hs = HTML::Strip->new(emit_spaces => 0, auto_reset => 1); my @item = (); - my $title = $it->title; - my $link = $it->link; - $title =~ s/^\s+//ig; - $title =~ s/\s+$//ig; - $link =~ s/^\s+//ig; - $link =~ s/\s+$//ig; - push @item, (($it->description ne '' && $it->description ne $it->title) || $it->pubDate ne '')? '## '. $title : $title; + my $title = trim_ws($it->title); + my $link = trim_ws($it->link); + my $desc = $it->description; + if ($desc ne '') { + $desc =~ s/\<li\>/* /igm; + $desc =~ s/\<h[1-2][^\>]+\>/### /igm; + $desc =~ s/\<br \/\>/\r\n/igm; + $desc = $hs->parse($desc); + $desc = trim_ws($desc); + } + push @item, (($desc ne '' && $desc ne $title) || $it->pubDate ne '')? '## '. $title : $title; if ($it->pubDate ne '') { my $dt = DateTime::Format::ISO8601->parse_datetime($it->pubDate); push @item, 'published '. strftime('%Y-%m-%dT%H:%M:%SZ', gmtime($dt->epoch)); push @item, ''; } - if ($it->description ne '' && $it->description ne $it->title) { - my $desc = $it->description; - $desc =~ s/\<li\>/* /igm; - $desc =~ s/\<h[1-2][^\>]+\>/### /igm; - $desc =~ s/\<br \/\>/\r\n/igm; - $desc = $hs->parse($desc); - $desc =~ s/^\r\n$//igm; - $desc =~ s/^\s+\*/*/igm; - $desc =~ s/\s+$//igm; - $desc =~ s/^\s+//igm; + if ($desc ne '' && $desc ne $title) { push @item, $desc; } $link eq '' or push @item, ('=> '.$link.' open entry in browser', ''); @@ -92,6 +87,16 @@ sub item return \@item; } +sub trim_ws +{ + my ( $string ) = @_; + $string =~ s/^\s+\*/*/igm; + $string =~ s/\s+$//igm; + $string =~ s/^\s+//igm; + $string =~ s/^\r\n$//igm; + return $string; +} + sub feed_get { my ( $query ) = @_;