Using MoinMoin to Create a Static Website
This is an example of how you can use a "lightweight" wiki to create a website like this, on a server/desktop and then publish it to a remote server.
The setup is as follows:
A wiki @ http://wiki1.localnet/edit - for creating content
A template & overlay - for design
A local website @ http://wiki1.localnet/ - for website inspection
- A remote website - for the public
This example makes 2 sites wiki1.localnet & wiki2.localnet
Installing on debian:
Installing the packages
sudo apt-get install libapache2-mod-wsgi python-moinmoin
Creating an apache config
/etc/apache2/sites-enabled/xxx-wiki.conf -> ../sites-available/wiki.conf:
<VirtualHost *:80>
ServerName wiki1.localnet
ServerAlias wiki2.localnet
UseCanonicalName Off
VirtualDocumentRoot /var/www/wiki/static/%0
DocumentRoot /var/www/wiki
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/wiki/static>
Options None
AllowOverride All
Order allow,deny
Allow from all
Header set Expires "Thu, 19 Nov 1981 08:52:00 GM"
Header set Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
Header set Pragma "no-cache"
</Directory>
# Ugly rewrite hack, to make sure that you cannot follow
# links into the wiki area from the static dump
RewriteEngine On
RewriteCond %{HTTP:Referer} !=""
RewriteCond %{HTTP:Referer} !^https?://[^/]*/edit(/.*)?$
RewriteRule ^/edit(/.*)?$ - [G]
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
ErrorLog ${APACHE_LOG_DIR}/error.log
#
# MoinMoin WSGI configuration
#
# you will invoke your moin wikis like http://servername/public :
WSGIScriptAlias /edit /usr/share/moin/server/moin.wsgi
# create some wsgi daemons - use user/group same as your data_dir:
WSGIDaemonProcess moin user=www-data group=www-data processes=5 threads=10 maximum-requests=1000 umask=0007
# use the daemons we defined above to process requests!
WSGIProcessGroup moin
### Serve static contents (images, javascript, css...) ###
AliasMatch "^/edit/moin_static[0-9]*/applets/FCKeditor/(.*)" "/usr/share/fckeditor/$1"
<Directory "/usr/share/fckeditor/">
Options None
AllowOverride None
</Directory>
# The path to static contents changes (named after moinmoin version).
AliasMatch "^/edit/moin_static[0-9]*/(.*)" "/usr/share/moin/htdocs/$1"
<Directory "/usr/share/moin/htdocs/">
Options -Indexes -FollowSymlinks
AllowOverride None
</Directory>
ScriptAlias /edit/publish /var/www/wiki/upload/publish-moin.py
<Directory /var/www/wiki/upload/publish-moin.py>
SetHandler cgi-script
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>
ScriptAlias /edit/upload /var/www/wiki/upload/upload-moin.py
<Directory /var/www/wiki/upload/upload-moin.py>
SetHandler cgi-script
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>
</VirtualHost>This allows for multiple wikis, if the hostname can be found.
so create en entry in /etc/hosts:
127.0.0.1 localhost wiki1.localnet wiki2.localnet
So that they can be found, and create the directories where the wiki content resides
sudo mkdir -p /var/www/wiki/{wiki1.localnet,wiki2.localnet}/data/pages
sudo cp -a /usr/share/moin/data/plugin /var/www/wiki/wiki1.localnet/data/
sudo cp -a /usr/share/moin/data/plugin /var/www/wiki/wiki2.localnet/data/
sudo cp -a /usr/share/moin/underlay /var/www/wiki/
sudo chown -R www-data:www-data /var/www/wiki//etc/moin/farmconfig.py
wikis = [
# wikiname, url regular expression
# ---------------------------------------------------------------
("wiki1", r"^https?://wiki1\.localnet/.*$"),
("wiki2", r"^https?://wiki2\.localnet/.*$"),
...
class FarmConfig(multiconfig.DefaultConfig):
...
url_prefix_static = '/edit' + url_prefix_static
...
data_underlay_dir = "/var/www/wiki/underlay/"/etc/moin/wiki1.py (/etc/moin/wiki2.py is almost the same, with quite obvious changes)
# -*- coding: utf-8 -*-
# IMPORTANT! This encoding (charset) setting MUST be correct! If you live in a
# western country and you don't know that you use utf-8, you probably want to
# use iso-8859-1 (or some other iso charset). If you use utf-8 (a Unicode
# encoding) you MUST use: coding: utf-8
# That setting must match the encoding your editor uses when you modify the
# settings below. If it does not, special non-ASCII chars will be wrong.
"""
This is a sample config for a wiki that is part of a wiki farm and uses
farmconfig for common stuff. Here we define what has to be different from
the farm's common settings.
"""
# we import the FarmConfig class for common defaults of our wikis:
from farmconfig import FarmConfig
# now we subclass that config (inherit from it) and change what's different:
class Config(FarmConfig):
# basic options (you normally need to change these)
sitename = u'Wiki1' # [Unicode]
interwikiname = u'Wiki1' # [Unicode]
# name of entry page / front page [Unicode], choose one of those:
# a) if most wiki content is in a single language
page_front_page = u"Index"
# b) if wiki content is maintained in many languages
#page_front_page = u"FrontPage"
data_dir = '/var/www/wiki/wiki1/data/'
template_dir = data_dir+'../template'
publish_cmd = 'rsync --archive --verbose --delete . /var/www/wiki/static/wiki1.localnet/'
upload_cmd = 'rsync --rsh="ssh -i '+upload_dir+'/id_rsa" --archive --verbose --delete /var/www/wiki/static/wiki1.localnet/ user@server.tld:'Everything is set up, and you only need to restart the webserver:
/etc/init.d/apache2 restart
and you should be able to point your browser at http://wiki1.localnet/ and start entering content for your website.
Creating a Static Website
My approach is dumping a snapshot of the wiki, wrapping all content in a template, and adding an overlay of stylesheets and graphics needed by the template.
For this you need a upload data structure that looks like this:
- template.html - the major design of the site
- underlay/ - files that should be handled as files dumped from the wiki (special content, does not get id-attributes and script-tabs wiped)
- overlay/ - files added to the site (.png .jpg .css .js aso)
- id_rsa - ssh key for rsync uploading
Directories for template:
sudo mkdir -p /var/www/wiki/{wiki1,wiki2}/template/{underlay,overlay}
sudo chown -R `id -un`:`id -gn` /var/www/wiki/{wiki1,wiki2}/template/the format of the template.html
<html>
<head><title> - my home</title></head>
<body>
<div class="menu" id="menu:Menu.html"></div>
<div id=":"></div>
</body>
</html>- the "menu:Menu.html" id-attribute - includes the content of Menu.html into the div on every page, and removes the Menu.html from the published website
- the ":" id-attribute is where the content of every published page is inserted
- If a title tag exists, the content of it is prepended with the content of the first "Heading 1" aka. the title of the page
Directories for publishing local:
sudo mkdir -p /var/www/wiki/static/{wiki1.localnet,wiki2.localnet}
sudo chown -R www-data:www-data /var/www/staticAdding this to [settings] [preferences] [Quick links] in your wiki:
[[publish|* Publish (local)]] [[upload|* Upload]]
Or if you don't want to add users you can add the 2 entries to /etc/moin/farmconfig.py under navi_bar
will add a couple of shortcuts, that allows you to publish to your local site, and upload (the published) to your remote site.
Last but not least,
Download publish-moin.py and upload-moin.py, then:
mv publish-moin.py upload-moin.py /var/www/wiki/upload/ chmod +x /var/www/wiki/upload/publish-moin.py /var/www/wiki/upload/upload-moin.py
This is ready to go... however, you need a .htaccess file in the "template/overlay/" directory telling which page is your frontpage. The file should contain somthing like this:
DirectoryIndex Home.html
If you call your frontpage "Home".
Uploading with rsync & SSH
Create a ssh key in the template directory
ssh-keygen -t rsa -f /var/www/wiki/wiki1/template/id_rsa sudo chown www-data:www-data /var/www/wiki/wiki1/template/id_rsa
get the public part of the key
cat /var/www/wiki/wiki1/template/id_rsa.pub
gives ssh-rsa Base64KeyKEykEykEYkeYkeyKEY... user@host
As user "publish" on a remote add the following to .ssh/authorized_keys:
command="rsync --server -vlogDtpre.iLsf --delete /var/www/mysite-documentroot",no-agent-forwarding,no-port-forwarding,no-pty,no-user-rc,no-X11-forwarding ssh-rsa Base64KeyKEykEykEYkeYkeyKEY... user@host
This will make sure that when you connect to publish@server the command "rsync --server -vlogDtpre.iLsf --delete /var/www/mysite-documentroot" will be run. This matches the "rsync --archive --delete . publish@server:" but will force destination to be publish@server:/var/www/mysite-documentroot.
Create a .ssh directory for the www-data user, and ssh as the www-data user to your publish host, in order to save the server fingerprint
mkdir ~www-data/.ssh chown www-data:www-data su - www-data ssh host
And you're ready to go.