summaryrefslogtreecommitdiff
path: root/panfry/document.py
diff options
context:
space:
mode:
authorScott Bahling <sbahling@suse.de>2013-03-23 14:49:42 +0100
committerScott Bahling <sbahling@suse.de>2013-03-23 14:49:42 +0100
commit74edbf065728498c38f1975c97b7d16f40d1903c (patch)
treedbbd610f899b16447a09e7dc36e975c042404b05 /panfry/document.py
parenta62783371454942e4edc1aa6e23b7deb76a268a4 (diff)
downloadpanfry-74edbf065728498c38f1975c97b7d16f40d1903c.tar.gz
panfry-74edbf065728498c38f1975c97b7d16f40d1903c.tar.xz
panfry-74edbf065728498c38f1975c97b7d16f40d1903c.zip
New document file structure
- Document source is to be found under srcdir/src - Templates under srcdir/templates - Assets under srcdir/assets Assets are any files/directories that should be copied to the pubdir but are otherwise unprocessed by panfry. - By default pubdir = srcdir/pub
Diffstat (limited to 'panfry/document.py')
-rwxr-xr-xpanfry/document.py40
1 files changed, 17 insertions, 23 deletions
diff --git a/panfry/document.py b/panfry/document.py
index 4379f6e..7bc65c2 100755
--- a/panfry/document.py
+++ b/panfry/document.py
@@ -11,12 +11,13 @@ from panfry.page import TextFile, Page
class Document:
def __init__(self, path):
- self.src_path = path
- self.meta = self.get_meta(path)
- self.pages = self.get_pages(path)
+ self.src_path = os.path.join(path, 'src')
+ self.meta = self.get_meta(self.src_path)
+ self.pages = self.get_pages(self.src_path)
self.full_toc = True
self.css_file = 'css/style.css'
+ self.assets_dir = 'assets'
@property
def set_simple_toc(self):
@@ -74,7 +75,6 @@ class Document:
def get_pages(self, path):
pages = []
filelist = self.toc.lines
- print filelist
for filename in filelist:
print("Reading in %s..." % filename)
if not filename: # blank line in toc
@@ -187,28 +187,21 @@ class Document:
doc = pandoc.Document()
doc.markdown = src
+ print("epub_path: %s" % epub_path)
pandoc.set_cwd(os.path.abspath(self.src_path))
doc.to_file(epub_path)
pandoc.set_cwd(None)
return self.epub_filename
- def publish_css(self, pub_path):
- src = os.path.join(self.src_path, 'css')
- dst = os.path.join(pub_path, 'css')
- if os.path.isdir(src):
- copy(src, dst)
-
- def publish_images(self, pub_path):
- src_path = self.src_path
- if os.path.exists(os.path.join(src_path, 'images/html')):
- src = os.path.join(src_path, 'images/html')
- else:
- src = os.path.join(src_path, 'images')
-
- dst = os.path.join(pub_path, 'images')
- if os.path.exists(src):
- copy(src, dst)
+ def publish_assets(self, pub_path):
+ if not os.path.isdir(self.assets_dir):
+ return
+ for asset in os.listdir(self.assets_dir):
+ src = os.path.join(self.assets_dir, asset)
+ dst = os.path.join(pub_path, asset)
+ if os.path.isdir(src):
+ copy(src, dst)
def publish_html(self, pub_path):
pandoc.set_cwd(None)
@@ -235,8 +228,9 @@ class Document:
if not 'index.md' in self.pages:
src = os.path.join(self.pages[0].htmlfile)
ref = os.path.join(pub_path, 'index.html')
+ if os.path.exists(ref):
+ os.remove(ref)
os.symlink(src, ref)
- ###### Copy any images to publish directory
- self.publish_css(pub_path)
- self.publish_images(pub_path)
+ ###### Copy any assets to publish directory
+ self.publish_assets(pub_path)