The weird choice of using Lex to present a template effect is because I want to pretend that I am a guru. And gurus often use complicated or even brain damaged tools to fulfil simple and sometime stupid tasks. Of course, if I am a true guru, I'd rather write a similar tool by myself from scratch using LISP or C. But since I am only pretending I am one, so forget about it.
There is a wonderful Debian
package which provides great documentation on standard CSS and HTML
practice. That is
wdg-html-reference package. If you are
serious into HTML 4 and CSS, then you'd better
into that package, and read the documents there. They're easy to
follow. Only remember one thing though, a good understanding on CSS
does NOT mean that you should use every possible effects on your
homepage. A good taste is more important than a good technique. At the
end of this article, I presented some example
files, you could keep them handy when reading through.
I will not duplicate those excellent documentation on HTML and CSS here, and there are many more high quality documents outside on the web and in the bookstore. Even better, you could use your browser's "View Source" menu item to sneak in every webpage that you're interested to learn from. I will provide you one advice though, that is you should keep it simple, keep your homepage simple unless you have a big team of webmasters and webmistress work for you, or you have a lot and a lot of free time to work on your homepage.
Simple does not necessarily mean ugly, sometime simple is considered beauty, expecially when the CSS is available to nearly everyone now. So your best practice (pretending that I am an expert. heh) is to use standard HTML in your content file, and use the HTML tags as logically as you can.
For example, you may want to use
empasize a sentence or a word, DON'T, use
instead. Then use CSS to provide the desired effects. That's the whole
point. And not to forget to appreciate the Mozilla web browser which is nearly
the most standard compliant one out there. (Hint, use it to test your
For example, if we want to present a navigation menu for our webpage, we will have to copy and paste our menu paragraph in HTML into every content file (as mentioned above, we do not have enough priviledges to use any server side facilities.), and what if we want to change the style used for our menu? That's a big nightmare to adjust each webpages for that.
When we want to add an item to our menu, we only need to change
header.js file, then viola, every webpages are
could even ease the task of generating menus by hand too. Go check out
header.js at the end of this article.
Lex is presented in the Debian package
flex. It is a
GNU tool. What lex do is to scan the input file, and whenever a
regular expression is met, execute some C code. So we can use it to
scan our templates then generate the HTML files. Lex could turn your
dull project of maitaining a stupid personal homepage into an exciting
C programming journey. Isn't it wonderful?
Lex is a scanner generator, which means, we use lex to generate our scanner, then using our scanner to scan our template files to generate HTML files. How could lex generate a scanner? It does this by reading a rules file written by us. Basically, we design some set of rules, then using this rules in our content files. And we write a rules file for Lex, then we use lex to read our rules file and generate a scanner, then we use the scanner to scan our content file to get the desired HTML file. And, it's very simple! Gurus R Us!
What makes a rule? A rule is made of two parts. The first part is
a regular expression (regex) similar to that you found in
egrep. The second part is a small
part of C code. Whenever a regex is found met, then the C code will be
executed. The following is a sample rule from our example rules file:
The above code means that, when "header" is appeared in the input file, and some conditions are satisfied, then we will replace it with a big bunch of HTML codes. The corresonding example content file is as the following:
<lex title="home page" description="zhaoway's homepage." /> <lex keywords="zhaoway, personal, homepage, diary, curriculum, vitae, resume" /> <lex here="header" />
When doing the upload, to decide which file on the server needs to
be updated is difficult, and that task should be automated indeed. So
we use Make to do it. The basic idea is to touch a blank
some.html.upload file whenever
some.html is newer than
some.html.upload that means it needs to be uploaded to
the server again. The following
Makefile rule shows that:
%.upload: % lftp -c "open -u \"$(USER),$(PASS)\" $(SITE); put $<" touch $@
Makefile and Lex themselves warrantize lengthy articles. They are very traditional Unix tools for C development. But could be very useful in maintaining webpages. We cannot explore the details of them very carefully. This article is just mean to raise your imagination with these traditional Unix tools.
You could visit my homepage
for the resulted effects. Have fun and good luck!
zhaoway lives in Nanjing, China. He divides his time among his
beautiful girlfriend, his old Pentium computer, and pure
mathematics. He wants to marry now, which means he needs money, ie., a
job. Feel free to help him come into the sweet cage of marriage by
providing him a job opportunity. He would be very thankful! He is also
another volunteer member of the Debian
Copyright © 2002, zhaoway.
Copying license http://www.linuxgazette.net/copying.html
Published in Issue 75 of Linux Gazette, February 2002