<s> '''<STR_LIT>''' <EOL> import email . utils <EOL> import time <EOL> import pyquery <EOL> from tinkerer . ext import patch <EOL> def remove_header_link ( body ) : <EOL> """<STR_LIT>""" <EOL> doc = pyquery . PyQuery ( body ) <EOL> doc . remove ( '<STR_LIT>' ) <EOL> body = doc . html ( ) <EOL> return body <EOL> def add_rss ( app , context ) : <EOL> '''<STR_LIT>''' <EOL> context [ "<STR_LIT>" ] = app . config . rss_service <EOL> def generate_feed ( app ) : <EOL> '''<STR_LIT>''' <EOL> env = app . builder . env <EOL> if not env . blog_posts : <EOL> return <EOL> posts = env . blog_posts <EOL> if app . config . rss_max_items > <NUM_LIT:0> : <EOL> posts = posts [ : app . config . rss_max_items ] <EOL> context = make_feed_context ( app , None , posts ) <EOL> yield ( "<STR_LIT>" , context , "<STR_LIT>" ) <EOL> def make_feed_context ( app , feed_name , posts ) : <EOL> env = app . builder . env <EOL> context = dict ( ) <EOL> context [ "<STR_LIT>" ] = [ ] <EOL> for post in posts : <EOL> link = "<STR_LIT>" % ( app . config . website , post ) <EOL> timestamp = email . utils . formatdate ( <EOL> time . mktime ( env . blog_metadata [ post ] . date . timetuple ( ) ) , <EOL> localtime = True ) <EOL> categories = [ category [ <NUM_LIT:1> ] for category in <EOL> env . blog_metadata [ post ] . filing [ "<STR_LIT>" ] ] <EOL> description = patch . strip_xml_declaration ( <EOL> patch . patch_links ( <EOL> env . blog_metadata [ post ] . body , <EOL> app . config . website + post [ : <NUM_LIT:11> ] , <EOL> post [ <NUM_LIT:11> : ] , <EOL> replace_read_more_link = not app . config . rss_generate_full_posts , <EOL> ) , <EOL> ) <EOL> description = remove_header_link ( description ) <EOL> context [ "<STR_LIT>" ] . append ( { <EOL> "<STR_LIT:title>" : env . titles [ post ] . astext ( ) , <EOL> "<STR_LIT>" : link , <EOL> "<STR_LIT:description>" : description , <EOL> "<STR_LIT>" : categories , <EOL> "<STR_LIT>" : timestamp <EOL> } ) <EOL> if feed_name : <EOL> context [ "<STR_LIT:title>" ] = "<STR_LIT>" % ( app . config . project , feed_name ) <EOL> else : <EOL> context [ "<STR_LIT:title>" ] = app . config . project <EOL> context [ "<STR_LIT>" ] = app . config . website <EOL> context [ "<STR_LIT>" ] = app . config . tagline <EOL> context [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> if context [ '<STR_LIT>' ] : <EOL> context [ "<STR_LIT>" ] = context [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] <EOL> return context </s>
