#!/usr/bin/perl # Created from thin air by abb@acm.org on 6/16/99. # # A little Perl script to process my bookmarks into a loosely # structured file tree. My bookmarks were totally out of control, # impossible to navigate, out of date, and useless IMHO, yet they # continue to receive thousands of hits/month?? Anyway, this makes # it much easier to navigate, by splitting folder levels into # separate files. # # I looked around for a SIMPLE script to do this, but could find none. # My aim here was to whip up something minimal. I mean really minimal, # no frills at all. # I am NOT a Perl wizard, as you can see. I just try to get the job done. # I limited myself to 2 hours work and less than 100 lines of code. # I don't have time for documentation, but IMHO just about anyone # should be able to figure out 100 lines of code for themselves. # # I think this should work on anybody's Netscape bookmarks file. # If it doesn't work for you that's your problem. I don't care. # It works for me. I expect to receive not a single e-mail in reference # to this script. # Understood?!! Am I making myself clear?!! Don't answer that... # (I'm a little stressed by all the morons who try to use my other software.) # # Usage: ./bm2html.pl ~/.netscape/bookmarks.html # Side effect: The script will attempt to create an HTML file for each # folder level in your bookmarks. The deepest folder level in my # bookmarks is 5, so this script creates 5 files for me. # Just give it a try in an empty directory and you'll understand. # (I just went over my 2 hour limit.) @heading = () ; @target = () ; @bmhtml = () ; @filehandle = () ; @filename = () ; $curlev = 0 ; $linkcount = 0 ; $fileprefix = "bm" ; $filename[1] = "index.html" ; $header = qq(
[Andy's Medical Imaging Page] [Andy's Info & Referral Page] [Perl Script to Create This]
) ; ($mday,$mon,$year) = (localtime(time))[3,4,5] ; $mon++ ; # range is 0-11 $year += 1900 ; $update = "$mon/$mday/$year" ; $footer = qq([Andy's Medical Imaging Page] [Andy's Info & Referral Page] [Perl Script to Create This]
Nobody is responsible for anything here. Use it in any way you wish. Or not.$/\1/i ;
s/(/
/ig ) {
$curlev++ ;
#print STDERR "Level $curlev, Heading=$heading[$curlev]\n" ;
$bmhtml[$curlev] = qq(\n) ;
$bmhtml[$curlev] .= "
\n" ;
for (1..($curlev-1)) {
$bmhtml[$curlev] .= qq($heading[$_]->) ;
}
$bmhtml[$curlev] .= "$heading[$curlev]
\n" ;
}
if( !defined($privlev) ) {
if( $line =~ m//LI>/ig ;
$bmhtml[$curlev] .= $line ;
}
if( $line =~ s/<\/dl>/<\/UL>/ig ) {
if( !defined($privlev) ) {
OutputHTML( $curlev ) ;
} else {
if( $curlev == $privlev ) {
# End of private part.
undef( $privlev ) ;
}
}
$bmhtml[$curlev--] = "" ; # just in case I screwed up...
}
}
foreach $fh (@filehandle) {
if( defined( $fh ) ) {
print {$fh} $footer ;
close( $fh ) ;
}
}
print STDERR "Done. I count $linkcount links.\n" ;