Add tags support
Set slugify to be global Update modification date only if text has been changed Fix a bug in preview (post_id was passed instead of blog_id) Add Home, Category and Tag links in blog area instead of global area (dynastie template) Fix a bug in Have_I_right
This commit is contained in:
@@ -1 +1 @@
|
||||
__all__ = ["generator", "index", "post", "category", "archive", "rss", "atom"]
|
||||
__all__ = ["generator", "index", "post", "category", "tag", "archive", "rss", "atom"]
|
||||
|
||||
@@ -57,9 +57,10 @@ class Archive(Index):
|
||||
def generate(self, blog, src, output):
|
||||
from dynastie.models import Post, Blog
|
||||
|
||||
hooks = {'posts' : self.createPosts,
|
||||
self.hooks = {'posts' : self.createPosts,
|
||||
'navigation' : self.createNavigation,
|
||||
'archive' : self.createArchive}
|
||||
'archive' : self.createArchive,
|
||||
'tags' : self.createTags}
|
||||
|
||||
if not os.path.exists(src + '/_archive.html'):
|
||||
self.addError('No _archive.html found, exiting')
|
||||
@@ -99,7 +100,7 @@ class Archive(Index):
|
||||
if posts[i].creation_date.year != posts[i+1].creation_date.year:
|
||||
dom = parse(src + '/_archive.html')
|
||||
my_post.reverse()
|
||||
self.createArchives(src, output, dom, hooks, my_post)
|
||||
self.createArchives(src, output, dom, self.hooks, my_post)
|
||||
self.cur_year = int(posts[i+1].creation_date.year)
|
||||
#print 'New year ' + str(self.cur_year)
|
||||
my_post = []
|
||||
@@ -114,7 +115,7 @@ class Archive(Index):
|
||||
self.cur_year = int(posts[i].creation_date.year)
|
||||
|
||||
if len(my_post) != 0:
|
||||
self.createArchives(src, output, dom, hooks, my_post)
|
||||
self.createArchives(src, output, dom, self.hooks, my_post)
|
||||
|
||||
if not self.somethingWrote:
|
||||
self.addReport('Nothing changed')
|
||||
|
||||
@@ -24,9 +24,10 @@ class Category(Index):
|
||||
def generate(self, blog, src, output):
|
||||
from dynastie.models import Post, Blog, Category
|
||||
|
||||
hooks = {'posts' : self.createPosts,
|
||||
self.hooks = {'posts' : self.createPosts,
|
||||
'navigation' : self.createNavigation,
|
||||
'category' : self.createCategory}
|
||||
'category' : self.createCategory,
|
||||
'tags' : self.createTags}
|
||||
|
||||
if not os.path.exists(src + '/_category.html'):
|
||||
self.addError('No _category.html found, exiting')
|
||||
@@ -73,7 +74,7 @@ class Category(Index):
|
||||
while self.cur_page <= self.nb_pages:
|
||||
#print 'Generate ' + filename
|
||||
nodes = dom.getElementsByTagName("*")
|
||||
nodes[0] = self.parse(src, hooks, posts, dom, nodes[0])
|
||||
nodes[0] = self.parse(src, self.hooks, posts, dom, nodes[0])
|
||||
self.writeIfNotTheSame(output + self.dirname + '/' + filename, nodes[0])
|
||||
self.cur_page = self.cur_page + 1
|
||||
filename = self.filename + str(self.cur_page) + '.html'
|
||||
|
||||
@@ -105,6 +105,9 @@ class Index(DynastieGenerator):
|
||||
post_elem = self.createElement(dom, '', '<b>No posts yet</b>')
|
||||
posts_elem.appendChild(post_elem)
|
||||
|
||||
# Parse inner HTML
|
||||
self._parse(self.hooks, posts, dom, post_elem)
|
||||
|
||||
self.cur_post = self.cur_post + 1
|
||||
if self.cur_post == len(posts):
|
||||
break
|
||||
@@ -139,12 +142,48 @@ class Index(DynastieGenerator):
|
||||
|
||||
return recents_elem
|
||||
|
||||
def createTags(self, posts, dom, root, node):
|
||||
from dynastie.models import Post
|
||||
tags_elem = self.createElement(dom, 'tags')
|
||||
create_link = (node.getAttribute('link') == '1')
|
||||
if type(posts) == models.query.QuerySet:
|
||||
if len(posts) > self.cur_post:
|
||||
cur_post = posts[self.cur_post]
|
||||
else:
|
||||
cur_post = None
|
||||
elif type(posts) == Post:
|
||||
cur_post = posts
|
||||
else:
|
||||
cur_post = None
|
||||
|
||||
if not cur_post is None:
|
||||
for tag in cur_post.tags.all():
|
||||
if create_link:
|
||||
tag_elem = self.createElement(dom, 'tag')
|
||||
link_elem = self.createLinkElem(dom, '/tag/' + tag.name_slug, '#' + tag.name)
|
||||
tag_elem.appendChild(link_elem)
|
||||
else:
|
||||
tag_elem = self.createElement(dom, 'tag', '#' + tag.name)
|
||||
tags_elem.appendChild(tag_elem)
|
||||
|
||||
if len(cur_post.tags.all()) == 0:
|
||||
root.removeChild(node)
|
||||
return None
|
||||
else:
|
||||
root.replaceChild(tags_elem, node)
|
||||
else:
|
||||
root.removeChild(node)
|
||||
return None
|
||||
|
||||
return tags_elem
|
||||
|
||||
def generate(self, blog, src, output):
|
||||
from dynastie.models import Post, Blog
|
||||
|
||||
hooks = {'posts' : self.createPosts,
|
||||
self.hooks = {'posts' : self.createPosts,
|
||||
'navigation' : self.createNavigation,
|
||||
'recents' : self.createRecents}
|
||||
'recents' : self.createRecents,
|
||||
'tags' : self.createTags}
|
||||
|
||||
if not os.path.exists(src + '/_index.html'):
|
||||
self.addError('No _index.html found, exiting')
|
||||
@@ -180,7 +219,7 @@ class Index(DynastieGenerator):
|
||||
while self.cur_page <= self.nb_pages:
|
||||
#print 'Generate ' + filename
|
||||
nodes = dom.getElementsByTagName("*")
|
||||
nodes[0] = self.parse(src, hooks, posts, dom, nodes[0])
|
||||
nodes[0] = self.parse(src, self.hooks, posts, dom, nodes[0])
|
||||
self.writeIfNotTheSame(output + '/' + filename, nodes[0])
|
||||
self.cur_page = self.cur_page + 1
|
||||
filename = 'index' + str(self.cur_page) + '.html'
|
||||
|
||||
@@ -138,9 +138,10 @@ class Post(Index):
|
||||
def _generate(self, blog, src, output, posts):
|
||||
import xml
|
||||
self.hooks = {'post' : self._createPost,
|
||||
'meta' : self.createMetas,
|
||||
'comments' : self.createComments,
|
||||
'replace' : self.createReplace}
|
||||
'meta' : self.createMetas,
|
||||
'comments' : self.createComments,
|
||||
'replace' : self.createReplace,
|
||||
'tags' : self.createTags}
|
||||
|
||||
if not os.path.exists(src + '/_post.html'):
|
||||
self.addError('No _post.html found, exiting')
|
||||
@@ -210,7 +211,8 @@ class Post(Index):
|
||||
def preview(self, src, values):
|
||||
from dynastie.models import Blog
|
||||
|
||||
self.hooks = {'post' : self.createPreview}
|
||||
self.hooks = {'post' : self.createPreview,
|
||||
'tags' : self.createTags}
|
||||
|
||||
if not os.path.exists(src + '/_post.html'):
|
||||
self.addError('No _post.html found, exiting')
|
||||
|
||||
Reference in New Issue
Block a user