Hari's Corner
Humour, comics, tech, law, software, reviews, essays, articles and HOWTOs intermingled with random philosophy now and thenWebsite generation using asciidoc
Filed under:
Tutorials and HOWTOs by
Hari
Posted on Tue, Jul 3, 2007 at 10:41 IST (last updated: Wed, Oct 1, 2008 @ 22:10 IST)
- You need to have asciidoc and python installed on your system.
- Save the script below as
website-gen.py
and make it executable (usingchmod +x website-gen.py
from the command line). - Customize the source and destination directory in the script to your needs.
- Create the asciidoc sources in the source directory tree.
- Create a
layout.conf
file (optional) or remove the-f layoutfile
option from the script to use default settings. - Run the script to generate the output in XHTML 1.1 format in the destination directory tree.
- For more information on asciidoc, you can read the man page and the full online documentation.
#!/usr/bin/env python import os # The source directory containing the asciidoc .txt files # (you can modify this to your needs) source_dir = './source/' # The destination directory # (you can modify this to your needs) dest_dir = './html' # The layout configuration file # (you can use your own layout file. Modify the layout file # to your needs or remove the layout_file = './layout.conf' # Run through the source directory and compile the asciidoc files for root, dirs, files in os.walk (source_dir): for file in files: if (file.endswith ('.txt')): fullfilepath = os.path.join (root, file) # Use the commented command to generate with no # custom layout file # command = 'asciidoc ' + fullfilepath command = 'asciidoc -f ' + layout_file + ' ' + fullfilepath os.system (command) print fullfilepath print 'Completed generating documentation from sources' # Remove the destination directory if it exists command = 'rm -rf ' + dest_dir os.system (command) print 'Copying to destination dir...' # Copy the source dir to the destination command = 'cp -dpR ' + source_dir + ' ' + dest_dir os.system (command) # Remove the source files from the destination directory for root, dirs, files in os.walk (dest_dir): for file in files: if (file.endswith ('.txt')): os.remove (os.path.join (root, file)) print 'Completed successfully'
Comments closed
The blog owner has closed further commenting on this entry.
No comments yet
There are no comments for this article yet.