#!/usr/bin/gawk -f # # pak-web-site -- 2008-08-17, last edit 2008-09-20 # # script to convert shtml web pages to static version with optional # compression # # Copyright (C) 2008 Grant Coady GPLv2 # # Home site: http://bugsplatter.id.au/pakweb/ # #-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # merge ssi files / values # ````````````````````````` # SSI (Server Side Include) directives to be replaced by their source # are discovered at runtime. # # SSI directives to be replaced by value: # # # special action: # panel.html's menu list requires special action to replace the SSI # conditional directives that control the CSS menu highlighting marker # # 1. when reading panel.html, strip the conditionals, leaving the
  • # tag as the usual option # # 2. when rewriting html pages, check for the menu highlight select: # $/ { ++ssi_read; next } # must have non-empty lines for page rewriter (junkdata needs this) !targets && /^$/ { $0 = " " } # menu: remove conditional menu ssi directives part1 !targets && /
  • / { sub(/
  • /, "
  • ") } # store ssi include file contents for page rewriter !targets && ssi_read { ssi_data[ssi_file_ndx[FILENAME],++rec_num] = $0; next } #-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # process html files # ``````````````````` # in case we get wildcard, ignore non-html files FILENAME !~ /\.html$/ { ++skipfile; nextfile } # no post-process on entry, post-process the file read on prior pass FNR == 1 && targetcount { post_process() } # setup rewriter for this pass FNR == 1 { ++targetcount if (debug) { print "read " FILENAME } else { # magical eye guide dash writer fluffy bit s = FILENAME " " if (targetcount % 2 == 1) { while (length(s) % 8) { s = s " " } while (length(s) < 57) { s = s "- " } sub(/[ ]+$/, "", s) } printf " %-63s", s } thisfile = FILENAME tempfile = thisfile ".temp" gzipfile = thisfile ".gz" footlink = make_footer_links(thisfile) menupage = ""; shrinkme = ssimerge = pre_flag = skipfile = 0 if (system("[ -x " thisfile " ]") == 0 && \ thisfile !~ /README\.html$/) { ++shrinkme } } # skip marked ssi include files FNR == 1 && /^$/ { ++skipfile; nextfile } # allow
     tag in front of ssi directive for formatting
    /^
    / {
    	++ssimerge
    	if (pre_flag) { pre_flag = 0; printf "%s", "
    " > tempfile }
    	sub(//, footlink)
    	print > tempfile
    	next
    }
    # menu: extract menu highlight page name				part2
    #  
    //, "")
    	menupage = ">" $1 ""
    	next
    }
    # replace known ssi directives with their ssi source file contents, 
    #  assumes no trailing content after the ssi include directive
    ($0 in ssi_incl_ndx) {
    	++ssimerge
    	src = ssi_incl_ndx[$0]
    	if (pre_flag) { pre_flag = 0; printf "%s", "
    " > tempfile }
    	i = 0
    	# this while loop requires non-empty ssi replacement lines
    	while (ssi_data[src,++i]) {
    
    		# menu: mark menu page for highlighting			part3
    		if (menupage) {
    			s = ssi_data[src,i]
    			if (s ~ menupage) {
    				sub(/
  • /, "
  • ", s) menupage = "" } print s > tempfile } else { print ssi_data[src,i] > tempfile } } ++ssi_this[ssi_filename[src]] next } # if find unrecognised SSI directive disable compression /