bkmrkconv - Convert Mozilla's bookmarks.html to HTML ~~~~~~~~~ (c) Andrew Flegg 1999, 2006 mailto:andrew@bleb.org v1.12 (12-Nov-2006) http://www.bleb.org/software/bkmrkconv/ Licence ------- This program and all its associated files have been released under the Open Source[TM] Artistic Licence, for further details and a full copy of the text please see the following URL. By using this product you are implicitly agreeing to the terms of this agreement. http://www.opensource.org/licenses/artistic-license.html Introduction ------------ This Perl program will convert a Netscape/Mozilla/Firefox etc. bookmarks.html file into a series of separate pages useful for placing on the external web. Usage ----- Simply modify the first line of bkmrkconv.pl to wherever your Perl executable lives (usually either /usr/local/bin/perl or /usr/bin/perl - failing that try 'which perl' or refer to your User's Guide). The command line syntax is: bkmrkconv [OPTION]... -h, --help list the command line options -n, --nocontents do not create a contents.html -s, --onlysections contents page will list the sections rather than each individual link -f, --file FILE read input from FILE rather than stdin -d, --dir OUTPUTDIR read templates from OUTPUTDIR/src and output HTML files to here. [Default: .] -t, --sort sort the output alphabetically All links are output (if the template has a ... section (see later). However, if they contain a '(P)' they will be skipped. Sections containing a '(P)' are skipped entirely. Configuration ------------- Three files are used for configuration all in OUTPUTDIR/src/: rootpage.html Template for OUTPUTDIR/index.html, the frontpage for your site. linkspage.html Generated for every folder in the bookmarks file, this forms the basis of most pages in the output. contentspage.html OUTPUTDIR/contents.html contains every link in alphabetical order, or just every section if --onlysections is specified. Two examples are included, src.example and src.aflegg. The latter contains the templates I use to generate my own bookmarks site at: http://www.eh.org/~jaffa/bookmarks/ The former contains simpler templates which show that the pages don't necessarily have to look like Yahoo's. You need a 'src' directory in your output directory which can be based on one of these if you so wish. However, it is recommended to "roll your own" to develop a distinctive style for your site. Macros ------ The templates are normal HTML files but some special strings when the pages are created. All templates ~~~~~~~~~~~~~ $DATE The current date and time in the form returned by 'scalar localtime()'; eg. (on this system): Wed Dec 15 20:05:55 1999. Text between the double quotes is passed out using the Perl backtick operator and the results of the command inserted into the file, eg. each page could contain a cookie from the fortune command. Include the specified file into this template and continue. The current directory for the file is the output directory. Macros are expanded, and you can even use more INCLUDEs! eg. Section templates (rootpage.html and linkspage.html) ~~~~~~~~~~~~~~~~~ $TITLE The name of the current section. $PATH A colon separated of the sections about this one, eg. "Root : Misc." $PATHURL As $PATH but each of the sections is a hyperlink to that section's page. "cond" is evaluated as a Perl expression and if ... it evaluates to true the first block is [] placed into the text; if not, the second, optional ... block is used instead. Two variables which may be of use here are '$numSections' and '$numLinks' which contain the number of sections and the number of links on the current page respectively. Repeat this section for every subsection in this ... page. Repeat this block for every link in this section. ... $URL The URL of whatever is currently being replaced, either a relative URL for a new section or an absolute URL from the bookmarks file for a link. $NAME The text describing the above URL, either a section name or link title. $NUMSECTIONS Within a block returns the number of links contained within the subsection currently being processed. $NEXT Within a block this will contain the next two links (and an ellipsis if appropriate). $DESC Inside a link this contains the description field for that link, if defined. This must be used within a ... block within the section. Currently only the first line of the description is used. Contents template (contentspage.html) ~~~~~~~~~~~~~~~~~ A section exists for [A-Z] and a symbol category. ... A block is inserted for each link. ... ... $PREFIX The first letter of the section being currently generated. $SECTION Of the form ..., this contains a link to the section this link came from. Tables ------ Two column tables are produced if there is a tag within 16 characters of the tag. This will insert and tags as appropriate. This also applies with LINKs as well. Testing ------- The program has been successfully run on RedHat Linux 5.2 with Perl 5.00404, Windows 98 with Perl 5.00307 and Solaris 7 with Perl 5.00505. Limitations ----------- Each section must have its own page - ie. you can't generate a whole page of all the links. This is a design decision rather than a limitation (IMHO)... Thanks ------ Thanks to: * David S. Cargo for suggesting the contents page, private links and INCLUDE. * Paul Leclerc for the description line. * Kurt Hindenburg for better handling of Firefox's bookmarks.html, sorting and better handling of Safari's format. * Luca Corti for XHTML-compliance suggestions. Data Structure -------------- The following Perl fragment demonstrates the internal format of the bookmarks - mainly documentation for documentation's sake ;-)... %root = ( name => 'My bookmarks', url => 'index.html', sections => [ { name => 'Misc.', url => 'root_misc.html', links => [ { name => 'Slashdot', desc => 'News For Nerds. Stuff that Matters.' url => 'http://slashdot.org/index.pl', }, ], }, { name => 'Other...', url => 'root_other.html', links => [ { name => 'The Register', url => 'http://www.theregister.co.uk/', }, ], }, ], links => [ { name => 'Home', url => 'http://www.eh.org/~jaffa/', }, { name => 'Jaffa Software', url => 'http://www.jaffasoft.co.uk/', }, ], );