Add dyn:first_page_only

Add dyn:ljdc_last
This commit is contained in:
Gregory Soutade 2014-06-01 18:58:13 +02:00
parent a747417ad2
commit 0741709259
5 changed files with 59 additions and 6 deletions

View File

@ -46,7 +46,9 @@ class Index(DynastieGenerator):
'navigation' : self.createNavigation,
'recents' : self.createRecents,
'tags' : self.createTags,
'replace' : self.createReplace}
'first_page_only' : self.createFirstPageOnly,
'ljdc_last' : self.createLJDCLast,
}
self.first_try = True
@ -133,6 +135,23 @@ class Index(DynastieGenerator):
root.replaceChild(node, title_elem)
def createFirstPageOnly(self, posts, dom, root, node):
if self.cur_page == 0:
for n in node.childNodes:
root.insertBefore(n.cloneNode(True), node)
root.removeChild(node)
def createLJDCLast(self, posts, dom, root, node):
from dynastie.generators.ljdc import LJDC
l = LJDC()
img = l.getLast(dom, self.blog.src_path)
if not img is None:
root.replaceChild(img, node)
else:
root.removeChild(node)
def createDate(self, posts, dom, root, date_elem):
date_format = date_elem.getAttribute('format')
if date_format == '':
@ -457,6 +476,8 @@ class Index(DynastieGenerator):
def generate(self, blog, src, output):
from dynastie.models import Post, Blog
self.blog = blog
dom = self.parseTemplate(blog, src, output, 'index')
if dom is None: return self.report

View File

@ -42,7 +42,8 @@ class LJDC(Index):
a.setAttribute('href', address.childNodes[0].nodeValue)
title_value = self.cur_post_obj.getElementsByTagName('title')[0]
title = self.createElement(dom, 'title', title_value.childNodes[0].nodeValue)
title_value = title_value.childNodes[0].nodeValue
title = self.createElement(dom, 'title', title_value)
a.appendChild(title)
img_src = self.cur_post_obj.getElementsByTagName('img')[0]
@ -57,9 +58,7 @@ class LJDC(Index):
return new_elem
def generate(self, blog, src, output):
from dynastie.models import Post, Blog, Category
def _load_references(self, src):
name = '_ljdc.xml'
if not os.path.exists(src + '/%s' % name):
self.addWarning('No %s found, exiting' % name)
@ -71,6 +70,13 @@ class LJDC(Index):
self.addError('Error parsing %s : ' + e)
return None
return srcdom
def generate(self, blog, src, output):
srcdom = self._load_references(src)
if srcdom is None: return None
posts = srcdom.getElementsByTagName("entry")
dom = self.parseTemplate(blog, src, output, 'ljdc', 'ljdc')
@ -83,3 +89,18 @@ class LJDC(Index):
return self.report
def getLast(self, dom, src):
srcdom = self._load_references(src)
if srcdom is None: return None
images = srcdom.getElementsByTagName("img")
if len(images) == 0: return None
img = dom.createElement('img')
img.setAttribute('src', images[0].childNodes[0].nodeValue)
title = srcdom.getElementsByTagName("title")[0]
title = title.childNodes[0].nodeValue
img.setAttribute('alt', title.replace("\"", "'"))
return img

View File

@ -1,5 +1,5 @@
post
index
post
category
tag
archive

View File

@ -17,6 +17,12 @@
</footer>
</article>
</dyn:posts>
<dyn:first_page_only>
<div id="last_ljdc">
<b>Dernier gif</b> <a href="/ljdc">les joies du code</a>
<a href="/ljdc"><dyn:ljdc_last/></a>
</div>
</dyn:first_page_only>
<nav>
<dyn:recents>
<span id="recents_title">More posts...</span>

View File

@ -595,4 +595,9 @@ div.all_posts div.post
.feed > a
{
margin-right:10px;
}
#last_ljdc
{
padding-bottom:40px;
}