Created
February 28, 2022 20:35
-
-
Save emceeaich/e5104b9e3c48ea7427f87cff9c822ebe to your computer and use it in GitHub Desktop.
Blosxom, a simple blog hosting script from back in the day
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# Blosxom | |
# Author: Rael Dornfest <[email protected]> | |
# Version: 0+2i | |
# Home/Licensing: http://www.oreillynet.com/~rael/lang/perl/blosxom/ | |
# For documentation, type: perldoc blosxom | |
# Where are my blog entries kept? | |
my $datadir = "/Library/WebServer/Documents/blosxom"; | |
# How many entries should I show? | |
my $num_entries = 20; | |
use strict; | |
use DirHandle; | |
use FileHandle; | |
use File::stat; | |
use Time::localtime; | |
use CGI qw/:standard :netscape/; | |
my $fh = new FileHandle; | |
my $dh = new DirHandle($datadir); | |
my($nul,$pi_yr,$pi_mo,$pi_da,$id) = split /\//, path_info(); | |
print header(), ( $fh->open("< $datadir/head.html") ? <$fh> : (start_html('Blosxom'), center(font({-size=>'+3'},'Blosxom'), font({-size=>'+1'},br(),'[pronounced "blossom" or "blogsome"]'))) ); | |
my $curdate = ''; | |
foreach ( | |
sort { return stat("$datadir/$b")->ctime <=> stat("$datadir/$a")->ctime; } | |
grep /.txt$/, $dh->read | |
) { | |
last if $num_entries-- <= 0 && !path_info(); | |
my($fn) = ($_ =~ /^(.*)\.txt$/); | |
my $ctime = ctime(stat("$datadir/$fn.txt")->ctime); | |
my($dw,$mo,$da,$ti,$yr) = ( $ctime =~ /(\w{3}) +(\w{3}) +(\d{1,2}) +(\d{2}:\d{2}):\d{2} +(\d{4})$/ ); | |
next if $pi_yr && $yr != $pi_yr; last if $pi_yr && $yr < $pi_yr; | |
next if $pi_mo && $mo ne ucfirst(lc $pi_mo); | |
next if $pi_da && $da != $pi_da; last if $pi_da && $da < $pi_da; | |
$curdate ne "$dw, $da $mo $yr" && | |
print span({-class=>'blosxomDate'}, $curdate = "$dw, $da $mo $yr"); | |
if (-T "$datadir/$fn.txt" && $fh->open("< $datadir/$fn.txt")) { | |
print p({-class=>'blosxomEntry'}, a({-name=>$fn},span({-class=>'blosxomTitle'},b("".<$fh>))), br(), span({-class=>'blosxomBody'},<$fh>), br(), span({-class=>'blosxomTime'}, "Posted at $ti"), a({-href=>url()."/$yr/$mo/$da#$fn"},'#')),"\n\n"; | |
$fh->close; | |
} | |
} | |
print $fh->open("< $datadir/foot.html") ? <$fh> : center(h6("Powered -- for some narrow definition of powered -- by " . a({-href=>"http://www.oreillynet.com/~rael/lang/perl/blosxom/"},"Blosxom"))), end_html(); | |
__END__ | |
=head1 NAME | |
Blosxom [pronounced "blossom" or "blogsome"] | |
=head1 AUTHOR | |
Rael Dornfest <[email protected]> | |
=head1 VERSION | |
0+2i | |
Fri Mar 1 01:14:02 PST 2002 | |
=head1 LICENSING | |
Copyright 2002, Rael Dornfest | |
See: http://www.oreillynet.com/~rael/lang/perl/blosxom/#license | |
=head1 SYNOPSIS | |
Blosxom [pronounced "blossom" or "blogsome"] | |
is a lightweight (to say the least -- it's <31 lines of code) | |
Weblog-in-a-jiffy Perl CGI script for (but in no way limited to) Mac OS X. | |
Blosxom simply nabs text documents (written in your text editor of choice) | |
from a particular directory and displays them (in reverse chronological | |
order) as a Weblog. Simplistic -- but a spot of fun nevertheless. | |
The idea for Blosxom, while rattling about in my head for some time now, | |
came to the fore in response to a query on the Forwarding Address: OSX weblog | |
[http://saladwithsteve.com/osx/2002_02_01_archive.html#9743127] regarding | |
the existence of any weblog tool that takes makes use of some of the built-in | |
yummy goodness | |
of OS X. | |
=head1 DESIGN GOALS | |
=over 4 | |
=item 1. Weblogging should be as natural to the weblogger as the comfort of their favourite text editor, be it BBEdit, vi, emacs, notepad... | |
=item 2. As much an exercise in silliness as minimalism, Blosxom uses only in-the-box components of OS X and Perl. | |
=back | |
=head1 DIRECTIONS | |
=over 4 | |
=item 1. Make sure you have Apache running. Under OS X's Control Panels, visit the Sharing panel and start Web Sharing. | |
=item 2. Plop blosxom into your cgi-bin directory (/Library/WebServer/CGI-Executables on Mac OS X, typically /usr/local/apache/cgi-bin under *nix). | |
=item 3. Either a) create the default blog directory (on OS X: mkdir /Library/WebServer/Document/blosxom) directory or b) create it somewhere else and alter the $datadir variable in the blosxom script: my $datadir = "/path/to/your/blosxom/data/directory"; Note: the default blosxom data directory may be browsed-to as http://localhost/blosxom and its contents viewed by about anyone; I leave protection of this directory as an exercise for the reader (or a little later documentation). | |
=item 4. Blog away using your favourite text editor (BBEdit, vi, emacs, TextEdit, et al). Simply save your blog entries as text documents (be sure to include the .txt extension) into your blog directory and you're off to the races. | |
=item 5. Point your browser at http://localhost/cgi-bin/blosxom | |
=item 6. Enjoy! | |
=back | |
=head1 STYLE | |
The format of Blosxom weblog entries is as simple as can be. The first | |
line in the .txt file is considered the title, the rest the body. | |
Blosxom attempts to sandwiche your blog entries between any head.html and | |
foot.html it may find in your blog directory, otherwise dropping in rather | |
bland bits of required HTML and a largish, uglyish Blosxom header. | |
Entries themselves are rather plain looking by default, but the HTML includes | |
stylesheet hooks (blosxomEntry, blosxomDate, blosxomTitle, blosxomBody, | |
blosxomTime) which you can style to your heart's content using a home-brewed | |
CSS stylesheet. | |
=head1 CHANGES IN 0+2i | |
=over 4 | |
=item Support on the URL-line for by-year, by-month, or by-day view (e.g. /blosxom/2002/apr/01) | |
=item Permalinks (the # thingies after each entry pointing to the permanent location of the entry at hand) to by-day#by-item (e.g. /blosxom/2002/apr/01/fool) | |
=back | |
=head1 ORIGINAL VERSION 0+1i | |
=over 4 | |
=item Everything's new :-) | |
=back | |
=head1 TO DO | |
=over 4 | |
=item Search (aka grep ;-) | |
=item Lightweight RSS consumption and production | |
=back | |
=head1 SEE ALSO | |
Blosxom Home: http://www.oreillynet.com/~rael/lang/perl/blosxom/ | |
Blosxom License: http://www.oreillynet.com/~rael/lang/perl/blosxom/#license | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment