Node:A Trivial Example, Next:, Previous:Synchronizing a Website, Up:Top



A Trivial Example

The advantage that WebPublish has over other website publishers is its ability to call a script or a program just before a file is transferred to a server (see Making Alterations). The script or program can add a time stamp to a file, change a file's <BASE> tag address, include common HTML sections to a webpage, etc.

This chapter will present a trivial example that will demonstrate how you can use WebPublish to develop and maintain a website. This example will create a website in a local directory. The example website will be published by WebPublish to a remote server. When files are transferred to the server, the base address of all html and RealMedia ram files will be changed to work correctly from the server. This development scheme makes it possible to develop a new section for a website locally. The local base address in the html and RealMedia ram files will prevent the additions from contaminating the live website on the server. When the new section is developed, WebPublish can transfer the additions to the server.

In our example, Charles, our website developer, will set up his own personal website. Charles will create and maintain his website in the local directory /mnt/linux/websites/personal. Charles will publish this website to the FTP server <ftp.xanadu2.net>. Publishing the website to <ftp.xanadu2.net> will make the website available to the public over the internet.

First, Charles creates the website directory. Charles also creates a subdirectory that will hold the website's templates. Finally, Charles writes a simple index webpage that explains that the website is under construction. The index webpage contains a local base address (<BASE href="file:/mnt/linux/websites/personal/">).

Here is a directory listing of the new website in the local directory.

[charles@localhost personal]$ ls -Fl
total 8
-rw-r--r--  1 charles  charles      0137 Oct 28 08:16 index.html
drwxr-xr-x  2 charles  charles      4096 Oct 28 08:15 templates/

Next, Charles sets up the WebPublish account that will publish his personal website to the FTP server. In this example, Charles creates a WebPublish account called, personal.

webpublish --add -F account -a personal -w
/mnt/linux/websites/personal -s ftp.xanadu2.net -u charles -p
example

The example above creates the personal WebPublish account. The personal account can be used to publish the website that is located at /mnt/linux/websites/personal to the FTP server <ftp.xanadu2.net>. WebPublish will log into the FTP server using the specified user name (-u) and the password (-p). Here is a listing of the account.

[charles@localhost personal]$ webpublish --list -F account -a
personal
Listing WebPublish account:
Account  : personal
Website  : /mnt/linux/websites/personal
Server   : ftp.xanadu2.net
User     : charles
Password : example
Directory:

After Charles creates the personal WebPublish account, Charles excludes the template directory from being transferred to the server by WebPublish.

webpublish --add -F publish -a personal -P
/mnt/linux/websites/personal/templates

The example above adds the path /mnt/linux/websites/personal/templates to the publish database file. This will cause WebPublish to ignore the template directory when WebPublish is searching for files and directories that need to be transferred to the server while the personal account is being published. Here is the listing of the record.

[charles@localhost personal]$ webpublish --list -F publish -a
personal
Listing local paths for personal:

Path: /mnt/linux/websites/personal/templates

Next, Charles excludes the server directory cgi-bin from being removed by WebPublish when WebPublish synchronizes the account.

webpublish --add -F -synch -a personal -P cgi-bin

The example above will add the path cgi-bin to the synch database file. This will cause WebPublish to ignore the cgi-bin directory when WebPublish is searching for files and directories that need to be removed from the server while the personal account is being synchronized. Here is the listing of the record.

[charles@localhost personal]$ webpublish --list -F synch -a
personal
Listing server paths for personal:

Path: cgi-bin

Next, Charles will associate an alteration program with the html file extension and the RealMedia ram file extension. This will cause the alteration program to be called just before a file with an html extension or a RealMedia ram extension is transferred to the server.

webpublish --add -F shell -a personal -e html -P
/mnt/linux/websites/support/changebase

webpublish --add -F shell -a personal -e ram -P
/mnt/linux/websites/support/changebase

The example above will add two records to the shell database file. The two records associate the html and RealMedia ram file extensions with the program changebase that is located in the directory /mnt/linux/websites/support. This will cause WebPublish to call the changebase program just before a file with an html or RealMedia ram file extension is about to be transferred while the personal account is being published. If the changebase program changes the base address in a file then the altered file will be transferred to the server by WebPublish. Here is a listing of the records.

[charles@localhost personal]$ webpublish --list -F shell -a
personal
Listing shell programs for personal:

Extension: html
Program  : /mnt/linux/websites/support/changebase

Extension: ram
Program  : /mnt/linux/websites/support/changebase

NOTE: Appendix A includes the source code for the changebase program. The program is a simple C++ program that can be used to change the base address of html and RealMedia ram files. The program also demonstrates how to use one program to manage multiple websites.

The last thing that Charles needs to do before he can concentrate fully on the development of the website's content is to make sure that all of the file transfer modes are correct. In our example, Charles needs to make sure that all files with a css extension (the style sheets) are transferred in text mode.

webpublish --add -F mode -e css -m text

The example above will add the css file extension to the mode database file. This will cause WebPublish to transfer all files with a css file extension to the server using text mode. Here is a listing of the record.

[charles@localhost personal]$ webpublish --list -F mode
Listing all file transfer modes:

Extension: css
Mode     : TEXT

Charles is now ready to publish his website to the server for the first time.

webpublish -publish -a personal -V

The example above will publish the personal account. In this case, WebPublish will transfer the file index.html to the server. Since the file has an html extension, WebPublish will call the changebase program just before the file is transferred. The index.html file has a base address of <BASE href="file:/mnt/linux/websites/personal/">. The base address will be changed by the changebase program to <BASE href="charles.padresoftware.com/">. This will cause the base address to work correctly from the server. (The -V FLAG causes WebPublish to write messages to stdout that describe what WebPublish is doing as WebPublish does it.) Since the templates directory is excluded, WebPublish will ignore it.

Charles can now concentrate on developing the content for his new website. Thanks to WebPublish, Charles does not have to spend any more time keeping track of the files and directories that need to be transferred to the server. WebPublish will know when files and directories have been added or changed and only the files and directories that have been added or changed will be transferred to the server.

This development scheme allows Charles to work on his home webpage without contaminating the website that is available to the public on the server.

Charles is really smart for using GNU/Linux and WebPublish.