From ae99cfbd9a0372b577a23636f0677f266a559c5f Mon Sep 17 00:00:00 2001 From: Scott Bahling Date: Tue, 19 Mar 2013 18:25:18 +0100 Subject: Implement full table of contents generation By default panfry now generates a full table of contents navigation for split page documents. This means the TOC navitation has links to all pages and page sections. Simple, page only level table of contents can be switched on by passing the --simple-toc option. --- panfry/document.py | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'panfry/document.py') diff --git a/panfry/document.py b/panfry/document.py index 0b450da..aa29561 100755 --- a/panfry/document.py +++ b/panfry/document.py @@ -14,9 +14,20 @@ class Document: self.src_path = path self.meta = self.get_meta(path) self.pages = self.get_pages(path) + self.full_toc = True - css_file = 'css/style.css' - workdir = 'stdocs-work' + self.css_file = 'css/style.css' + + @property + def set_simple_toc(self): + self.full_toc = False + + @property + def set_full_toc(self): + self.full_toc = True + + def set_templater(self, templater): + self.templater = templater @property def title(self): @@ -56,9 +67,6 @@ class Document: return meta - def set_templater(self, templater): - self.templater = templater - def next_page(self, page): try: idx = self.pages.index(page) @@ -85,11 +93,17 @@ class Document: ''' links = [] for page in self.pages: - title, level = page.title - links.append(dict(link=unicode(page.htmlfile, "utf8"), - text=unicode(title, "utf8"), - level=level, - )) + if self.full_toc: + toc = page.toc + else: + toc = [page.toc[0]] + + for tocitem in toc: + link = '%s#%s' % (page.htmlfile, tocitem.section_id) + links.append(dict(link=unicode(link, "utf8"), + text=unicode(tocitem.heading, "utf8"), + level=tocitem.level, + )) return links -- cgit v1.2.3