Add georss support to atomfeed.
[blosxom-plugins.git] / general / categories
blobc0ce484e7e5adc0bb019387717afc5712f8f26e0
1 # Blosxom Plugin: categories
2 # Author: Todd Larason (jtl@molehill.org)
3 # Version: 1.1
4 # Blosxom Home/Docs/Licensing: http://www.blosxom.com/
6 # This plugin is simplified version of "categories" plugin.
7 # "categories" plugin maybe found at:
8 # http://www.blosxom.com/plugins/category/categories.htm
10 package categories;
12 use strict;
13 use vars qw($categories $title $name);
15 # --- Configuration Variables ----------
17 # should the story-count add up?
18 my $add_up_story_count = 1;
20 # should the story-count display?
21 my $display_story_count = 0;
23 # directories to include, but not children of -- full name under $datadir
24 my @prune_dirs = qw!/draft /old /freeze!;
26 # friendly name of directories
27 my %friendly_name = (
28   'alt-shell' => 'Alternative Shell',
29   'blog'      => 'blog',
30   'blosxom'   => 'blosxom',
31   'coding'    => 'Coding',
32   'foaf'      => 'FOAF',
33   'gadget'    => 'Gadget',
34   'game'      => 'Game',
35   'internet'  => 'Internet',
36   'media'     => 'Media',
37   'misc'      => 'Misc',
38   'rss'       => 'RSS',
39   'software'  => 'Software',
40   'sports'    => 'Sports',
41   'webdesign' => 'Web Design',
44 # separator string between $blog_title and $categories::name
45 my $title_sep = " - ";
47 # separater string between each name of category
48 my $name_sep = " » ";
50 # --- Plug-in package variables --------
52 my %children;
53 my %stories;
54 my %seen;
56 # --------------------------------------
58 sub start {
59   return 1;
62 sub filter {
63   my($pkg, $files) = @_;
65   foreach (keys %$files) {
66     my($dir, $file) = m!(.*)/(.*)!;
67     my $child;
68     $stories{$dir}++;
70     while ($dir ne $blosxom::datadir) {
71       ($dir, $child) = ($dir =~ m!(.*)/(.*)!);
72       $stories{$dir}++ if $add_up_story_count;
74       if (!$seen{"$dir/$child"}++) {
75         push @{$children{$dir}}, $child;
76       }
77     }
78   }
80   $categories = report_root();
82   return 1;
85 sub head {
86   if (!$blosxom::path_info_yr and $blosxom::path_info and
87         ($blosxom::path_info !~ m|.*?/?\w+\.\w+$|)) {
88     $title = '';
89     my @path_info = split(/\//, $blosxom::path_info);
91     foreach (@path_info) {
92       next if !$_;
93       $_ = %friendly_name->{$_} if %friendly_name->{$_};
94       $title .= qq!$name_sep$_!;
95     }
96   }
98   $title =~ s!^$name_sep!$title_sep!;
100   return 1;
103 sub story {
104   my($pkg, $path, $fn, $story_ref, $title_ref, $body_ref) = @_;
106   $name = '';
107   my @name = split(/\//, $path);
109   foreach (@name) {
110     next if !$_;
111     $_ = %friendly_name->{$_} if %friendly_name->{$_};
112     $name .= qq!$name_sep$_!;
113   }
115   $name =~ s!^$name_sep!!;
117   return 1;
120 sub report_root {
121   my $results = report_categories_start();
122 #   $results .= report_dir_start('', 'all entries', $stories{$blosxom::datadir});
124   foreach (sort @{$children{$blosxom::datadir}}) {
125     $results .= report_dir('/', $_);
126   }
128 #   $results .= report_dir_end();
129   $results .= report_categories_end();
131   return $results;
134 sub report_categories_start {
135   return qq!<ul>\n!;
138 sub report_dir_start {
139   my($fulldir, $thisdir, $numstories) = @_;
140   $numstories ||= 0;
141   $thisdir = %friendly_name->{$thisdir} if %friendly_name->{$thisdir};
143   return qq!<li><a href="$blosxom::url${fulldir}" title="$thisdir">$thisdir</a> ($numstories)\n<ul>\n! if $display_story_count;
144   return qq!<li><a href="$blosxom::url${fulldir}" title="$thisdir">$thisdir</a>\n<ul>\n!;
147 sub report_dir {
148   my($parent, $dir) = @_;
149   my $results;
150   local $_;
152   if (!defined($children{"$blosxom::datadir$parent$dir"}) || is_prune_dir("$parent$dir")) {
153     $results = report_dir_leaf("$parent$dir/", "$dir", $stories{"$blosxom::datadir$parent$dir"});
154   }
155   else {
156     $results = report_dir_start("$parent$dir/", "$dir", $stories{"$blosxom::datadir$parent$dir"});
158     foreach (sort @{$children{"$blosxom::datadir$parent$dir"}}) {
159       $results .= report_dir("$parent$dir/", $_);
160     }
162     $results .= report_dir_end();
163   }
165   return $results;
168 sub report_dir_leaf {
169   my($fulldir, $thisdir, $numstories) = @_;
170   $numstories ||= 0;
171   $thisdir = %friendly_name->{$thisdir} if %friendly_name->{$thisdir};
173   return qq!<li><a href="$blosxom::url${fulldir}" title="$thisdir">$thisdir</a> ($numstories)</li>\n! if $display_story_count;
174   return qq!<li><a href="$blosxom::url${fulldir}" title="$thisdir">$thisdir</a></li>\n!;
177 sub report_dir_end {
178   return qq!</ul>\n</li>\n!;
181 sub report_categories_end {
182   return qq!</ul>!;
185 sub is_prune_dir {
186   my($dir) = @_;
188   foreach (@prune_dirs) {
189     return 1 if $dir eq $_;
190   }
192   return 0;