<%!
from datetime import datetime
WEEK_DAY = ("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
MONTH_DAY = ("Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

def format_rfc822_date(dt, localtime=True):
    if localtime:
        dt = dt - datetime.timedelta(hours=8)
    return "%s, %02d %s %04d %02d:%02d:%02d GMT" % (
        WEEK_DAY[dt.weekday()],
        dt.day,
        MONTH_DAY[dt.month-1],
        dt.year, dt.hour, dt.minute, dt.second
    )
%>
<%
items = G.items
pubdate = items and items[0]['pubdate']
pubdate = pubdate and format_rfc822_date(pubdate)
desc = G.rss_desc
%>

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>\
    <language>zh-cn</language>\
    <title>${G.rss_title}</title>\
    <link>${G.rss_link}</link>\
    %if desc:
    <description>${desc}</description>\
    %endif
    %if pubdate:
    <pubDate>${pubdate}</pubDate>\
    %endif
    %if items:
        %for i in items:
            <item>\
                <title>${i['title']}</title>\
                <link>${i['link']}</link>\
                <dc:creator>${i['author']}</dc:creator>\
                <description><![CDATA[${i['desc']}]]></description>\
                <pubDate>${format_rfc822_date(i['pubdate'])}</pubDate>\
                <guid isPermaLink="true">${i['link']}</guid>\
            </item>\
        %endfor
    %endif
</channel>\
</rss>