# Blosxom plugin: storytitle # Author(s): Struan Donald # Version: 0.5 # Documentation: see bottom of file or perldoc title package storytitle; use strict; use vars qw($sep $right $right_sep $left_sep $page_title $page_title_left $page_title_right); # ------------------ Config variables --------------------- # default seperator to add to story title $sep = ' : ' unless defined $sep; # do we default to the right aligned title # 1 for right aligned, 0 for left $right = 0 unless defined $right; # seperator for right aligned title $right_sep = ''|| $sep unless defined $right_sep; # seperator for left aligned title $left_sep = '' || $sep unless defined $left_sep; # ------ Output variables -------------------------------- $page_title; $page_title_left; $page_title_right; # --------------------------------------------------------- sub start { 1; } sub head { my ($p, $dir, $head) = @_; my $title; if (!$dir) { $title = (defined $blosxom::path_info_da ? "$blosxom::path_info_da/" : "") . (defined $blosxom::path_info_mo ? "$blosxom::path_info_mo/" : "") . "$blosxom::path_info_yr" ; } elsif ($dir =~ m#(.*?)/?([\-\.\w]+)\.(\w+)$# and $2 ne 'index') { my $file = join('/', $blosxom::datadir, $1, "$2.txt"); my $fh = new FileHandle; if (-f "$file" && $fh->open("< $file")) { chomp($title = <$fh>); $fh->close; } } if (defined $title and $title =~ /\S/) { $page_title_right = $right_sep . $title; $page_title_left = $title . $left_sep; $page_title = $right ? $page_title_right : $page_title_left; } else { # these need to be reset otherwise we'll get the last value $page_title_right = undef; $page_title_left = undef; $page_title = undef; } } 1; __END__ =head1 NAME Blosxom Plug-in: storytitle =head1 SYNOPSIS Allows you to include the story title in the page header for individually views blosxom stories. =head2 QUICK START Put title in your plug-ins directory. If required change the $sep variable. This controls the seperator that goes at the start of the story title. E.g. if $sep is ' : ' and the story title is 'A blosxom entry' then the plugin will return ' : A blosxom entry'. Now all individually displayed stories can have their title in the pages title tag, or anywhere else in the page header you want. Just place $storytitle::page_title where you want to display the story title. =head2 LEFT AND RIGHT ALIGNED TITLES If you have a need for a left aligned title (i.e. you want to have 'story title : somethign else') then you can use either $storytitle::page_title_left or set the value of $right in the configuration to 0. In that case $storytitle::page_title will have the seperator at the left. You can also individually configure the left and right sided seperators with the left_sep and right_sep configuration options. $storytitle::page_title_left and $storytitle::page_title_right will access the left and right sided titles. =head1 VERSION 0.5 =head2 CHANGES 0.5 - deals with filenames with like foo.bar.txt and foo-bar.txt (thanks to Antti Vähä-Sipilä for pointing this out) catches titles containing only white space. 0.4 - bugfix to stop title values hanging around under static generation 0.3 - fixed left_title to actually be a left title 0.2 - introduced left and right options =head1 AUTHOR Struan Donald , http://exo.org.uk/code/ =head2 CREDITS Lim Chee Aun for the left/right sided titles idea. =head1 SEE ALSO Blosxom Home/Docs/Licensing:http://blosxom.sourceforge.net/ Blosxom Plugin Docs: http://blosxom.sourceforge.net/documentation/users/plugins.html =head1 BUGS None known; please send bug reports and feedback to the Blosxom development mailing list . =head1 COPYRIGHT Copyright (C) 2003 Struan Donald. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut