c4bee2f20591

Linkify titles.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Mon, 23 Jan 2012 20:30:25 -0500
parents 790fe5ece24e
children 26cae5dde824
branches/tags (none)
files d/base.py

Changes

--- a/d/base.py	Mon Jan 23 20:07:28 2012 -0500
+++ b/d/base.py	Mon Jan 23 20:30:25 2012 -0500
@@ -38,8 +38,10 @@
     <body class="content">
         <div class="wrap">
             <header><h1><a href="..">{project_title}</a></h1></header>
+                <div class="markdown">
 '''
 POST = '''
+                </div>
             <footer>{footer}</footer>
         </div>
     </body>
@@ -116,10 +118,19 @@
     e('.toc > ul').html(subtoc)
     return unicode(e)
 
+def _linkify_title(content):
+    e = pq(content)
+
+    title = e('.markdown h1').text()
+    e('.markdown h1').html('<a href="">' + title + '</a>')
+
+    return unicode(e)
+
 def _ensure_dir(path):
     if not os.path.isdir(path):
         os.makedirs(path)
 
+
 def _render(title, footer, path, target, page_type, toc=None):
     if page_type == 'index':
         pre, post = INDEX_PRE, POST
@@ -141,7 +152,7 @@
     content += post.format(footer=footer)
 
     if page_type == 'content':
-        content = _fix_md_toc(content)
+        content = _linkify_title(_fix_md_toc(content))
 
     if not os.path.isdir(target):
         os.makedirs(target)
@@ -171,6 +182,7 @@
 
     return _render(title, footer, path, target, 'index', toc)
 
+
 def render_files():
     _ensure_dir(BUILD_LOC)
     _ensure_dir(j(BUILD_LOC, '_dmedia'))