Newsgroups: best.www Subject: Inserting header/footer without #include (server-parsed-html) Summary: Expires: References: <642t07$8im$1@nntp1.ba.best.com> <65v196$g4n$1@shell3.ba.best.com> <65vln3$aru$1@nntp1.ba.best.com> <660g2s$mkd$1@nntp1.ba.best.com> Sender: Followup-To: Distribution: best Organization: Chez INWAP (people, computers, cats) Keywords: Cc: In article <660g2s$mkd$1@nntp1.ba.best.com>, wrote: >> At the risk of seeming simplistic, *why*? >If it's parsed, then the server has to search through it. This step is >probably 20-30x slower than straight html. > >Save the program at the end of this message as "preparse", ... >Of course, I haven't really tested this program, and it's pretty incomplete. >After reading this, wait 24 hours and check again for a followup from >Joe Smith, who will post a version of this program that is two lines >long, including the "#!/..." header. ;-) Sorry to disappoint you, Paul, it took 123 lines. :-) But that's because I took your idea and improved on it. 1) Eliminate the need for a separate template file, 2) Do variable substitution on the replacement text (like a macro). It is now available in http://www.inwap.com/mybin/ . -Joe (home/inwap) inwap@shell3% html-include usage: /home/inwap/mybin/html-include include_dir $HOME/public_html where 'include_dir' is the directory containing the files to be included and '$HOME/public_html' is the directory with HTML files to be updated. For each *.html file, this program looks for lines like this: several lines that will be replaced with contents of include_dir/footer Each file that has any changes will be renamed to have a *.bak extension. The names of these *.bak files are sent to STDOUT so that they can be deleted if there are no errors. (home/inwap) inwap@shell3% cat includes/footer
Maintained by js-cgi at inwap.com
(home/inwap) inwap@shell3% cat public_html/02.html This line of text is before the footer These lines of text get replaced by executing html-include. This line of text is after the footer (home/inwap) inwap@shell3% html-include includes public_html/02.html public_html/02.html - 1 change public_html/02.html.bak (home/inwap) inwap@shell3% cat public_html/02.html This line of text is before the footer
Maintained by js-cgi@inwap.com
This line of text is after the footer (home/inwap) inwap@shell3% html-include includes public_html/02.html public_html/02.html - 0 changes ==================================================================== The section of the HTML file that needs to be updated is bracketed by and and all the text between the two will be replaced by the contents of the specified file, after doing variable substitution. Since the start and end tags are preserved, there HTML file is its own template; the output from the html-include script can be used as input to the script later on. The first argument to the html-include script is the name of the directory that has the files to be included. A good choice for this is "$HOME/includes" which will keep the header and footer files in your home directory instead of on the web area. The remaining command-line arguments are names of files and/or directories to process; the script does directories recursively looking for *.html and *.htm files to process. Only files that actually need to be changed are rewritten and their modification dates are incremented by 60 seconds. If you have several levels of subdirectories, then you probably want to create several header and footer files. includes/footer1 - uses includes/footer2 - uses includes/footer3 - uses (Maybe I ought to build that into the program; have it use a single footer file but insert "../" where appropriate. Hmm.) To do all of the files and subdirectories of your web area, use this: html-include includes public_html >temp rm `cat temp` This is only the first cut at this html-include program. Any suggestions? -Joe The html-include.txt file has an example of its use, but you're right, it's not written as a tutorial. I'll have to work on getting a better example written up. 1) Create a directory $HOME/includes . 2) Create two files, $HOME/includes/header and $HOME/includes/footer that have the HTML code that you want to have at the top of the page and at the bottom of the page, respectively. 3) On each file in $HOME/public_html, add two lines near the top and to near the bottom. For example, create test.html with this: the title goes here

This is a test

4) To do just the one file, use this command: html-include $HOME/includes public_html/test.html 5) Later on, when $HOME/includes/header and/or footer are changed, use html-include $HOME/includes public_html and it will locate all the files that need to be changed. -Joe