![]() |
Perl - Web Site Maintenance
|
|
|
Download the script
Like many people on the Web, you may use an ISP that does not provide server-side includes or scripting support. If so, keeping all the common content in your Web pages updated and in step can be difficult and tiresome. For example, just changing the copyright message or contact details in the footer of the pages can mean having to edit a large number of files. However, by writing some fairly simple Perl to pre-process your Web pages, some of these difficulties can be smoothed out. Described here is such a script. build_file.plTo use this script you write template web pages that reference common content. These templates get expanded by the script into the full HTML pages to upload to the Web-site. The script can either expand a single file from a source location to an equivalent destination location, or an entire directory and all the files below. To do the expansion the script reads the template page from the source location, processes it to find include references to other pre-written HTML snippets, or pagelets as I term them, and substitutes the similarly processed snippet content in place of the reference. The final expanded HTML is written to the destination location. The references are just special markup inside normal HTML. During the processing of source directories, any file that does not contain inclusion markup is copied unchanged to the destination. This way it is possible to use the script to point to the top of a web site file structure and have it expanded and copied to the destination without worrying about whether binary files having been corrupted. I have tried this with GIFs, JPGs, Java class files and Zips amongst others with no harmful effect. The script allows for cascading of page inclusions which means that the referenced pages can themselves reference further pages. The pagelet files can be organised into directories of common content because the inclusion reference separates pagelet name and location. Using the inclusion cascading and the directory separation, a manageable hierarchy of simple pagelets can then be created and knitted together for final use in the templates. Also, in order that context sensitive information can be passed down to the included pagelets, the markup syntax allows for parameters to be given in the inclusion reference. Inclusion SyntaxThe simplest inclusion request looks like this:
%%pagelets::copyright%% A more complex, parameterised request might look like this:
%%pagelets::titlebarhead(DIR='../',TITLE='A page about PERL')%%
<a href="%%DIR%%index.html">link</a> Example pageletI have made extensive use of this script in writing this Web site which is constructed entirely from template and pagelet files. For example the "next page" image links are generated using the pagelet shown below.
<a HREF="%%URL%%"><IMG SRC="%%DIR%%images/next_page.gif" WIDTH=26 HEIGHT=26 ALT="[Next]" ALIGN=absbottom BORDER=0></a> Script Usagethe script is invoked as shown below.
build_file.pl [ -o ] ( src_dir | src_file ) dest_dir
-o overwrite existing destination files
src_dir source directory to copy and expand
src_file source file to copy and expand in equivalent
destination location
dest_dir top-level of destination, created if needed
DownloadYou can download a Zip file containing the script and the custom Perl modules it uses from here. |
|
Content of this page Copyright © Robert Quince 1996 - 2005. |