Given a full absolute file name, as /home/users/foo/html/index.html, you can take the number of slashes as an indication of file's depth in directory tree. This function returns a string consisting in a number of ../ sequences given by the difference between the depth of the output file and depth of site's root directory. In other words, this is the number of directories traveled to reach the generated file from the root directory.
You can provide site's root directory by the mean of -r or -root-dir options; otherwise Cows will use the launching directory. This default behavior is the right one if you use Cows-mkgen and Make to manage your site.
Suppose to place the following lines in file /home/httpd/htdocs/tools/header.cws:
// FILE: /home/httpd/htdocs/tools/header.cws echo ("<img src=\"" + linkadjust () + "images/logo.jpg\">"); echo ("<a href=\"" + linkadjust () + "index.html\">Home</a>");
Now, include this file from /home/httpd/htdocs/index.cws:
// FILE: /home/httpd/htdocs/index.cws <cows include ("tools/header.cws"); />
If you run Cows in order to create output file within the same directory:
cows index.cws index.html
its output will be:
<img src="images/logo.jpg"> <a href="index.html">Home</a>
Since the output file is in the root directory, they have the same depth in the directory tree and no ../ sequences have been added. Please note that you must run Cows from site's root directory, or use the -root-dir (or -r) option in order for Cows to get its bearings.
Now, include the same file from /home/httpd/htdocs/docs/pdf/pdf.cws:
// FILE: /home/httpd/htdocs/docs/pdf/pdf.cws include ("../../tools/header.cws");
Cows' output will be:
<img src="../../images/logo.jpg"> <a href="../../index.html">Home</a>
In practice, linkadjust ()
returned the string ../../ because output file /home/httpd/htdocs/docs/pdf/pdf.html is two directories below
site's root directory. Again, you must run Cows from site's root directory, or use the
-root-dir (or -r) option in order for
Cows to get its bearings.
This manual can be downloaded from http://www.g-cows.org/.