Chapter 20 Adjusting Links

Table of Contents
20.1 A Common Problem
20.2 Solution
20.3 The linkadjust () Function

20.1 A Common Problem

Suppose your site is split among a number of subdirectories; let's say:

/your-site/

This is site's root directory, every file is here or in subdirectories; as an example /your-site/ can be /home/httpd/htdocs/ on a web server, or /home/username/html/ within a home directory.

/your-site/images/

A subdirectory containing images.

/your-site/tools/

A subdirectory containing Cows scripts to be included from other pages (for displaying common headers, footers, indexes, etc.).

/your-site/docs/

A subdirectory containing pages related to documentation you're hypothetically distributing.

Now, you create a small script displaying an header and place it in /your-site/tools/header.cws:

File /your-site/tools/header.cws:

echo ("<img src=\"../images/logo.jpg\">");
echo ("<a href=\"../index.html\">Home</a>");

Finally, you include this header in every file of your site (as an example /your-site/index.cws and /your-site/docs/docs.cws).

File /your-site/index.cws:

include ("tools/header.cws");

File /your-site/docs/docs.cws:

include ("../tools/header.cws");

This won't work: /your-site/index.html will not display the image and the link will be wrong !

The reason is simple: while creating /your-site/index.html, the output file /your-site/index.html and the included file /your-site/tools/header.cws have different depths in the directory tree. Image logo.gif is seen as images/logo.gif from /your-site/index.html but is seen as ../images/logo.gif from /your-site/tools/header.cws.

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