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
====
- don't pregenerate listings (index, tag-pages), move to template.
- TEST!
- make a shipable default template
- implement --post

View File

@ -70,6 +70,7 @@ class Tag(object):
self.name = name
self.posts = []
@property
def colour(self):
""" return html colour for Tag. """
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))
post_template = env.get_template('index.html')
# generate index from index.md
# 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)
# generate index from template
ihtml = post_template.render(
config=config,
body=ihtml,
pages=pages,
posts=posts,
)
codecs.open(
os.path.join(config.outputdir, 'index.html'),
@ -391,21 +374,10 @@ def generate_tag_indeces(tagobjs, pages):
# generate index from index.md
# TODO move markdown to md module
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(
config=config,
body=ihtml,
pages=pages,
posts=tag.posts,
)
codecs.open(
os.path.join(config.outputdir, 'tags', '{}.html'.format(tag.name)),

View File

@ -21,7 +21,19 @@
</div>
<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>
</body>
</html>

View File

@ -14,6 +14,6 @@ class TestTag(unittest.TestCase):
def test_tag(self):
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.
#
# The short X.Y version.
version = '0.0.1b'
version = '0.0.2-alpha'
# 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
# for a list of supported languages.

View File

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

View File

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