don't use md for (tag) listing pages.

This commit is contained in:
chris 2014-02-09 17:15:46 +01:00
parent 6faaedfc0e
commit 9d22b24ed5
7 changed files with 25 additions and 42 deletions

View File

@ -41,7 +41,6 @@ Usage
TODO TODO
==== ====
- don't pregenerate listings (index, tag-pages), move to template.
- TEST! - TEST!
- make a shipable default template - make a shipable default template
- implement --post - implement --post

View File

@ -70,6 +70,7 @@ class Tag(object):
self.name = name self.name = name
self.posts = [] self.posts = []
@property
def colour(self): def colour(self):
""" return html colour for Tag. """ """ return html colour for Tag. """
return hashlib.md5(self.name.encode('utf-8')).hexdigest()[:6] return hashlib.md5(self.name.encode('utf-8')).hexdigest()[:6]
@ -303,29 +304,11 @@ def generate_index(posts, pages):
env = Environment(loader=FileSystemLoader(config.templatedir)) env = Environment(loader=FileSystemLoader(config.templatedir))
post_template = env.get_template('index.html') post_template = env.get_template('index.html')
# generate index from index.md # generate index from template
# TODO move markdown to md module
indexpage = "# {}\n".format(config.blogtitle)
for post in posts:
indexpage += "* {}: ".format(
post.date.strftime('%Y-%m-%d')
)
for tag in post.tags: # TODO HTML?!
indexpage += '<a class="post-category" style="background: #{};"' \
' href="tags/{}.html">{}</a> '.format(
tag.colour(),
tag.name,
tag.name,
)
indexpage += "[{}]({})\n".format(
post.title,
post.outfile,
)
ihtml = markdown2.markdown(indexpage, extras=config.mdextras)
ihtml = post_template.render( ihtml = post_template.render(
config=config, config=config,
body=ihtml,
pages=pages, pages=pages,
posts=posts,
) )
codecs.open( codecs.open(
os.path.join(config.outputdir, 'index.html'), os.path.join(config.outputdir, 'index.html'),
@ -391,21 +374,10 @@ def generate_tag_indeces(tagobjs, pages):
# generate index from index.md # generate index from index.md
# TODO move markdown to md module # TODO move markdown to md module
for tag in tagobjs.values(): for tag in tagobjs.values():
tagpage = "# {}\n".format(tag.name)
for post in tag.posts:
tagpage += "* {}: ".format(
post.date.strftime('%Y-%m-%d')
)
tagpage += "[{}]({}{})\n".format(
post.title,
config.blogurl,
post.outfile,
)
ihtml = markdown2.markdown(tagpage, extras=config.mdextras)
ihtml = post_template.render( ihtml = post_template.render(
config=config, config=config,
body=ihtml,
pages=pages, pages=pages,
posts=tag.posts,
) )
codecs.open( codecs.open(
os.path.join(config.outputdir, 'tags', '{}.html'.format(tag.name)), os.path.join(config.outputdir, 'tags', '{}.html'.format(tag.name)),

View File

@ -21,7 +21,19 @@
</div> </div>
<div id="post"> <div id="post">
{{ body|replace("{{blogurl}}", config.blogurl) }} <h1>{{ config.blogtitle }}</h1>
<ul>
{% for post in posts %}
<li>
{{ post.date }}:
{% for tag in post.tags %}
<a class="post-category" style="background: #{{ tag.colour }};"
href="tags/{{ tag.name }}.html">{{ tag.name }}</a>
{% endfor %}
<a href="{{ post.outfile }}">{{ post.title }}</a>
</li>
{% endfor %}
</ul>
</div> </div>
</body> </body>
</html> </html>

View File

@ -14,6 +14,6 @@ class TestTag(unittest.TestCase):
def test_tag(self): def test_tag(self):
colour = hashlib.md5('tag'.encode('utf-8')).hexdigest()[:6] colour = hashlib.md5('tag'.encode('utf-8')).hexdigest()[:6]
self.assertEqual(self.tag1.colour(), colour) self.assertEqual(self.tag1.colour, colour)
self.assertEqual(self.tag2.colour(), 'f32af7') self.assertEqual(self.tag2.colour, 'f32af7')

View File

@ -37,9 +37,9 @@ copyright = u'2014, Christoph Gebhardt'
# built documents. # built documents.
# #
# The short X.Y version. # The short X.Y version.
version = '0.0.1b' version = '0.0.2-alpha'
# The full version, including alpha/beta/rc tags. # The full version, including alpha/beta/rc tags.
release = '0.0.1b' release = '0.0.2-alpha'
# The language for content autogenerated by Sphinx. Refer to documentation # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.

View File

@ -40,8 +40,8 @@ Each template gets passed a few variables by blogtopoid.
**index.html only:** **index.html only:**
*body* *posts*
The preformatted page body. A list of Post objects to render. See below for details.
**post.html & page.html only:** **post.html & page.html only:**

View File

@ -14,8 +14,8 @@ def read_requirements():
setup( setup(
name='blogtopoid', name='blogtopoid',
version='0.0.1b', version='0.0.2-alpha',
author='chris', author='Christoph Gebhardt',
author_email='cg@zknt.org', author_email='cg@zknt.org',
packages=find_packages(), packages=find_packages(),
include_package_data=True, include_package_data=True,