From ad3af3cccc6f2e50b250bd3ca8d98e2a1a58e994 Mon Sep 17 00:00:00 2001 From: Gavin Carr Date: Mon, 3 Dec 2007 10:21:28 +0000 Subject: [PATCH 1/1] Add __END_CONFIG__ token to remaining gavinc plugins. --- gavinc/entries_timestamp | 1 + gavinc/metamail | 1 + gavinc/rss20 | 136 ++++++++++++++++++++++++++++----------- gavinc/storydate | 31 ++++++++- gavinc/storytags | 32 +++++---- gavinc/tagcloud | 1 + gavinc/tags | 1 + 7 files changed, 152 insertions(+), 51 deletions(-) diff --git a/gavinc/entries_timestamp b/gavinc/entries_timestamp index be6ddb5..b814c9f 100644 --- a/gavinc/entries_timestamp +++ b/gavinc/entries_timestamp @@ -32,6 +32,7 @@ my $entries_index = 'entries_timestamp.index'; my $reindex_password = 'abracad'; # CHANGEME! # -------------------------------- +# __END_CONFIG__ my $q = CGI->new; diff --git a/gavinc/metamail b/gavinc/metamail index 29da361..3ae65df 100644 --- a/gavinc/metamail +++ b/gavinc/metamail @@ -23,6 +23,7 @@ my @keep_in_body_headers = qw(Tags); my $unfold_headers = 1; # -------------------------------- +# __END_CONFIG__ sub start { 1 }; diff --git a/gavinc/rss20 b/gavinc/rss20 index 8419ef1..402a59a 100644 --- a/gavinc/rss20 +++ b/gavinc/rss20 @@ -1,21 +1,24 @@ # Blosxom Plugin: rss20 # Author(s): Gavin Carr -# Version: 0.001002 -# Requires: storydate, lastmodified2 -# Suggests: absolute -# Follows: storydate, lastmodified2 +# Version: 0.002000 +# Requires: storydate +# Suggests: absolute, storytags +# Follows: storydate package rss20; use strict; + use vars qw( $flavour $author_email - $error_email + $author_name + $webmaster_email $permalink $trackback_link $copyright - $generator_url + $generator + $category_list ); # --- Configuration variables ----- @@ -25,10 +28,18 @@ $flavour = 'rss'; #$flavour = 'rss20'; # What email address should be used as the default author email? -$author_email = 'author@example.com'; +# Recommended format is 'email (name)', but bare emails or mailto emails are ok too +$author_email = 'author@example.com (A. U. Thor)'; + +# What name should be used as the default author name? +# Define this only if you don't want to disclose an email address in $author_email. +# It will be ignored if $author_email is set. +$author_name = ''; # What email address should feed errors be reported to? -$error_email = ''; +# Recommended format is 'email (name)', but bare emails or mailto emails are ok too +$webmaster_email = ''; +#$webmaster_email = 'webmaster@example.com (Web Master)'; # What do your story permalinks look like? # This must be single-quoted, to defer evaluation; blosxom namespace applies @@ -44,11 +55,15 @@ $trackback_link = ''; $copyright = ''; # Generator that produced this feed -$generator_url = "http://blosxom.sourceforge.net/?v=$blosxom::version"; +$generator = "blosxom $blosxom::version"; # -------------------------------- +# __END_CONFIG__ + +$webmaster_email ||= $author_email; -$error_email ||= $author_email; +my $channel_indent = 8; +my $item_indent = 12; # Escape <, >, and & to hex-encoded entities for max compatibility in text elements # See http://www.rssboard.org/rss-profile#data-types-characterdata @@ -71,6 +86,7 @@ sub start { _load_templates(); } +my $do_encode = 0; sub story { my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_; @@ -78,12 +94,24 @@ sub story { return unless $blosxom::flavour eq $flavour; # Don't double-encode if someone else has already done it - return unless $blosxom::encode_xml_entities; + return unless $do_encode || $blosxom::encode_xml_entities; + + # Because we're inside a loop, we set $do_encode for runs after the first + unless ($do_encode) { + $do_encode = 1; + $blosxom::encode_xml_entities = 0; + } # Encode and reset encode_xml_entities flag $$title_ref = _escape_text( $$title_ref ); $$body_ref = _escape_html( $$body_ref ); - $blosxom::encode_xml_entities = 0; + + $category_list = ''; + if ($blosxom::plugins{storytags}) { + for (@storytags::taglist) { + $category_list .= qq($_\n) . ' ' x $item_indent; + } + } } # --- Private subroutines @@ -110,42 +138,78 @@ sub _load_templates { + xmlns:atom="http://www.w3.org/2005/Atom"> $blosxom::blog_title - $blosxom::url - $blosxom::blog_description - \$lastmodified2::latest_iso8601 - $blosxom::blog_language - mailto:$rss20::author_email - $rss20::copyright - - - + $blosxom::url/ +HEAD + + if ($blosxom::path_info) { + $blosxom::template{$flavour}{'head'} .= + ' ' x $channel_indent . + qq($blosxom::path_info\n); + } + if ($blosxom::blog_description) { + $blosxom::template{$flavour}{'head'} .= + ' ' x $channel_indent . + qq($blosxom::blog_description\n); + } + if ($rss20::author_email) { + $blosxom::template{$flavour}{'head'} .= + ' ' x $channel_indent . + qq($rss20::author_email\n); + } + elsif ($rss20::author_name) { + $blosxom::template{$flavour}{'head'} .= + ' ' x $channel_indent . + qq($rss20::author_name\n); + } + if ($rss20::webmaster_email) { + $blosxom::template{$flavour}{'head'} .= + ' ' x $channel_indent . + qq($rss20::webmaster_email\n); + } + if ($rss20::copyright) { + $blosxom::template{$flavour}{'head'} .= + ' ' x $channel_indent . + qq($rss20::copyright\n); + } + my $path_info = $blosxom::path_info_orig || "/$blosxom::path_info"; + $blosxom::template{$flavour}{'head'} .= <\$storydate::latest_rfc822 + $blosxom::blog_language + $rss20::generator + hourly 1 2000-01-01T12:00+00:00 - HEAD $blosxom::template{$flavour}{'story'} = < \$title - $rss20::permalink - \$body - $rss20::trackback_link - $rss20::permalink - \$storydate::story_iso8601 + $rss20::permalink + $rss20::permalink + \$storydate::story_rfc822 +STORY + + if ($rss20::trackback_link) { + $blosxom::template{$flavour}{'story'} .= + ' ' x $item_indent . + qq($rss20::trackback_link\n); + } + $blosxom::template{$flavour}{'story'} .= <\$body + STORY $blosxom::template{$flavour}{'foot'} = <<'FOOT'; - - + + + FOOT 1; @@ -180,10 +244,10 @@ Flavour string to use for your feed (typically 'rss' or 'rss20'). Default author email address for posts. -=item $error_email +=item $webmaster_email -Email address to use to report errors with the feed (defaults to -$author_email). +Email address to use for webmaster responsible for the feed (defaults +to $author_email). =item $permalink diff --git a/gavinc/storydate b/gavinc/storydate index 35c060b..78c2df1 100644 --- a/gavinc/storydate +++ b/gavinc/storydate @@ -2,7 +2,7 @@ # Author(s): Gavin Carr # (based on work by Frank Hecker # and Bob Schumaker ) -# Version: 0.001000 +# Version: 0.002000 # Documentation: See the bottom of this file or type: perldoc storydate package storydate; @@ -20,6 +20,7 @@ use File::stat; my @strftime_modules = qw(Time::Piece Date::Format POSIX); # --------------------------------- +# __END_CONFIG__ # Package variables use vars qw( @@ -29,11 +30,13 @@ use vars qw( $story_mtime_iso8601 $now_rfc822 $now_iso8601 + $latest_rfc822 + $latest_iso8601 %strftime_formats ); %strftime_formats = ( - rfc822 => "%a, %d %b %Y %T %z", + rfc822 => "%a, %d %b %Y %T %z", # ISO 8601 format (localtime, including time zone offset) # Format is YYYY-MM-DDThh:mm:ssTZD per http://www.w3.org/TR/NOTE-datetime iso8601 => "%Y-%m-%dT%T%z", @@ -48,6 +51,22 @@ sub start { 1; } +sub filter { + my ($pkg, $files, $others) = @_; + + # Find the latest publish date in our stories + my $latest_ts = 0; + for (values %$files) { + $latest_ts = $_ if $_ > $latest_ts; + } + + # Format the 'latest' variables + $latest_rfc822 = format_date('rfc822', $latest_ts); + $latest_iso8601 = format_date('iso8601', $latest_ts); + + return 1; +} + sub story { my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_; @@ -206,6 +225,14 @@ The current time in RFC822 format. The current time in ISO8601 format. +=item $latest_rfc822 + +The latest story publication date, in RFC822 format. + +=item $latest_iso8601 + +The latest story publication date, in ISO8601 format. + =back In addition, storydate defines a few subroutines that might be useful diff --git a/gavinc/storytags b/gavinc/storytags index 148a48f..1665dbf 100644 --- a/gavinc/storytags +++ b/gavinc/storytags @@ -1,6 +1,6 @@ # Blosxom Plugin: storytags # Author(s): Gavin Carr -# Version: 0.001000 +# Version: 0.002000 # Documentation: See the bottom of this file or type: perldoc storytags # Requires: tags # Follows: tags @@ -12,7 +12,7 @@ use strict; # Uncomment next line to enable debug output (don't uncomment debug() lines) #use Blosxom::Debug debug_level => 1; -use vars qw($taglist); +use vars qw($taglist @taglist); # --- Configuration variables ----- @@ -21,6 +21,7 @@ my $prefix = 'Tags: '; my $suffix = '. '; # --------------------------------- +# __END_CONFIG__ $taglist = ''; @@ -31,24 +32,26 @@ sub story { my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_; return 1 unless $tags::tag_cache - && ref $tags::tag_cache - && keys %{ $tags::tag_cache }; + && ref $tags::tag_cache + && keys %{ $tags::tag_cache }; return 1 unless defined $tags::tag_cache->{"$path/$filename"}; - $taglist = _format_taglist($tags::tag_cache->{"$path/$filename"}->{tags}); + @taglist = (); + @taglist = sort { lc $a cmp lc $b } split /\s*,\s*/, + $tags::tag_cache->{"$path/$filename"}->{tags} + if defined $tags::tag_cache->{"$path/$filename"}->{tags}; + $taglist = _format_taglist( \@taglist ); return 1; } sub _format_taglist { my ($tags) = @_; - $tags = '' unless defined $tags; - my @tags = sort { lc $a cmp lc $b } split /\s*,\s*/, $tags; - return '' unless @tags; + return '' unless @$tags; return $prefix . join(', ', map { qq() } - @tags + @$tags ) . $suffix; } @@ -60,14 +63,17 @@ __END__ =head1 NAME storytags - blosxom plugin to format a per-story $storytags::taglist string +and @storytags::taglist array of tags =head1 DESCRIPTION L is a blosxom plugin to format a per-story $storytags::taglist -string. The string is a comma-separated list of the tags defined for the -story, prefixed by $storytags::prefix, and suffixed by $storytags::suffix. -If no tags are defined, then $taglist will be the empty string '' (i.e. no -prefix and suffix are added). +string, and a @storytags::taglist array of tags. The $taglist is a +comma-separated list of the tags defined for the story, prefixed by +$storytags::prefix, and suffixed by $storytags::suffix. If no tags are +defined, then $taglist will be the empty string '' (i.e. no prefix and +suffix are added). @taglist is a simple array of the tags for the story, +and an empty array if none are set. The default values for $prefix and $suffix are 'Tags: ' and '. ' respectively, so a typical $taglist might look like: diff --git a/gavinc/tagcloud b/gavinc/tagcloud index c94ddb3..e0c3baa 100644 --- a/gavinc/tagcloud +++ b/gavinc/tagcloud @@ -33,6 +33,7 @@ use vars qw(%config $cloud); ); # --------------------------------- +# __END_CONFIG__ my %tagcloud_blacklist = map { $_ => 1 } @{$config{tagcloud_blacklist}}; diff --git a/gavinc/tags b/gavinc/tags index 9282ea2..5c5d813 100644 --- a/gavinc/tags +++ b/gavinc/tags @@ -25,6 +25,7 @@ my $tag_header = 'Tags'; my $tag_cache_file = "$blosxom::plugin_state_dir/tag_cache"; # --------------------------------- +# __END_CONFIG__ $tag_cache = {}; $tag_entries = {}; -- 2.30.2