Example #1
0
def cb_end(request):
    """Generates a overview of all articles."""
    
    request = deepcopy(request)
    request = tools.run_callback('prepare',
                    request) # needed for entry's url
    
    config = request._config
    data = request._data
    layout = os.path.join(config.get('layout_dir', 'layouts'), 'articles.html')
    tt_articles = Template(convert_text(open(layout).read()))
    articles = defaultdict(list)
    
    for entry in sorted(data['entry_list'], key=lambda k: k.date, reverse=True):
        url, title, year = entry['url'], entry['title'], entry.date.year
        
        articles[year].append((entry.date, url, title))
        
    articlesdict = config.copy()
    articlesdict.update({'articles': articles,
                 'num_entries': len(data['entry_list'])})
                 
    html = tt_articles.render(articlesdict)
    path = os.path.join(config.get('output_dir', 'out'), 'articles', 'index.html')
    
    tools.mk_file(html, {'title': 'articles/index.html'}, path)
    
    return request
Example #2
0
def cb_end(request):
    
    tt_atom_entry = Template(convert_text(ATOM_ENTRY))
    tt_atom_body = Template(convert_text(ATOM_BODY))
    tt_rss_entry = Template(convert_text(RSS_ENTRY))
    tt_rss_body = Template(convert_text(RSS_BODY))
    config = request._config
    data = request._data
    
    data['type'] = 'feed'
    count = 25
    
    # last preparations
    request = tools.run_callback(
            'prepare',
            request)
    
    dict = request._config
    rss_list = []
    atom_list = []
    for entry in data['entry_list'][:25]:
        entry['body'] = cgi.escape(entry['body'].replace('­', ''))
        entrydict = dict.copy()
        entrydict.update(entry)
        atom_list.append(tt_atom_entry.render( entrydict ))
        rss_list.append(tt_rss_entry.render( entrydict ))
    
    # atom
    dict.update( {'entry_list': '\n'.join(atom_list),
                  'date': data['entry_list'][0].date } )
    xml = tt_atom_body.render( dict )
    directory = os.path.join(config.get('output_dir', 'out'), 'atom')
    path = os.path.join(directory, 'index.xml')
    tools.mk_file(xml, {'title': 'atom/index.xml'}, path)
    
    # rss
    dict.update( {'entry_list': '\n'.join(rss_list),
                  'date': data['entry_list'][0].date } )
    xml = tt_rss_body.render( dict )
    directory = os.path.join(config.get('output_dir', 'out'), 'rss')
    path = os.path.join(directory, 'index.xml')
    tools.mk_file(xml, {'title': 'rss/index.xml'}, path)
    
    return request
    
Example #3
0
def cb_page(request):
    """mostly identical to lilith._cb_page except of not displaying
    content which has translations and is not in default language."""
    
    config = request._config
    data = request._data
    data['type'] = 'page'
    ipp = config.get('items_per_page', 6)
    
    # last preparations
    request = tools.run_callback(
                'prepare',
                request)
    
    layout = config.get('layout_dir', 'layouts')
    tt_entry = Template(open(os.path.join(layout, 'entry.html')).read())
    tt_main = Template(open(os.path.join(layout, 'main.html')).read())
    
    dict = request._config
    entry_list = []
    for entry in data['entry_list']:
        if entry.get('identifier', False) and entry['lang'] != config['lang'][:2]:
            continue
        
        translations = filter(lambda e: e != entry and \
                e.get('identifier', '') == entry.get('identifier', False),
                data['entry_list'])
        entry['translations'] = translations    
        
        entrydict = dict.copy()
        entrydict.update(entry)
        entry_list.append(tt_entry.render(entrydict))
                
    for i, mem in enumerate([entry_list[x*ipp:(x+1)*ipp] for x in range(len(entry_list)/ipp+1)]):
        
        dict.update( {'entry_list': '\n'.join(mem), 'page': i+1,
                      'num_entries': len(entry_list)} )
        html = tt_main.render( dict )
        directory = os.path.join(config.get('output_dir', 'out'),
                         '' if i == 0 else 'page/%s' % (i+1))
        path = os.path.join(directory, 'index.html')
        tools.mk_file(html, {'title': 'page/%s' % (i+1)}, path)
        
    return request
