summaryrefslogtreecommitdiff
path: root/panfry/document.py
diff options
context:
space:
mode:
authorScott Bahling <sbahling@mudgum.net>2013-03-18 21:25:05 +0100
committerScott Bahling <sbahling@mudgum.net>2013-03-18 21:25:05 +0100
commitc483362f5afcc5ae9e89e560148cc4129e4d62da (patch)
treed7e3f260be04f53f19e3dda34ab48cd7b535c2b6 /panfry/document.py
parentf773bbd88666b4ac8c3e1db93b9a9dc2bd92c43d (diff)
downloadpanfry-c483362f5afcc5ae9e89e560148cc4129e4d62da.tar.gz
panfry-c483362f5afcc5ae9e89e560148cc4129e4d62da.tar.xz
panfry-c483362f5afcc5ae9e89e560148cc4129e4d62da.zip
Better document title detection and pdf filename generation
Diffstat (limited to 'panfry/document.py')
-rwxr-xr-xpanfry/document.py32
1 files changed, 18 insertions, 14 deletions
diff --git a/panfry/document.py b/panfry/document.py
index 42ef959..5ff7ee6 100755
--- a/panfry/document.py
+++ b/panfry/document.py
@@ -17,6 +17,14 @@ class Document:
css_file = 'css/style.css'
workdir = 'stdocs-work'
+ @property
+ def title(self):
+ header = self.meta['HEADER'].strip()
+ if header.startswith('%'):
+ return header.split('%')[1].strip()
+ else:
+ return pages[0].title
+
def get_pages(self, path):
pages = []
filelist = get_lines(self.meta['TOC'])
@@ -81,20 +89,16 @@ class Document:
@property
def pdf_filename(self):
- header = self.meta['HEADER']
- m = re.match('(^%)(.*\n.*)(%*)', header)
- if m:
- title = m.group(2).strip()
- title = re.sub(r'\s+', ' ', title)
- title = re.sub(r'[\n ]', '_', title)
- title = re.sub(r'[:,]', '-', title)
- title = re.sub(r'_+', '_', title)
- title = re.sub(r'-_', '-', title)
- title = re.sub(r'-+', '-', title)
- else:
- title = os.path.split(self.src_path)[1]
-
- return title + '.pdf'
+ filename = self.title
+ filename = self.meta['HEADER'].split('%')[1].strip()
+ filename = re.sub(r'\s+', ' ', filename)
+ filename = re.sub(r'[\n ]', '_', filename)
+ filename = re.sub(r'[:,]', '-', filename)
+ filename = re.sub(r'_+', '_', filename)
+ filename = re.sub(r'-_', '-', filename)
+ filename = re.sub(r'-+', '-', filename)
+
+ return filename + '.pdf'
def publish_pdf(self, pub_path):
pdf_path = os.path.join(pub_path, self.pdf_filename)