def generate(self, conf, env, data): ipp = self.items_per_page tt = env.engine.fromfile(self.template) entrylist = data['entrylist'] paginator = paginate(entrylist, ipp, self.path, conf.default_orphans) route = self.path for (next, curr, prev), entries, modified in paginator: # curr = current page, next = newer pages, prev = older pages next = None if next is None \ else link(u'« Next', self.path.rstrip('/')) if next == 1 \ else link(u'« Next', expand(self.pagination, {'num': next})) curr = link(curr, self.path) if curr == 1 \ else link(expand(self.pagination, {'num': curr})) prev = None if prev is None \ else link(u'Previous »', expand(self.pagination, {'num': prev})) path = joinurl(conf['output_dir'], curr.href, 'index.html') if isfile(path) and not (modified or tt.modified or env.modified or conf.modified): event.skip(path) continue html = tt.render(conf=conf, env=union(env, entrylist=entries, type='index', prev=prev, curr=curr, next=next, items_per_page=ipp, num_entries=len(entrylist), route=route)) yield html, path
def generate(self, request): ipp = self.items_per_page tt = self.env.engine.fromfile(self.template) entrylist = [entry for entry in request['entrylist'] if not entry.draft] paginator = paginate(entrylist, ipp, orphans=self.conf['default_orphans']) route = self.path for (next, curr, prev), entries, has_changed in paginator: # curr = current page, next = newer pages, prev = older pages next = None if next is None \ else link(u'« Next', self.path.rstrip('/')) if next == 1 \ else link(u'« Next', expand(self.pagination, {'num': next})) curr = link(curr, self.path) if curr == 1 \ else link(expand(self.pagination, {'num': curr})) prev = None if prev is None \ else link(u'Previous »', expand(self.pagination, {'num': prev})) path = joinurl(self.conf['output_dir'], curr.href, 'index.html') if exists(path) and not has_changed and not tt.has_changed: event.skip(path) continue html = tt.render(conf=self.conf, env=union(self.env, entrylist=entries, type='index', prev=prev, curr=curr, next=next, items_per_page=ipp, num_entries=len(entrylist), route=route)) yield html, path
def generate(self, conf, env, data, **kwargs): if self.pagination is None: self.items_per_page = 2**32 self.pagination = self.path ipp = self.items_per_page tt = env.engine.fromfile(env, self.template) route = expand(self.path, kwargs) entrylist = data['entrylist'] paginator = paginate(entrylist, ipp, route, conf.default_orphans) for (next, curr, prev), entrylist, modified in paginator: next = None if next is None \ else link(u'Next', expand(self.path, kwargs)) if next == 1 \ else link(u'Next', expand(self.pagination, union({'num': next}, kwargs))) curr = link(curr, expand(self.path, kwargs)) if curr == 1 \ else link(curr, expand(self.pagination, union({'num': curr}, kwargs))) prev = None if prev is None \ else link(u'Previous', expand(self.pagination, union({'num': prev}, kwargs))) path = joinurl(conf['output_dir'], curr.href) if isfile(path) and not (modified or tt.modified or env.modified or conf.modified): event.skip(self.__class__.__name__.lower(), path) continue html = self.render(conf, env, union(locals(), kwargs)) yield html, path
def generate(self, request): """Creates paged listing by tag.""" ipp = self.items_per_page tt = self.env.engine.fromfile(self.template) for tag in self.tags: entrylist = [entry for entry in self.tags[tag]] paginator = paginate(entrylist, ipp, salt=tag, orphans=self.conf["default_orphans"]) route = expand(self.path, {"name": tag}).rstrip("/") for (next, curr, prev), entries, has_changed in paginator: # e.g.: curr = /page/3, next = /page/2, prev = /page/4 next = ( None if next is None else link(u"« Next", expand(self.path, {"name": tag}).rstrip("/")) if next == 1 else link(u"« Next", expand(self.pagination, {"name": tag, "num": next})) ) curr = ( link(curr, expand(self.path, {"name": tag})) if curr == 1 else link(expand(self.pagination, {"num": curr, "name": tag})) ) prev = ( None if prev is None else link(u"Previous »", expand(self.pagination, {"name": tag, "num": prev})) ) path = joinurl(self.conf["output_dir"], curr, "index.html") if exists(path) and not has_changed and not tt.has_changed: event.skip(path) continue html = tt.render( conf=self.conf, env=union( self.env, entrylist=entries, type="tag", prev=prev, curr=curr, next=next, tag=tag, items_per_page=ipp, num_entries=len(entrylist), route=route, ), ) yield html, path
def generate(self, conf, env, data): tt = env.engine.fromfile(env, self.template) keyfunc = lambda k: () if '/:year' in self.path: keyfunc = lambda k: (k.year, ) if '/:month' in self.path: keyfunc = lambda k: (k.year, k.imonth) if '/:day' in self.path: keyfunc = lambda k: (k.year, k.imonth, k.iday) for next, curr, prev in neighborhood( groupby(data['entrylist'], keyfunc)): salt, group = '-'.join(str(i) for i in curr[0]), list(curr[1]) modified = memoize('archive-' + salt, hash(*group)) or any( e.modified for e in group) if prev: prev = link(u'/'.join('%02i' % i for i in prev[0]), expand(self.path, prev[1][0])) if next: next = link(u'/'.join('%02i' % i for i in next[0]), expand(self.path, next[1][0])) route = expand(self.path, group[0]) path = joinurl(conf['output_dir'], route) # an object storing year, zero-padded month and day as attributes (may be None) key = type( 'Archive', (object, ), dict( zip(('year', 'month', 'day'), map(lambda x: '%02i' % x if x else None, keyfunc(group[0])))))() if isfile(path) and not (modified or tt.modified or env.modified or conf.modified): event.skip('archive', path) continue html = tt.render(conf=conf, env=union(env, entrylist=group, type='archive', prev=prev, curr=link(route), next=next, num_entries=len(group), route=route, archive=key)) yield html, path
def generate(self, request): """Creates paged listing by tag.""" ipp = self.items_per_page tt = self.env.engine.fromfile(self.template) entrylist = [ entry for entry in request['entrylist'] if not entry.draft ] for tag in self.tags: entrylist = [entry for entry in self.tags[tag]] paginator = paginate(entrylist, ipp, salt=tag, orphans=self.conf['default_orphans']) route = expand(self.path, {'name': tag}).rstrip('/') for (next, curr, prev), entries, has_changed in paginator: # e.g.: curr = /page/3, next = /page/2, prev = /page/4 next = None if next is None \ else link(u'« Next', expand(self.path, {'name': tag}).rstrip('/')) if next == 1 \ else link(u'« Next', expand(self.pagination, {'name': tag, 'num': next})) curr = link(curr, expand(self.path, {'name': tag})) if curr == 1 \ else link(expand(self.pagination, {'num': curr, 'name': tag})) prev = None if prev is None \ else link(u'Previous »', expand(self.pagination, {'name': tag, 'num': prev})) path = joinurl(self.conf['output_dir'], curr, 'index.html') if exists(path) and not has_changed and not tt.has_changed: event.skip(path) continue html = tt.render(conf=self.conf, env=union(self.env, entrylist=entries, type='tag', prev=prev, curr=curr, next=next, tag=tag, items_per_page=ipp, num_entries=len(entrylist), route=route)) yield html, path
def generate(self, conf, env, data): for lang in env.langs: ipp = self.items_per_page tt = env.engine.fromfile(self.template) entrylist = [] for entry in data['entrylist']: try: e = entry_for_lang(data, lang, entry) entrylist.append(e) except TranslationNotFound: pass#entrylist.append(entry) paginator = paginate(entrylist, ipp, self.path, conf.default_orphans) route = '/blog/' for (next, curr, prev), entries, modified in paginator: # curr = current page, next = newer pages, prev = older pages if next is None: pass elif next == 1: next = link(u'« Next', expand(self.path.rstrip('/'), {'lang':lang})) else: next = link(u'« Next', expand(self.pagination, {'num': next,'lang': lang})) if next: next.href = strip_default_lang(next.href, self.conf) curr = link(curr, self.path) if curr == 1 \ else link(expand(self.pagination, {'num': curr,'lang': lang})) curr.href = strip_default_lang(curr.href, self.conf) prev = None if prev is None \ else link(u'Previous »', expand(self.pagination, {'num': prev,'lang': lang})) if prev: prev.href = strip_default_lang(prev.href, self.conf) path = joinurl(conf['output_dir'], expand(curr.href, {'lang': lang}), 'index.html') path = strip_default_lang(path, self.conf) env['lang'] = lang env['active_route'] = route if isfile(path) and not (modified or tt.modified or env.modified or conf.modified): event.skip(path) continue html = tt.render(conf=conf, env=union(env, entrylist=entries, type='index', prev=prev, curr=curr, next=next, items_per_page=ipp, num_entries=len(entrylist), route=route)) yield html, path
def next(self, entrylist, i): if i == 0: return None refs.append(entrylist[i], entrylist[i - 1]) return link(u"« " + entrylist[i-1].title, entrylist[i-1].permalink.rstrip('/'))
def next(self, entrylist, i): if i == 0: return None refs.append(entrylist[i], entrylist[i - 1]) return link(entrylist[i-1].title, entrylist[i-1].permalink)
def prev(self, entrylist, i): if i == len(entrylist) - 1: return None refs.append(entrylist[i], entrylist[i + 1]) return link(entrylist[i + 1].title, entrylist[i + 1].permalink)
def next(self, entrylist, i): if i == 0: return None refs.append(entrylist[i], entrylist[i - 1]) return link(entrylist[i - 1].title, entrylist[i - 1].permalink)
def prev(self, entrylist, i): if i == len(entrylist) - 1: return None refs.append(entrylist[i], entrylist[i + 1]) return link(entrylist[i+1].title, entrylist[i+1].permalink)
def generate(self, request): tt = self.env.tt.fromfile(self.template) entrylist = request['entrylist'] pathes = dict() for entry in entrylist: if entry.permalink != expand(self.path, entry): p = joinurl(self.conf['output_dir'], entry.permalink) else: p = joinurl(self.conf['output_dir'], expand(self.path, entry)) if p.endswith('/'): p = joinurl(p, 'index.html') if p in pathes: raise AcrylamidException("title collision %r in %r" % (entry.permalink, entry.filename)) pathes[p] = entry has_changed = False hv = md5(*entrylist, attr=lambda e: e.permalink) if memoize('entry-permalinks') != hv: memoize('entry-permalinks', hv) has_changed = True pathes = sorted(pathes.iteritems(), key=lambda k: k[1].date, reverse=True) for i, (path, entry) in enumerate(pathes): next = None if i == 0 else link(entrylist[i-1].title, entrylist[i-1].permalink.rstrip('/'), entrylist[i-1]) prev = None if i == len(pathes) - 1 else link(entrylist[i+1].title, entrylist[i+1].permalink.rstrip('/'), entrylist[i+1]) if exists(path) and not any([has_changed, entry.has_changed, tt.has_changed]): event.skip(path) continue html = tt.render(conf=self.conf, entry=entry, env=union(self.env, entrylist=[entry], type='entry', prev=prev, next=next)) yield html, path
def generate(self, request): ipp = self.items_per_page tt = self.env.engine.fromfile(self.template) entrylist = [ entry for entry in request['entrylist'] if not entry.draft ] paginator = paginate(entrylist, ipp, orphans=self.conf['default_orphans']) route = self.path for (next, curr, prev), entries, has_changed in paginator: # curr = current page, next = newer pages, prev = older pages next = None if next is None \ else link(u'« Next', self.path.rstrip('/')) if next == 1 \ else link(u'« Next', expand(self.pagination, {'num': next})) curr = link(curr, self.path) if curr == 1 \ else link(expand(self.pagination, {'num': curr})) prev = None if prev is None \ else link(u'Previous »', expand(self.pagination, {'num': prev})) path = joinurl(self.conf['output_dir'], curr.href, 'index.html') if exists(path) and not has_changed and not tt.has_changed: event.skip(path) continue html = tt.render(conf=self.conf, env=union(self.env, entrylist=entries, type='index', prev=prev, curr=curr, next=next, items_per_page=ipp, num_entries=len(entrylist), route=route)) yield html, path
def generate(self, request): """Creates paged listing by tag.""" ipp = self.items_per_page tt = self.env.engine.fromfile(self.template) entrylist = [entry for entry in request['entrylist'] if not entry.draft] for tag in self.tags: entrylist = [entry for entry in self.tags[tag]] paginator = paginate(entrylist, ipp, salt=tag, orphans=self.conf['default_orphans']) route = expand(self.path, {'name': tag}).rstrip('/') for (next, curr, prev), entries, has_changed in paginator: # e.g.: curr = /page/3, next = /page/2, prev = /page/4 next = None if next is None \ else link(u'« Next', expand(self.path, {'name': tag}).rstrip('/')) if next == 1 \ else link(u'« Next', expand(self.pagination, {'name': tag, 'num': next})) curr = link(curr, expand(self.path, {'name': tag})) if curr == 1 \ else link(expand(self.pagination, {'num': curr, 'name': tag})) prev = None if prev is None \ else link(u'Previous »', expand(self.pagination, {'name': tag, 'num': prev})) path = joinurl(self.conf['output_dir'], curr, 'index.html') if exists(path) and not has_changed and not tt.has_changed: event.skip(path) continue html = tt.render(conf=self.conf, env=union(self.env, entrylist=entries, type='tag', prev=prev, curr=curr, next=next, tag=tag, items_per_page=ipp, num_entries=len(entrylist), route=route)) yield html, path
def generate(self, conf, env, data): tt = env.engine.fromfile(env, self.template) keyfunc = lambda k: ( ) if '/:year' in self.path: keyfunc = lambda k: (k.year, ) if '/:month' in self.path: keyfunc = lambda k: (k.year, k.imonth) if '/:day' in self.path: keyfunc = lambda k: (k.year, k.imonth, k.iday) for next, curr, prev in neighborhood(groupby(data['entrylist'], keyfunc)): salt, group = '-'.join(str(i) for i in curr[0]), list(curr[1]) modified = memoize('archive-' + salt, hash(*group)) or any(e.modified for e in group) if prev: prev = link(u'/'.join('%02i' % i for i in prev[0]), expand(self.path, prev[1][0])) if next: next = link(u'/'.join('%02i' % i for i in next[0]), expand(self.path, next[1][0])) route = expand(self.path, group[0]) path = joinurl(conf['output_dir'], route) # an object storing year, zero-padded month and day as attributes (may be None) key = type('Archive', (object, ), dict(zip(('year', 'month', 'day'), map(lambda x: '%02i' % x if x else None, keyfunc(group[0])) )))() if isfile(path) and not (modified or tt.modified or env.modified or conf.modified): event.skip('archive', path) continue html = tt.render(conf=conf, env=union(env, entrylist=group, type='archive', prev=prev, curr=link(route), next=next, num_entries=len(group), route=route, archive=key)) yield html, path
def generate(self, conf, env, data): """Creates paged listing by tag.""" ipp = self.items_per_page tt = env.engine.fromfile(self.template) for tag in self.tags: route = expand(self.path, {'name': tag}).rstrip('/') entrylist = [entry for entry in self.tags[tag]] paginator = paginate(entrylist, ipp, route, conf['default_orphans']) for (next, curr, prev), entries, modified in paginator: # e.g.: curr = /page/3, next = /page/2, prev = /page/4 next = None if next is None \ else link(u'Next', expand(self.path, {'name': tag}).rstrip('/')) if next == 1 \ else link(u'Next', expand(self.pagination, {'name': tag, 'num': next})) curr = link(curr, expand(self.path, {'name': tag})) if curr == 1 \ else link(expand(self.pagination, {'num': curr, 'name': tag})) prev = None if prev is None \ else link(u'Previous', expand(self.pagination, {'name': tag, 'num': prev})) path = joinurl(conf['output_dir'], curr) if isfile(path) and not (modified or tt.modified or env.modified or conf.modified): event.skip('tag', path) continue html = tt.render(conf=conf, env=union(env, entrylist=entries, type='tag', prev=prev, curr=curr, next=next, tag=tag, items_per_page=ipp, num_entries=len(entrylist), route=route)) yield html, path
def next(self, entrylist, i): return None if i == 0 else link(u"« " + entrylist[i-1].title, entrylist[i-1].permalink.rstrip('/'), entrylist[i-1])
def prev(self, entrylist, i): return None if i == len(entrylist) - 1 else link(entrylist[i+1].title + u" »", entrylist[i+1].permalink.rstrip('/'), entrylist[i+1])