summaryrefslogtreecommitdiff
path: root/site_builder/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'site_builder/__init__.py')
-rw-r--r--site_builder/__init__.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/site_builder/__init__.py b/site_builder/__init__.py
index f72cd92..c8e9a46 100644
--- a/site_builder/__init__.py
+++ b/site_builder/__init__.py
@@ -8,6 +8,7 @@ Site Builder
8""" 8"""
9 9
10import os 10import os
11from os import path
11import jinja2 12import jinja2
12import pagebuilder 13import pagebuilder
13from datetime import datetime 14from datetime import datetime
@@ -15,10 +16,13 @@ from docutils.core import publish_parts
15from docutils.io import FileInput 16from docutils.io import FileInput
16 17
17 18
19TEMPLATES = path.join(path.dirname(path.dirname(__file__)), "templates")
20
21
18def get_template(name): 22def get_template(name):
19 loader = jinja2.FileSystemLoader('ventriloquy/templates') 23 loader = jinja2.FileSystemLoader(TEMPLATES)
20 renderer = jinja2.Environment(loader=loader) 24 renderer = jinja2.Environment(loader=loader)
21 return renderer.get_template(name) 25 return renderer.get_template(name)
22 26
23 27
24def build_standard_page(filename, output_name): 28def build_standard_page(filename, output_name):
@@ -26,7 +30,7 @@ def build_standard_page(filename, output_name):
26 template = get_template('page.html') 30 template = get_template('page.html')
27 31
28 try: 32 try:
29 os.makedirs(os.path.dirname(output_name)) 33 os.makedirs(path.dirname(output_name))
30 except OSError: 34 except OSError:
31 pass # directory exists 35 pass # directory exists
32 36
@@ -37,9 +41,9 @@ def build_standard_page(filename, output_name):
37 41
38 42
39def get_output_name(base_dir, output_dir, filename): 43def get_output_name(base_dir, output_dir, filename):
40 base_depth = len(base_dir.split(os.path.sep)) 44 base_depth = len(base_dir.split(path.sep))
41 out_name = filename.split(os.path.sep)[base_depth:] 45 out_name = filename.split(path.sep)[base_depth:]
42 new_path = os.path.join(output_dir, *out_name) 46 new_path = path.join(output_dir, *out_name)
43 47
44 if new_path.endswith('.rst'): 48 if new_path.endswith('.rst'):
45 new_path = new_path[:-len('.rst')] + '.html' 49 new_path = new_path[:-len('.rst')] + '.html'
@@ -50,12 +54,11 @@ def get_output_name(base_dir, output_dir, filename):
50def build_all(base_dir, output_dir): 54def build_all(base_dir, output_dir):
51 for root, dirs, files in os.walk(base_dir): 55 for root, dirs, files in os.walk(base_dir):
52 for filename in files: 56 for filename in files:
53 if ('personal_blog' in root or 57 if ('blog.cfg' in files or
54 'blog' in root or
55 not filename.endswith('.rst')): 58 not filename.endswith('.rst')):
56 continue 59 continue
57 60
58 old_path = os.path.join(root, filename) 61 old_path = path.join(root, filename)
59 new_path = get_output_name(base_dir, output_dir, old_path) 62 new_path = get_output_name(base_dir, output_dir, old_path)
60 63
61 print "BUILDING: ", old_path 64 print "BUILDING: ", old_path