X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fupstream%2Fblosxom-plugins.git;a=blobdiff_plain;f=gavinc%2Ftags;h=644239efb9ee777d867dacbe88d4b5fa438f48f3;hp=0202f8550fe1ba3cac511a841c3a568eaf518025;hb=HEAD;hpb=e1adedc9d0a948a755ac648befbf5a3415072e5a diff --git a/gavinc/tags b/gavinc/tags index 0202f85..644239e 100644 --- a/gavinc/tags +++ b/gavinc/tags @@ -1,6 +1,6 @@ # Blosxom Plugin: tags # Author(s): Gavin Carr -# Version: 0.001000 +# Version: 0.002000 # Documentation: See the bottom of this file or type: perldoc tags package tags; @@ -11,20 +11,23 @@ use File::stat; # Uncomment next line to enable debug output (don't uncomment debug() lines) #use Blosxom::Debug debug_level => 2; -use vars qw($tagroot $tag_cache $tag_entries $tag_counts); +use vars qw(%config $tag_cache $tag_entries $tag_counts); # --- Configuration variables ----- +%config = (); + # What path prefix is used for tag-based queries? -$tagroot = "/tags"; +$config{tagroot} = "/tags"; # What story header to you use for your tags? -my $tag_header = 'Tags'; +$config{tag_header} = 'Tags'; # Where is our $tag_cache file? -my $tag_cache_file = "$blosxom::plugin_state_dir/tag_cache"; +$config{tag_cache_file} = "$blosxom::plugin_state_dir/tag_cache"; # --------------------------------- +# __END_CONFIG__ $tag_cache = {}; $tag_entries = {}; @@ -36,8 +39,8 @@ my $path_tags_op; sub start { # Load tag_cache - if (-f $tag_cache_file) { - my $fh = FileHandle->new( $tag_cache_file, 'r' ) + if (-f $config{tag_cache_file}) { + my $fh = FileHandle->new( $config{tag_cache_file}, 'r' ) or warn "[tags] cannot open cache: $!"; { local $/ = undef; @@ -54,9 +57,19 @@ sub entries { my $path_info = "/$blosxom::path_info"; # debug(3, "entries, path_info $path_info"); - if ($path_info =~ m!^$tagroot/(.*)!) { + if ($path_info =~ m!^$config{tagroot}/(.*)!) { + $blosxom::flavour = ''; my $taglist = $1; # debug(3, "entries, path_info matches tagroot (taglist $taglist)"); + + # Allow flavours appended to tags after a slash + # Dot-flavour versions are problematic, because tags can include dot e.g. web2.0 + if ($taglist =~ m! /(\w+)$ !x) { + $blosxom::flavour = $1; + $taglist =~ s! /$blosxom::flavour$ !!x; + } + + # Split individual tags out of taglist if ($taglist =~ m/;/) { @path_tags = split /\s*;\s*/, $taglist; $path_tags_op = ';'; @@ -65,8 +78,9 @@ sub entries { @path_tags = split /\s*,\s*/, $taglist; $path_tags_op = ','; } - # If $path_info matches $tagroot it's a virtual path, so reset + # If $path_info matches tagroot it's a virtual path, so reset $blosxom::path_info = ''; + $blosxom::flavour ||= $blosxom::default_flavour; } return 0; @@ -121,7 +135,7 @@ sub story { } # mtime has changed (or story is new) - compare old and new tagsets - my $tags_new = $blosxom::meta{$tag_header}; + my $tags_new = $blosxom::meta{$config{tag_header}}; my $tags_old = $tag_cache->{"$path/$filename"}->{tags}; # debug(2, "tags_new: $tags_new, tags_old: $tags_old"); @@ -148,9 +162,9 @@ sub last { } } - # Save tag caches back to $tag_cache_file - my $fh = FileHandle->new( $tag_cache_file, 'w' ) - or warn "[tags] cannot open cache '$tag_cache_file': $!" + # Save tag caches back to $config{tag_cache_file} + my $fh = FileHandle->new( $config{tag_cache_file}, 'w' ) + or warn "[tags] cannot open cache '$config{tag_cache_file}': $!" and return 0; print $fh Data::Dumper->Dump([ $tag_cache, $tag_entries, $tag_counts ], [ qw(tag_cache tag_entries tag_counts) ]); @@ -172,9 +186,9 @@ and allow tag-based filtering L is a blosxom plugin to read tags from story files, maintain a tag cache, and allow tag-based filtering. -Tags are defined in a comma-separated list in a $tag_header header at the -beginning of a blosxom post, with $tag_header defaulting to 'Tags'. So for -example, your post might look like: +Tags are defined in a comma-separated list in a $config{tag_header} header +at the beginning of a blosxom post, with $tag_header defaulting to 'Tags'. +So for example, your post might look like: My Post Title Tags: dogs, cats, pets @@ -182,16 +196,16 @@ example, your post might look like: Post text goes here ... L uses the L plugin to parse story headers, and stores -the tags in a cache (in $tag_cache_file, which defaults to +the tags in a cache (in $config{tag_cache_file}, which defaults to $blosxom::plugin_state_dir/tag_cache). The tag cache is only updated when the mtime of the story file changes, so L should perform pretty well. L also supports tag-based filtering. If the blosxom $path_info -begins with $tagroot ('/tags', by default, e.g. '/tags/dogs'), then -L filters the entries list to include only posts with the +begins with $config{tagroot} ('/tags', by default, e.g. '/tags/dogs'), +then L filters the entries list to include only posts with the specified tag. The following syntaxes are supported (assuming the -default '/tags' for $tagroot): +default '/tags' for 'tagroot'): =over 4 @@ -211,6 +225,25 @@ OR semantics. =back +Tag filtering also supports a trailing flavour after the taglist, +separated by a slash e.g. + + /tags/dogs/html + /tags/dogs,cats/rss + /tags/dogs;cats;pets/atom + +Note that this is different to L, which treats trailing +components as additional tags. + +At this point L don't support dot-flavour paths e.g. + + /tags/mysql.html + +The problem with this is that tags can include dots, so it's +ambiguous how to parse C, for instance. If you'd +like this supported and have suggestions about how to handle +the ambiguities, please get in touch. + =head1 USAGE L should be loaded early as it modifies blosxom $path_info when