If you often update your site's contents you'll probably want your users to know it. Also - if you're managing a very large site - your habitual users will probably like to browse it quickly and dwell upon lately modified pages.
This section will teach you
the echo ()
function (complete reference: Section 14.1);
the print ()
function (complete reference: Section 14.2);
the date ()
function (complete reference: Section 19.1);
the include ()
function (complete reference: Section 17.2.1);
Updating a Makefile once dependencies changes.
The sources described in this section can be found inside directory tutorial-3 in the examples archive downloadable from http://www.g-cows.org/.
First, let's replace the footer with a small Cows script displaying the last modify date. The new footer will have a .cws extension since it's not an HTML file anymore but a Cows-script.
File lib/footer.cws:
<cows> print ("<hr>"); print (date ("Updated: #d #M #y")); echo (" [ <a href='mailto:webmaster@your-domain'>"); print ("webmaster@your-domain</a> ]"); </cows>
We've just introduced some new Cows functions: both print
()
and echo ()
display a string. The only difference
is that the former adds an end-of-line at the end of the string.
Another new function is date ()
; it returns a string
representing the current date according to the format described by a format string passed
as an argument. Strictly speaking, it simply returns the format string interpreting some
special sequences; we used #d, #M and
#y. They expands respectively to the day of month (1..31), the
full month name (January..December) and the current year (2006..).
Now, we have to modify every page including lib/footer.cws; only vivisection.cws is reported:
File vivisection.cws:
<html> <head><title>Vivisection</title></head> <body> <cows verbatim ("lib/header_html"); /> <h1>Vivisection</h1> <p align="right"> Atrocities are not less atrocities when they occur in<br> laboratories and are called medical research.<br> <em>-- George Bernard Shaw</em> </p> <cows include ("lib/footer.cws"); /> </body> </html>
Please note that footer is now included by the mean of include
()
function instead of verbatim ()
. While the former
allows to include a verbatim copy of an external file, the latter is used to include and
interpret a script.
You may be thinking "If I have to change all the files including the header, what is G-Cows good for?". The answer is that we had to change all files because of a change in site architecture: the header is no longer an html file, but a script. However, now we can modify header.cws again and again and leave the other files untouched.
Replacement of lib/footer_html with lib/footer.cws results in new updating rules so we have to create a new Makefile (with Cows-mkgen) before running Make in order to update the site.
The makefile created by Cows-mkgen allows to remove all generated files with the command make clean. It's a good practice cleaning your site's directory tree before creating a new makefile. Suppose you remove source foo.cws from your project: the new makefile won't know nothing about the target foo.html so this file will never be removed unless you do it by hand.
This is not our case: we are not removing any file from the project, but I think it's better to keep it as a safe habit.
$ make clean rm -f entertainment.html\ vivisection.html\ furs.html\ hunting.html\ index.html\ vegetarianism.html\ $ cows-mkgen $ make cows lib/footer.cws lib/footer.html cows entertainment.cws entertainment.html cows vivisection.cws vivisection.html cows furs.cws furs.html cows hunting.cws hunting.html cows index.cws index.html cows vegetarianism.cws vegetarianism.html
OK, so we just cleaned our project (make clean), created a new Makefile (cows-mkgen) and recreated the site (make). Let's check one of the files with Lynx:
File furs.html:
[ Home (Animal Rights) | Vegetarianism | Vivisection | Hunting | Furs & Leather | Animals in Entertainment ] _______________________________________________________ Furs & Leather I haven't bought any leather articles for a very long time. My ideal is to be able to avoid all animal products, in food as well as clothing. -- Martina Navratilova _______________________________________________________ Updated: 5 July 2004 [ webmaster@your-domain ]
One last thing before jumping to the next step: if you look at the output of the make command, you can see that footer.cws has been processed by cows and file footer.html has been created. Our footer is a script intended to be included from other pages, so it's useless processing it.
However, Cows-mkgen, when creating Makefiles, can't understand the difference between - let's say - vivisection.cws and footer.cws. So we have to tell it that footer.cws is a special file, which doesn't need a corresponding output file. We can do so by inserting the __NO_OUTPUT__ keyword within a comment.
Cows won't see this keyword (Cows don't need to know about these details) but Cows-mkgen will: the generated Makefile will won't include footer.cws in the list of files to be directly processed by Cows.
Please notice that creating a footer.html is useless but armless in this case (you'll only have a useless HTML file). Other times, a script can rely on external variables so processing it by itself will result in meaningless warning messages or in error messages that will stop the update procedure (Make stops when one of the launched commands exits with an error).
Follows, the modified version of footer.cws, which can be found within directory tutorial-3b.
File footer.html:
<cows> // __NO_OUTPUT__ print ("<hr>"); print (date ("Updated: #d #M #y")); echo (" [ <a href='mailto:webmaster@your-domain'>"); print ("webmaster@your-domain</a> ]"); </cows>
This manual can be downloaded from http://www.g-cows.org/.