Ejemplo n.º 1
0
def render_indexes(articles):
    """"""
    cats = {}
    article = None
    for article in articles:
        if article.category not in cats:
            cats[article.category] = []
        cats[article.category].append(article)
        if "/" in article.category:
            rootcat = article.category.split("/")[0]
            if rootcat not in cats:
                cats[rootcat] = []
            cats[rootcat].append(article)
    del article
    for category, a in cats.iteritems():
        if category == "":
            if not has_index(settings.BUILD_TARGET):
                template_engine.render_paginated("index",
                                                 "index.html",
                                                 a=articles,
                                                 articles=articles)
            render_feed(articles, category)
        elif not has_index(settings.BUILD_TARGET + "/" + category):
            description = None
            if os.path.exists("_doc/%s.category.html" % category):
                description = open("_doc/%s.category.html" %
                                   category).read().decode("UTF-8")
            template_engine.render_paginated("category",
                                             category + "/index.html",
                                             **locals())
            render_feed(a, category)
Ejemplo n.º 2
0
def render_indexes(articles):
    """"""
    cats = {}
    article = None
    for article in articles:
        if article.category not in cats:
            cats[article.category] = []
        cats[article.category].append(article)
        if "/" in article.category:
            rootcat = article.category.split("/")[0]
            if rootcat not in cats:
                cats[rootcat] = []
            cats[rootcat].append(article)
    del article
    for category, a in cats.iteritems():
        if category == "":
            if not has_index(settings.BUILD_TARGET):
                template_engine.render_paginated("index", "index.html",
                                                a=articles, articles=articles)
            render_feed(articles, category)
        elif not has_index(settings.BUILD_TARGET+"/"+category):
            description = None
            if os.path.exists("_doc/%s.category.html" % category):
                description = open("_doc/%s.category.html" % category).read().decode("UTF-8")
            template_engine.render_paginated("category", category+
                            "/index.html", **locals())
            render_feed(a, category)
Ejemplo n.º 3
0
def build(my_settings=None):
    """Build the final website"""
    if my_settings is not None:
        settings.extend(**my_settings)
    fire_hook("build.start")
    load_plugins()
    settings.ORIG_BUILD_TARGET = settings.BUILD_TARGET.rstrip("/")
    settings.BUILD_TARGET = os.path.abspath(settings.BUILD_TARGET)
    copy_statics()
    all_articles = get_articles()
    articles = [a for a in all_articles \
                if "noref" not in a.headers.status]
    articles.sort()
    template_engine.set_articles(articles)
    for article in all_articles:
        article.save(articles=articles)
    render(articles)
    for template in get_templates():
        template_engine.render_template(template,
                template.replace(".mako", ".html"), a=articles, articles=articles)
    if not glob.glob(settings.BUILD_TARGET+"/index.html*") and \
       not glob.glob(settings.BUILD_TARGET+"/index.xhtml*"):
        template_engine.render_paginated("index", "index.html",
                                         a=articles, articles=articles)
    if not os.path.isfile(settings.BUILD_TARGET+"/feed.xml"):
        render_feed(articles)
    template_engine.render_sitemap()
    template_engine.make_index()
    fire_hook("build.end")
    return 0
Ejemplo n.º 4
0
def render_tags(articles):
    """"""
    tags = {}
    article = None
    for article in articles:
        a_tags = article.headers.get('SUBJECT', [])
        for a_tag in a_tags:
            if a_tag not in tags:
                tags[a_tag] = []
            tags[a_tag].append(article)
    del article
    for tag, a in tags.iteritems():
        description = None
        if os.path.exists("_doc/%s.tag.html" % tag):
            description = open("_doc/%s.tag.html" % category).read().decode("UTF-8")
        template_engine.render_paginated("tag", "tag/"+
                        tag+"/index.html", **locals())
        render_feed(a, "tag/%s" % tag, filter_langs=True)
Ejemplo n.º 5
0
def render_tags(articles):
    """"""
    tags = {}
    article = None
    for article in articles:
        a_tags = article.headers.get('SUBJECT', [])
        for a_tag in a_tags:
            if a_tag not in tags:
                tags[a_tag] = []
            tags[a_tag].append(article)
    del article
    for tag, a in tags.iteritems():
        description = None
        if os.path.exists("_doc/%s.tag.html" % tag):
            description = open("_doc/%s.tag.html" %
                               category).read().decode("UTF-8")
        template_engine.render_paginated("tag", "tag/" + tag + "/index.html",
                                         **locals())
        render_feed(a, "tag/%s" % tag, filter_langs=True)
Ejemplo n.º 6
0
def render_archives(articles):
    """"""
    dates = {}
    article = None
    for article in articles:
        d = article.headers['DATE'].strftime("%Y/%m")
        if d not in dates:
            dates[d] = []
        dates[d].append(article)
        y = article.headers['DATE'].strftime("%Y")
        if y not in dates:
            dates[y] = []
        dates[y].append(article)
    del article
    for xdate, a in dates.iteritems():
        if len(xdate) == 4:
            date = datetime(int(xdate), 12, 31)
        else:
            date = datetime(int(xdate[:4]), int(xdate[5:7]), 1)
        template_engine.render_paginated("archive", "archive/"+
                        xdate+"/index.html", **locals())
        render_feed(a, "archive/%s" % xdate)
Ejemplo n.º 7
0
def render_archives(articles):
    """"""
    dates = {}
    article = None
    for article in articles:
        d = article.headers['DATE'].strftime("%Y/%m")
        if d not in dates:
            dates[d] = []
        dates[d].append(article)
        y = article.headers['DATE'].strftime("%Y")
        if y not in dates:
            dates[y] = []
        dates[y].append(article)
    del article
    for xdate, a in dates.iteritems():
        if len(xdate) == 4:
            date = datetime(int(xdate), 12, 31)
        else:
            date = datetime(int(xdate[:4]), int(xdate[5:7]), 1)
        template_engine.render_paginated("archive",
                                         "archive/" + xdate + "/index.html",
                                         **locals())
        render_feed(a, "archive/%s" % xdate)