# Dirs: a Blagg plug-in to force posts to separate directories # Author: Brian St. Pierre # Version: 1.0.2 # Home/Docs/Licensing: http://www.bstpierre.org/Projects/blagg.html # Home/Docs/Licensing: http://bstpierre.org/Projects/blagg.html # # Copyright (c) 2004, Brian St. Pierre # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose, without fee, and without a written agreement # is hereby granted, provided that the above copyright notice and this # paragraph and the following two paragraphs appear in all copies. # # IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, # INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST # PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, # EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A # PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" # BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # # Revision history: # 1.0.2 -- 3/15/2004 -- Fix error: not skipping already-agg'd items # 1.0.1 -- 3/12/2004 -- Fix error: creating directories # 1.0.0 -- 3/12/2004 -- First public version # # Usage: # Add the following to the standard -blog and -mode command-line switches: # -plugin=dirs - activate the Dirs plug-in # # E.g. # blagg -blog=someblog -mode=interactive -plugin=dirs # --- Configurable variables ----- # Where are my blog entries kept? # (This should match $datadir from blagg.) my $datadir = "/home/brian/blagg"; # How do you want posts formatted? # Available variables: # $title -- item title # $link -- item link # $description -- item description # $feed_title -- feed title # $feed_link -- feed link # $feed_href -- $feed_title # $link_href -- link # Note: this example opens a

that needs to be terminated in the # blosxom story template. Note that double quotes (") in the format # need to be escaped. my $item_format = q#$feed_href: $title\n$description

\noriginally at: $link_href\n#; # -------------------------------- package blaggplug; use strict; use FileHandle; use CGI qw/:standard :netscape/; sub init { $item_format = "\$item = \"" . $item_format . "\";"; } sub post { my($title, $link, $description, $feed_title, $feed_link) = @_; my($i_dir, $i_fn); ($i_dir = $feed_title) =~ s/\W//g; ($i_dir = $i_dir) =~ tr/A-Z/a-z/; $i_dir = $datadir . "/" . $i_dir; ($i_fn = $title) =~ s/\W/_/g; $i_fn = "$i_dir/" . substr($i_fn, 0, 15) . '...' . substr($i_fn, -5) . ".txt"; if(! -d $i_dir) { mkdir $i_dir or die "failed to create directory $i_dir"; } # Skip already-aggregated items (aka filename already exists) return 1 if -e $i_fn; my $feed_href = a({-href=>$feed_link}, $feed_title); my $link_href = a({-href=>$link},'link'); my $item; eval($item_format); # modifies $item my $fh = new FileHandle; $fh->open("> $i_fn") && print($fh $item) && $fh->close(); # Return true to indicate blagg should not store locally. return 1; } sub destroy { }