Commits

Steve Losh committed ce14334

Moar.

Comments (0)

Files changed (20)

bookmarkdown/bookmarkdown

 import os, shutil
 import baker
 import markdown
+import config
+from pyquery import PyQuery as pq
 from jinja2 import Environment, PackageLoader
 
 env = Environment(loader=PackageLoader('bookmarkdown', 'templates'))
 join = os.path.join
+
+base_context = {
+    'title': getattr(config, 'title', ''),
+    'author': getattr(config, 'author', ''),
+    'author_url': getattr(config, 'author_url', ''),
+}
 # }}}
 
 # Utilities ------------------------------------------------------------------------
         return target
     reduce(_md, os.path.split(path), '')
 
+def render(template, **context):
+    full_context = {}
+    full_context.update(base_context)
+    full_context.update(context)
+
+    return env.get_template('%s.html' % template).render(**full_context)
+
+
 
 # Guts -----------------------------------------------------------------------------
 def _build_html_file(filename, template, context={}):
     with open(source, 'r') as f:
         content = markdown.markdown(f.read())
 
-    out = env.get_template('%s.html' % template).render(content=content, **context)
+    out = render(template, content=content, **context)
     target = join('build', 'html', '%s.html' % filename)
 
     with open(target, 'w') as f:
         f.write(out)
 
+    content = pq(out)
+
+    return {'content': content, 'name': content('.content h1').text(),
+            'filename': filename}
+
 def _build_index_file(chapters):
     source = 'introduction.markdown'
 
     with open(source, 'r') as f:
         content = markdown.markdown(f.read())
 
-    out = env.get_template('splash.html').render(content=content, chapters=chapters)
+    out = render('splash', content=content, chapters=chapters)
     target = join('build', 'html', 'index.html')
 
     with open(target, 'w') as f:
     for filename in os.listdir('chapters'):
         if filename.endswith('.markdown'):
             name = filename.rsplit('.')[0]
-            _build_html_file(join('chapters', name), 'chapter')
-            chapters.append(name)
+            chapter = _build_html_file(join('chapters', name), 'chapter')
+            chapters.append(chapter)
 
     _build_index_file(chapters)
 

bookmarkdown/static/styles/style.less

 html, body {
     font: normal 16px/22px 'Palatino', 'Georgia', sans-serif;
 
-    h2 {
+    h1 {
         font-size: 28px;
     }
-    h3 {
+    h2 {
         font-size: 24px;
     }
+    h3 {
+        font-size: 20px;
+    }
     h4 {
-        font-size: 20px;
+        font-size: 18px;
+    }
+    h5 {
+        font-size: 16px;
     }
     header {
         margin-top: 30px;
         margin-bottom: 30px;
         text-align: center;
+        
+        h1 {
+            font-size: 42px;
+        }
     }
     footer {
         margin-top: 30px;

bookmarkdown/templates/base.html

     <body class="{% block class %}{% endblock %}">
         <div class="container">
             <header class="sixteen columns">
-                <h1>Book Title</h1>
+                <h1>{{ title }}</h1>
             </header>
 
             {% block content_full %}
             {% endblock %}
 
             <footer class="sixteen columns">
-                Made by <a href="{{ author_url }}">{{ author }} Jimmy the Cat</a>.
+                Made by <a href="{{ author_url }}">{{ author }}</a>.
 
                 <a href="/license.html">License</a>.
 

bookmarkdown/templates/chapter.html

 {% extends "base.html" %}
 
 {% block content %}
-    Chapter foo:
     {{ content }}
 {% endblock %}

bookmarkdown/templates/splash.html

                 <li><a href="/acknowledgements.html">Acknowledgements</a></li>
                 <li><a href="/preface.html">Preface</a></li>
                 {% for chapter in chapters %}
-                    <li><a href="/chapters/{{ chapter }}.html">{{ chapter }}</a></li>
+                    <li><a href="/{{ chapter['filename'] }}.html">{{ chapter['name'] }}</a></li>
                 {% endfor %}
             </ol>
         </section>

sample/chapters/00.markdown

+Installing Vim
+==============

sample/chapters/01-history.markdown

Empty file removed.

sample/chapters/01.markdown

+Basic Mapping
+=============
+
+What Should Happen
+------------------
+
+Extra Credit
+------------
+
+

sample/chapters/02-basic.markdown

Empty file removed.

sample/chapters/02.markdown

+Modal Mapping
+=============
+
+What Should Happen
+------------------
+
+Extra Credit
+------------
+
+

sample/chapters/03-advanced.markdown

Empty file removed.

sample/chapters/03.markdown

+Strict Mapping
+==============
+
+What Should Happen
+------------------
+
+Extra Credit
+------------
+
+

sample/chapters/04.markdown

Empty file added.

sample/chapters/05.markdown

Empty file added.

sample/chapters/06.markdown

Empty file added.

sample/chapters/07.markdown

Empty file added.

sample/chapters/08.markdown

Empty file added.

sample/chapters/09.markdown

Empty file added.

sample/chapters/10.markdown

Empty file added.
+title = 'Learn Vimscript the Hard Way'
+author = 'Steve Losh'
+author_url = 'http://stevelosh.com'