Sources described in this section and next ones can be found under directory site-03 in the examples archive downloadable from http://www.g-cows.org.
The descriptive name associated to sections can be used as a title for the introductory pages (e.g. vegetarianism/index.html). For each subsection (e.g. vegetarianism/health.html) we need both a short name and a long one. The long name will be self-explaining (e.g. How a vegetarian diet can improve your health) and will be used as a title. The short name is intended to represent the subsection respect to the section (Your Health as an example is meaningful if used close to its parent section Vegetarianism, as an example in submenu and history stack (Home > Vegetarianism > Your Health).
In general, it's a good idea to keep per-pages informations (title, content, quotation etc.) within single source files. Information needed by more than one page must go into common files included by other pages; as an example, we need informations about site structure in order to create navigation bars so section labels and names must be placed in a file included everywhere.
According to this principle, titles should be placed within pages. However, later in the tutorial, we are going to create a site map, so a single file will need all titles. As a consequence of this, let's place them in lib/structure.cws.
site.vegetarianism_sub [ ] = { { "suffering", "Animal suffering", "Animal suffering behind meat" }, { "health", "Your Health", "How a vegetarian diet can improve your health" }, { "hunger", "World Hunger", "Correlation between meat eating and world hunger." }, { "act", "What You Can Do", "Vegetarianism: what you can do" } };
Now, we have to build titles for each page. Let's add the new code at the bottom of file lib/menus.cws:
// Page Title if (n_tokens == 1) { // This is the Home Page site.title = "Animal Rights Site"; } elif (current_subsec == "index") { // This is an introductory page. foreach (section [ ] in site.sections [ ]) { if (section [0] == current_section) { site.title = section [1]; // The SHORT name is used } } } else { // This is an internal page foreach (subsec [ ] in subsections [ ]) { if (subsec [0] == current_subsec) { site.title = subsec [2]; // The LONG name is used } } } term (site.title);
The last line is a debugging function: content of variable site.title
will be displayed on the console.
$ make cows index.cws index.html Animal Rights Site cows vegetarianism/suffering.cws vegetarianism/suffering.html Animal suffering behind meat cows vegetarianism/health.cws vegetarianism/health.html How a vegetarian diet can improve your health cows vegetarianism/hunger.cws vegetarianism/hunger.html Correlation between meat eating and world hunger. cows vegetarianism/index.cws vegetarianism/index.html Vegetarianism cows vegetarianism/act.cws vegetarianism/act.html Vegetarianism: what you can do
As you can see from debugging strings, titles are correct so we can remove the debugging line. Now, we have to add title to the template.
Title is displayed on the browser window (<title>...</title>) and within the page (<h1>...</h1>). When users bookmarks a page, the former is used as a label so it's a good idea to prefix it with site name.
So let's edit lib/template.cws and replace:
<title>Title</title>
with:
<title>Animal Rights -- @@ site.title @@</title>
and:
<h1 align="right">Title</h1>
with:
<h1 align="right">@@ site.title @@</h1>
This manual can be downloaded from http://www.g-cows.org/.