Fix how the date/time of the feed is determined from the date/time of the most recent...
[blosxom-plugins.git] / general / storytitle
blob5e6ae2d968a66c22d85e17ebd1dff2ce9a67c26d
1 # Blosxom plugin: storytitle
2 # Author(s): Struan Donald <code@exo.org.uk>
3 # Version: 0.5
4 # Documentation: see bottom of file or perldoc title
6 package storytitle;
8 use strict;
9 use vars qw($sep $right $right_sep $left_sep $page_title $page_title_left $page_title_right);
11 # ------------------ Config variables ---------------------
13 # default seperator to add to story title
14 $sep = ' : ' unless defined $sep;
16 # do we default to the right aligned title
17 # 1 for right aligned, 0 for left
18 $right = 0 unless defined $right;
20 # seperator for right aligned title 
21 $right_sep = ''|| $sep unless defined $right_sep;
23 # seperator for left aligned title
24 $left_sep = '' || $sep unless defined $left_sep;
26 # ------ Output variables  --------------------------------
27 $page_title;
28 $page_title_left;
29 $page_title_right;
31 # ---------------------------------------------------------
33 sub start { 1; }
34 sub head {
35     my ($p, $dir, $head) = @_;
36     my $title;
37     if (!$dir) {
38         $title = (defined $blosxom::path_info_da ? "$blosxom::path_info_da/" : "") . (defined $blosxom::path_info_mo ? "$blosxom::path_info_mo/" : "") . "$blosxom::path_info_yr" ;
39         
40     } elsif ($dir =~ m#(.*?)/?([\-\.\w]+)\.(\w+)$# and $2 ne 'index') {
41         my $file = join('/', $blosxom::datadir, $1, "$2.txt");
42         my $fh = new FileHandle;
43         if (-f "$file" && $fh->open("< $file")) {
44             chomp($title = <$fh>);
45             $fh->close;
46         }
47     }
48     if (defined $title and $title =~ /\S/) {
49         $page_title_right = $right_sep . $title;
50         $page_title_left = $title . $left_sep;
51         $page_title =  $right ? $page_title_right : $page_title_left;
52     } else { # these need to be reset otherwise we'll get the last value
53         $page_title_right = undef;
54         $page_title_left = undef;
55         $page_title = undef;
56     } 
61 __END__
62 =head1 NAME
64 Blosxom Plug-in: storytitle
66 =head1 SYNOPSIS
68 Allows you to include the story title in the page header for individually views blosxom stories.
70 =head2 QUICK START
72 Put title in your plug-ins directory.
74 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'.
76 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.
78 =head2 LEFT AND RIGHT ALIGNED TITLES
80 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.
82 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.
84 =head1 VERSION
86 0.5
88 =head2 CHANGES
90 0.5 - deals with filenames with like foo.bar.txt and foo-bar.txt (thanks to
91       Antti Vähä-Sipilä for pointing this out)
92       catches titles containing only white space.
94 0.4 - bugfix to stop title values hanging around under static generation
96 0.3 - fixed left_title to actually be a left title
98 0.2 - introduced left and right options
100 =head1 AUTHOR
102 Struan Donald <code@exo.org.uk>, http://exo.org.uk/code/
104 =head2 CREDITS
106 Lim Chee Aun <http://phoenity.com/> for the left/right sided titles idea.
108 =head1 SEE ALSO
110 Blosxom Home/Docs/Licensing:http://blosxom.sourceforge.net/
112 Blosxom Plugin Docs: http://blosxom.sourceforge.net/documentation/users/plugins.html
114 =head1 BUGS
116 None known; please send bug reports and feedback to the Blosxom
117 development mailing list <blosxom-devel@lists.sourceforge.net>.
119 =head1 COPYRIGHT
121 Copyright (C) 2003 Struan Donald. 
123 This program is free software; you can redistribute
124 it and/or modify it under the same terms as Perl itself.
126 =cut