19.3 Displaying Last Modify Dates

An important issue must be taken into account when inserting last modify dates: should we use the date of the source file (e.g. fdate ("foo.cws", "#D, #d #M #y")) or the date of creation of the output one (e.g. date ("#D, #d #M #y")) ? Both choices have advantages and disadvantages.

The most significant date is the one referring to output file: every time the file is generated, the date changes. However, a small change in site's layout would change dates on every page.

So, you may consider to use the date of source file: even if the corresponding HTML file is recreated, last modify date will change only if the source has been changed. This is a good way to reflect changes in contents, rather than changes in layout.

However, this approach has some problems, too: suppose a page (let's say index.cws) shows both its last modify date and the modify dates of some other pages (let's say foo.cws and bar.cws. All pages are created on December 01; same days later, on December 15, you modify foo.cws and run Make: foo.html and index.html will be updated.

Since index.cws has not been changed, index.html will display something like Last Revision: December 01, but will also say that foo.html has been updated on December 15. Your users will probably wonder how can a page updated on December 01 refer to something happened 15 day later !

A possible compromise could be: refer to source files except when this could lead to meaningless situations as in the example above.

This is an example from G-Cows sources: every page belongs to a given section and a given subsection. Every section has an introductory page listing its subsections and displaying their date of last revision.

These introductory pages are easy to recognize since the variable storing the section label is not empty while the variable storing the subsection label is. The following code, included from every page use this indication to displays the date of last modify related to generated HTML file or to source.

if ((section) && (! subsection))
  print (date (date_rev));
else
  print (fdate (inputfile ("../"), date_rev));

Date_rev is defined earlier in the script:

date_format = "#M #d, #y";
date_rev = "Last revision: " + date_format;

Another way to achieve the same result is to include the script with a parameter telling it which date has to be displayed:

format =  "#M #d, #y";
if (argv[1] == "html")
  modified = fdate(input_file (), format);
elif  (argv[1] == "src")
  modified = date(format);
else
  raiseerror ("Only `html' and `src' supported");
print (modified);

This script can be included with a line like this:

include ("footer.cws", "html");

This manual can be downloaded from http://www.g-cows.org/.