1 # Blosxom Plugin: categories
2 # Author: Todd Larason (jtl@molehill.org)
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
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
28 'alt-shell' => 'Alternative Shell',
30 'blosxom' => 'blosxom',
35 'internet' => 'Internet',
39 'software' => 'Software',
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 --------
56 # --------------------------------------
63 my($pkg, $files) = @_;
65 foreach (keys %$files) {
66 my($dir, $file) = m!(.*)/(.*)!;
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;
80 $categories = report_root();
86 if (!$blosxom::path_info_yr and $blosxom::path_info and
87 ($blosxom::path_info !~ m|.*?/?\w+\.\w+$|)) {
89 my @path_info = split(/\//, $blosxom::path_info);
91 foreach (@path_info) {
93 $_ = %friendly_name->{$_} if %friendly_name->{$_};
94 $title .= qq!$name_sep$_!;
98 $title =~ s!^$name_sep!$title_sep!;
104 my($pkg, $path, $fn, $story_ref, $title_ref, $body_ref) = @_;
107 my @name = split(/\//, $path);
111 $_ = %friendly_name->{$_} if %friendly_name->{$_};
112 $name .= qq!$name_sep$_!;
115 $name =~ s!^$name_sep!!;
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('/', $_);
128 # $results .= report_dir_end();
129 $results .= report_categories_end();
134 sub report_categories_start {
138 sub report_dir_start {
139 my($fulldir, $thisdir, $numstories) = @_;
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!;
148 my($parent, $dir) = @_;
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"});
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/", $_);
162 $results .= report_dir_end();
168 sub report_dir_leaf {
169 my($fulldir, $thisdir, $numstories) = @_;
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!;
178 return qq!</ul>\n</li>\n!;
181 sub report_categories_end {
188 foreach (@prune_dirs) {
189 return 1 if $dir eq $_;