Skip to content

Instantly share code, notes, and snippets.

@swanson
Created June 18, 2010 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swanson/443151 to your computer and use it in GitHub Desktop.
Save swanson/443151 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os, shutil
PAGE_ORDER = ['header', 'banner', 'content', \
'footer', 'sidebar', 'analytics']
def createPage(content, dest = None):
page, w_target = '', 'site'
for section in PAGE_ORDER:
if section is 'content':
r_target = 'content'
if dest:
r_target = os.path.join(r_target, dest)
r_target = os.path.join(r_target, content)
else:
if section is 'header' and content == 'index.html':
section = 'header-index' #twitter javascript
r_target = os.path.join('static', '%s.html' % section)
with open(r_target, 'r') as f:
html = f.read()
page += html
if dest:
w_target = os.path.join(w_target, dest)
w_target = os.path.join(w_target, content)
with open(w_target, 'w') as f:
f.write(page)
print 'Generated %s' % w_target
#clean out old directory
if os.path.exists('site'):
shutil.rmtree('site')
print 'Cleaned site/ directory'
#build directory structure
os.mkdir('site')
SITE_DIRS = ['images', 'projects', 'css']
for dir in SITE_DIRS:
os.mkdir(os.path.join('site', dir))
print 'Built directory structure'
#generate static content
#TODO generate sidebar
print 'Generated template elements'
#generate content pages
cwd = os.getcwd()
for item in os.listdir(os.path.join(cwd, 'content')):
if item.endswith('.html'):
createPage(item)
dir = os.path.join(cwd, 'content', item)
if os.path.isdir(dir):
for file in os.listdir(dir):
if file.endswith('.html'):
createPage(file, item)
#copy over images and css
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment