示例#1
0
def blog():
    filter_tag = request.args.get("tag")

    if filter_tag:
        l = list(filter(lambda x: filter_tag in x[1]["tags"], blog_list.items()))
    else:
        l = blog_list.items()

    blog_tuples = sorted(l, key=lambda item: item[1]["published_time"], reverse=True)
    return render_template(
        "blog.html",
        title="Blog",
        description="Sometimes I have thoughts",
        blog_tuples=blog_tuples,
        filter_tag=filter_tag,
    )
示例#2
0
def rss():
    items = []
    last_update_date = datetime(1970, 1, 1, 0, 0, 0, tzinfo=timezone("UTC"))
    now = datetime.now(tz=timezone("UTC"))

    for art_id, art_meta in art_list.items():
        date = art_meta["published_time"]

        if date > last_update_date:
            last_update_date = date

        meta = {"title": art_meta["title"], "url": url_for("art_by_id", art_id=art_id), "date": date}

        if (now - date).days <= 30:  # pragma: no cover
            items.append(meta)

    for blog_id, blog_meta in blog_list.items():
        date = blog_meta["published_time"]

        if date > last_update_date:
            last_update_date = date

        meta = {"title": blog_meta["title"], "url": url_for("blog_by_id", blog_id=blog_id), "date": date}

        if (now - date).days <= 30:  # pragma: no cover
            items.append(meta)

    items = sorted(items, key=lambda item: item["date"], reverse=True)

    for item in items:
        item["date"] = item["date"].strftime("%a, %d %b %Y %H:%M:%S %z")

    resp = Response(
        render_template("rss.xml", items=items, last_update_date=last_update_date.strftime("%a, %d %b %Y %H:%M:%S %z")),
        mimetype="application/rss+xml",
    )
    return resp