Example #4
0
def cb_item(request):
    """Creates single full-length entry.  Looks like
    http://domain.tld/year/$lang/title/(index.html).
    
    required:
    entry.html -- layout of Post's entry
    main.html -- layout of the website
    """
    config = request._config
    data = request._data
    data['type'] = 'item'
    
    layout = config.get('layout_dir', 'layouts')
    tt_entry = Template(open(os.path.join(layout, 'entry.html')).read())
    tt_main = Template(open(os.path.join(layout, 'main.html')).read())

    # last preparations
    request = tools.run_callback(
            'prepare',
            request)
    
    dict = request._config
        
    for entry in data['entry_list']:

        translations = filter(lambda e: e != entry and \
                e.get('identifier', '') == entry.get('identifier', False),
                data['entry_list'])
        log.debug("%s's translations: %s" % (entry.title, repr(translations)))
        entry['translations'] = translations
                        
        entrydict = dict.copy()
        entrydict.update(entry)
        dict.update({'entry_list': tt_entry.render(entrydict) })
        html = tt_main.render( dict )
        
        directory = os.path.join(config.get('output_dir', 'out'),
                      str(entry.date.year),
                      entry['lang_dir'],
                      entry.safe_title)
        path = os.path.join(directory, 'index.html')
        tools.mk_file(html, entry, path)
    
    return request
Example #5
0
def _page(request):
    """Creates nicely paged listing of your posts.  First “Page” is the
    index.hml used to have this nice url: http://yourblog.com/ with a recent
    list of your (e.g. summarized) Posts. Other pages are enumerated to /page/n+1
    
    required:
    items_per_page -- posts displayed per page (defaults to 6)
    entry.html -- layout of Post's entry
    main.html -- layout of the website
    """
    config = request._config
    data = request._data
    data['type'] = 'page'
    ipp = config.get('items_per_page', 6)
    
    # last preparations
    request = tools.run_callback(
                'prepare',
                request)
    
    layout = config.get('layout_dir', 'layouts')
    tt_entry = Template(open(os.path.join(layout, 'entry.html')).read())
    tt_main = Template(open(os.path.join(layout, 'main.html')).read())
    
    dict = request._config
    entry_list = []
    for entry in data['entry_list']:
        entrydict = dict.copy()
        entrydict.update(entry)
        entry_list.append(tt_entry.render(entrydict))
                
    for i, mem in enumerate([entry_list[x*ipp:(x+1)*ipp] for x in range(len(entry_list)/ipp+1)]):
        
        dict.update( {'entry_list': '\n'.join(mem), 'page': i+1,
                      'num_entries': len(entry_list)} )
        html = tt_main.render( dict )
        directory = os.path.join(config.get('output_dir', 'out'),
                         '' if i == 0 else 'page/%s' % (i+1))
        path = os.path.join(directory, 'index.html')
        tools.mk_file(html, {'title': 'page/%s' % (i+1)}, path)
        
    return request
Example #6
0
def _item(request):
    """Creates single full-length entry.  Looks like
    http://yourblog.org/year/title/(index.html).
    
    required:
    entry.html -- layout of Post's entry
    main.html -- layout of the website
    """
    config = request._config
    data = request._data
    data['type'] = 'item'
    
    layout = config.get('layout_dir', 'layouts')
    tt_entry = Template(open(os.path.join(layout, 'entry.html')).read())
    tt_main = Template(open(os.path.join(layout, 'main.html')).read())

    # last preparations
    request = tools.run_callback(
                'prepare',
                request)
    
    dict = request._config
    entry_list = []
    
    for entry in data['entry_list']:
        entrydict = dict.copy()
        entrydict.update(entry)
        dict.update({'entry_list':tt_entry.render(entrydict) })
        html = tt_main.render( dict )
        
        directory = os.path.join(config.get('output_dir', 'out'),
                         str(entry.date.year),
                         entry.safe_title)
        path = os.path.join(directory, 'index.html')
        tools.mk_file(html, entry, path)
        
    return request