reStructWeb
By castlebbs on Thursday 12 April 2007, 19:26 - Development - Permalink
reStructWeb is a small piece of software written in Python language. I wrote it to manage my personal web site. The most important features that I wished when I decided to write it are :
- To be able to simply modify my website online
- Not to have to write my pages in html or xml
- To create links between the pages very easily (like Wiki )
- To integrate templates and css to separate the presentation from the contents
- To be multi-lingual
- To be powerful and light for my poor computer ( SiteAbout ).
I took as a starting point the the Wiki system to update my Web site. The pages are created in text format using thereStructuredText format.
reStructWeb is based on the following tools:
At present reStructWeb makes hardly more than 300 lines of code. Largest of work (the management of the reStructuredText format) is made by Docutils.
reStructWeb was tested on the following environments :
- Red Hat 9
- Red Hat 8.0
- Debian Sarge
- Python 2.2.2, 2.2.3, 2.3.3
- apache 2.0.40
- docutils snapshot téléchargé le 2 mai 2004
The program should work on any system supporting Python 2.2 (or more) and docutils
Principle and performances
The system used is very powerful. The majority of time, the pages are sent to the navigator directly by Apache (static pages). Two cases of figures will lead Apache to return the request on reStructWeb script:
- The URL required does not exist
- The URL required contains parameters
reStructWeb script will ask you to create a page in case it don't exist or will ask you for the modification of an existing page. It generates thereafter html pages in the various languages and Apache will be able to send them in a traditional way.
Apache requires a small configuration to redirect the requests towards reStructWeb. You can however configure to use reStructWeb in a traditional way like a cgi, for example:
With Apache settings
http://www.test.com/index.html.en
Without Apache setting
http://www.test.com/rstweb.cgi/index.html.en
reStructWeb is a small script which I wrote for my needs only. It was not thought and not designed at all for a system having to be managed by several people. There is no management of users, no modifications history and the safety options are non-existent : The permission of modification of the site is based on a single password, the magicWord: -)
Attention!
Do not let anonymous users modify the contents of your website. reStructWeb is not a Wiki. An badly-attentive user can divert the use of the reStructuredText to try to compromise the system. Example :
.. include:: /etc/passwd
It is thus possible to include the contents in the page of any file on the system (for which the user of apache as the rights for reading).
This said, it is very fast 1 , very light, very simple to implement (a single file and four parameters)
| [1] | It is not the reStructWeb script which is fast, but the Apache sending of static pages. What is practically always the case on my site. |
Download
- Version 0.2 - magicword is now used when you want to create a link : download
Configuration
Standalone mode
In this mode, there is no Apache configuration. You only need to to copy the script in the directory cgi-bin.
- Install docutils, Download reStructWeb
- Copy the file rstgen.py in cgi-bin directory
- Modify if you need the parameters in rstgen.py
- Create the reStructWeb working directory
- Change the directory permissions (the user running apache must be able to modify and create files in this directory)
- Copy the templates files in the working directory: default.tmpl.fr, default.tmpl.en
- Test
Apache redirect mode
proceed as for the standalone mode and to configure Apache in the following way :
Script GET /cgi-bin/rstgen.py
Script POST /cgi-bin/rstgen.py
ErrorDocument 404 /cgi-bin/rstgen.py
My configuration
On my computer, the working directory is /home/web/david/pages, rstgen.py is copied in the/home/web/david/cgi-bin directory.
Here is my Apache configuration :
<Directory "/home/web/david/pages">
Options FollowSymLinks MultiViews +Includes
Script GET /drobert/admin
Script POST /drobert/admin
ErrorDocument 404 /drobert/admin
AddDefaultCharset UTF-8
</Directory>
<Directory "/home/web/david/pages/st">
Options Indexes FollowSymLinks MultiViews +Includes
AddDefaultCharset ISO-8859-1
</Directory>
<VirtualHost *>
ServerAdmin webmaster@ombrepixel.com
DocumentRoot /var/www/ombrepixel.com
ServerName www.ombrepixel.com
ServerAlias ombrepixel.com
ErrorLog logs/www.ombrepixel.com-error_log
CustomLog logs/www.ombrepixel.com-access_log combined
ScriptAlias /drobert/admin /home/web/david/cgi-bin/rstgen.py
Alias /drobert /home/web/david/pages/
</VirtualHost>
Templates
About
The appearance of each page can be completely customized because the system uses templates. It is completely possible to make a really nice website by using reStructWeb (not like this one).
The templates are files with the .tmpl extension located in the working directory. You need a default template for each language your website support, thus,on my site, two files are present on the working directory :
- default.tmpl.fr
- default.tmpl.en
They are the default templates for all the pages, in French and English.
You can create templates specific to each page with the filename page_name.tmpl.en. For example if I want a customized template for the reStructWeb page, you just have to create the files restructweb.tmpl.en and restructweb.tmpl.fr``.
Templates variables
The template file is a pure html file in which a certain number of variables are replaced by dynamic contents. Currently, reStructWeb makes it possible to use the following variables :
| Variables | Replaced by |
|---|---|
| $title | Title 2 of the page |
| $body | Body of the page |
| $sourceUrl | Page source url |
| $editUrl | Page edit url |
| $enUrl | English version url |
| $frUrl | French version url |
| $lastModified | Last modified date |
| [2] | Title is defined in the reStructuredText (name of first section) |
Bugs / To make
- I noticed that under IE by making http://www.ombrepixel.com/drobert/restructweb one arrives directly on document RST and not HTML
- Dictionary
- Need to create dynamic language url variable
Other projects
- Ian Bicking reST wiki : http://wiki.webwareforpython.org/thiswiki
