Exemplo n.º 1
0
def index():
    """
    Render the homepage.
    """
    page = config.CACHE.get('view:index')
    if page:
        return page

    docs = manager.list('blog')[:4]
    page = template('index.html', docs=docs, **view_kwargs)

    config.CACHE.set('view:index', page, time=300)
    return page
Exemplo n.º 2
0
def blog_list(name='list_all'):
    """
    Blog index page

    Generates a list of posts in the blog. It can be filtered by channel.
    """
    page = config.CACHE.get('view:blog_list:%s' % name)
    if page:
        return page

    index_name = 'blog' if name == 'list_all' else 'blog_%s' % name
    docs = manager.list(index_name)
    page = template('blog_list.html', docs=docs, page=name, **view_kwargs)

    config.CACHE.set('view:blog_list:%s' % name, page, time=300)
    return page
Exemplo n.º 3
0
def series_list():
    """
    Blog series index page

    Generates a list of series in the blog.
    """
    page = config.CACHE.get('view:series_list')
    if page:
        return page

    series = manager.view('blog_series')
    series_data = {}
    for s in series:
        series_data[s] = manager.list('blog_series_%s' % s)
    page = template('series_list.html', series=series_data, page='series', **view_kwargs)

    config.CACHE.set('view:series_list', page, time=300)
    return page
Exemplo n.º 4
0
def blog_feed(name='list_all'):
    """
    Feed generation for the blog
    """
    index_name = 'blog' if name == 'list_all' else 'blog_%s' % name
    docs = manager.list(index_name)[:20]

    channel_name = 'All' if name == 'list_all' else name.title()
    title = "%s: %s Blog Posts" % (config.SITE_NAME, channel_name)
    description = title
    feed_url = config.SITE_BASE + 'feed' + ('' if name == 'list_all' else '/channel/' + name)

    feed = Feed(title, config.SITE_BASE, description, feed_url=feed_url,
        feed_guid=feed_url, feed_copyright=u'(c) Copyright 2012, Caleb Brown')

    for doc in docs:
        feed.add_item(doc.title, config.SITE_BASE + 'blog/' + doc.path,
            doc.render_body(), pubdate=doc.publish_on,
            unique_id='blog/' + doc.path)

    response.content_type = 'application/rss+xml; charset=utf-8'
    return feed.writeString('utf-8')
Exemplo n.º 5
0
    Blog detail page

    Renders a single blog post.
    """
    newpath = path.strip('/')
    if path != newpath:
        redirect('/blog/' + newpath)

    try:
        doc = manager.get('blog/%s' % path)
    except DocumentNotFound, e:
        abort(404)
    except DocumentMoved, e:
        redirect('/blog/' + e.location)

    docs = manager.list('blog')
    last_index = len(docs) - 1
    index = manager.index('blog').index('blog/%s' % path)
    prev = docs[index+1] if index < last_index else None
    next = docs[index-1] if index > 0 else None

    view_context = {
        'doc': doc,
        'latest': docs[0],
        'random': docs[random.randint(0, last_index)],
        'next': next,
        'prev': prev,
    }
    view_context.update(view_kwargs)

    return template('document.html', **view_context)