80
80
81
81
# Default "Read more..." link
82
82
DEFAULT_INDEX_READ_MORE_LINK = '<p class="more"><a href="{link}">{read_more}…</a></p>'
83
- DEFAULT_RSS_READ_MORE_LINK = '<p><a href="{link}">{read_more}…</a> ({min_remaining_read})</p>'
83
+ DEFAULT_FEED_READ_MORE_LINK = '<p><a href="{link}">{read_more}…</a> ({min_remaining_read})</p>'
84
84
85
85
# Default pattern for translation files' names
86
86
DEFAULT_TRANSLATIONS_PATTERN = '{path}.{lang}.{ext}'
@@ -450,16 +450,17 @@ def __init__(self, **config):
450
450
'PRETTY_URLS' : False ,
451
451
'FUTURE_IS_NOW' : False ,
452
452
'INDEX_READ_MORE_LINK' : DEFAULT_INDEX_READ_MORE_LINK ,
453
- 'RSS_READ_MORE_LINK' : DEFAULT_RSS_READ_MORE_LINK ,
454
- 'RSS_LINKS_APPEND_QUERY' : False ,
455
453
'REDIRECTIONS' : [],
456
454
'ROBOTS_EXCLUSIONS' : [],
457
455
'GENERATE_ATOM' : False ,
456
+ 'FEED_TEASERS' : True ,
457
+ 'FEED_PLAIN' : False ,
458
+ 'FEED_PREVIEWIMAGE' : True ,
459
+ 'FEED_READ_MORE_LINK' : DEFAULT_FEED_READ_MORE_LINK ,
460
+ 'FEED_LINKS_APPEND_QUERY' : False ,
458
461
'GENERATE_RSS' : True ,
459
462
'RSS_LINK' : None ,
460
463
'RSS_PATH' : '' ,
461
- 'RSS_PLAIN' : False ,
462
- 'RSS_TEASERS' : True ,
463
464
'SASS_COMPILER' : 'sass' ,
464
465
'SASS_OPTIONS' : [],
465
466
'SEARCH_FORM' : '' ,
@@ -543,7 +544,7 @@ def __init__(self, **config):
543
544
'EXTRA_HEAD_DATA' ,
544
545
'NAVIGATION_LINKS' ,
545
546
'INDEX_READ_MORE_LINK' ,
546
- 'RSS_READ_MORE_LINK ' ,
547
+ 'FEED_READ_MORE_LINK ' ,
547
548
'INDEXES_TITLE' ,
548
549
'POSTS_SECTION_COLORS' ,
549
550
'POSTS_SECTION_DESCRIPTIONS' ,
@@ -608,6 +609,38 @@ def __init__(self, **config):
608
609
for i1 , i2 , i3 in self .config ['PAGES' ]:
609
610
self .config ['post_pages' ].append ([i1 , i2 , i3 , False ])
610
611
612
+ # RSS_TEASERS has been replaced with FEED_TEASERS
613
+ # TODO: remove on v8
614
+ if 'RSS_TEASERS' in config :
615
+ utils .LOGGER .warn ('The RSS_TEASERS option is deprecated, use FEED_TEASERS instead.' )
616
+ if 'FEED_TEASERS' in config :
617
+ utils .LOGGER .warn ('FEED_TEASERS conflicts with RSS_TEASERS, ignoring RSS_TEASERS.' )
618
+ self .config ['FEED_TEASERS' ] = config ['RSS_TEASERS' ]
619
+
620
+ # RSS_PLAIN has been replaced with FEED_PLAIN
621
+ # TODO: remove on v8
622
+ if 'RSS_PLAIN' in config :
623
+ utils .LOGGER .warn ('The RSS_PLAIN option is deprecated, use FEED_PLAIN instead.' )
624
+ if 'FEED_PLAIN' in config :
625
+ utils .LOGGER .warn ('FEED_PLIN conflicts with RSS_PLAIN, ignoring RSS_PLAIN.' )
626
+ self .config ['FEED_PLAIN' ] = config ['RSS_PLAIN' ]
627
+
628
+ # RSS_LINKS_APPEND_QUERY has been replaced with FEED_LINKS_APPEND_QUERY
629
+ # TODO: remove on v8
630
+ if 'RSS_LINKS_APPEND_QUERY' in config :
631
+ utils .LOGGER .warn ('The RSS_LINKS_APPEND_QUERY option is deprecated, use FEED_LINKS_APPEND_QUERY instead.' )
632
+ if 'FEED_TEASERS' in config :
633
+ utils .LOGGER .warn ('FEED_LINKS_APPEND_QUERY conflicts with RSS_LINKS_APPEND_QUERY, ignoring RSS_LINKS_APPEND_QUERY.' )
634
+ self .config ['FEED_LINKS_APPEND_QUERY' ] = utils .TranslatableSetting ('FEED_LINKS_APPEND_QUERY' , config ['RSS_LINKS_APPEND_QUERY' ], self .config ['TRANSLATIONS' ])
635
+
636
+ # RSS_READ_MORE_LINK has been replaced with FEED_READ_MORE_LINK
637
+ # TODO: remove on v8
638
+ if 'RSS_READ_MORE_LINK' in config :
639
+ utils .LOGGER .warn ('The RSS_READ_MORE_LINK option is deprecated, use FEED_READ_MORE_LINK instead.' )
640
+ if 'FEED_READ_MORE_LINK' in config :
641
+ utils .LOGGER .warn ('FEED_READ_MORE_LINK conflicts with RSS_READ_MORE_LINK, ignoring RSS_READ_MORE_LINK' )
642
+ self .config ['FEED_READ_MORE_LINK' ] = utils .TranslatableSetting ('FEED_READ_MORE_LINK' , config ['RSS_READ_MORE_LINK' ], self .config ['TRANSLATIONS' ])
643
+
611
644
# DEFAULT_TRANSLATIONS_PATTERN was changed from "p.e.l" to "p.l.e"
612
645
# TODO: remove on v8
613
646
if 'TRANSLATIONS_PATTERN' not in self .config :
@@ -1280,10 +1313,12 @@ def generic_rss_renderer(self, lang, title, link, description, timeline, output_
1280
1313
1281
1314
for post in timeline [:feed_length ]:
1282
1315
data = post .text (lang , teaser_only = rss_teasers , strip_html = rss_plain ,
1283
- rss_read_more_link = True , rss_links_append_query = feed_append_query )
1316
+ feed_read_more_link = True , feed_links_append_query = feed_append_query )
1284
1317
if feed_url is not None and data :
1285
1318
# Massage the post's HTML (unless plain)
1286
1319
if not rss_plain :
1320
+ if self .config ["FEED_PREVIEWIMAGE" ] and 'previewimage' in post .meta [lang ] and post .meta [lang ]['previewimage' ] not in data :
1321
+ data = "<figure><img src=\" {}\" ></figure> {}" .format (post .meta [lang ]['previewimage' ], data )
1287
1322
# FIXME: this is duplicated with code in Post.text()
1288
1323
try :
1289
1324
doc = lxml .html .document_fromstring (data )
@@ -1835,8 +1870,6 @@ def atom_link(link_rel, link_type, link_href):
1835
1870
nslist = {}
1836
1871
if context ["is_feed_stale" ] or "feedpagenum" in context and (not context ["feedpagenum" ] == context ["feedpagecount" ] - 1 and not context ["feedpagenum" ] == 0 ):
1837
1872
nslist ["fh" ] = "http://purl.org/syndication/history/1.0"
1838
- if not self .config ["RSS_TEASERS" ]:
1839
- nslist ["xh" ] = "http://www.w3.org/1999/xhtml"
1840
1873
feed_xsl_link = self .abs_link ("/assets/xml/atom.xsl" )
1841
1874
feed_root = lxml .etree .Element ("feed" , nsmap = nslist )
1842
1875
feed_root .addprevious (lxml .etree .ProcessingInstruction (
@@ -1881,31 +1914,45 @@ def atom_link(link_rel, link_type, link_href):
1881
1914
feed_generator .text = "Nikola"
1882
1915
1883
1916
feed_append_query = None
1884
- if self .config ["RSS_LINKS_APPEND_QUERY " ]:
1885
- feed_append_query = self .config ["RSS_LINKS_APPEND_QUERY " ].format (
1917
+ if self .config ["FEED_LINKS_APPEND_QUERY " ]:
1918
+ feed_append_query = self .config ["FEED_LINKS_APPEND_QUERY " ].format (
1886
1919
feedRelUri = context ["feedlink" ],
1887
1920
feedFormat = "atom" )
1888
1921
1889
- for post in posts :
1890
- data = post .text (lang , teaser_only = self .config ["RSS_TEASERS" ], strip_html = self .config ["RSS_TEASERS" ],
1891
- rss_read_more_link = True , rss_links_append_query = feed_append_query )
1892
- if not self .config ["RSS_TEASERS" ]:
1922
+ def atom_post_text (post , text ):
1923
+ if not self .config ["FEED_PLAIN" ]:
1924
+ if self .config ["FEED_PREVIEWIMAGE" ] and 'previewimage' in post .meta [lang ] and post .meta [lang ]['previewimage' ] not in text :
1925
+ text = "<figure><img src=\" {}\" ></figure> {}" .format (post .meta [lang ]['previewimage' ], text )
1926
+
1893
1927
# FIXME: this is duplicated with code in Post.text() and generic_rss_renderer
1894
1928
try :
1895
- doc = lxml .html .document_fromstring (data )
1929
+ doc = lxml .html .document_fromstring (text )
1896
1930
doc .rewrite_links (lambda dst : self .url_replacer (post .permalink (lang ), dst , lang , 'absolute' ))
1897
1931
try :
1898
1932
body = doc .body
1899
- data = (body .text or '' ) + '' .join (
1933
+ text = (body .text or '' ) + '' .join (
1900
1934
[lxml .html .tostring (child , encoding = 'unicode' )
1901
1935
for child in body .iterchildren ()])
1902
1936
except IndexError : # No body there, it happens sometimes
1903
- data = ''
1937
+ text = ''
1904
1938
except lxml .etree .ParserError as e :
1905
1939
if str (e ) == "Document is empty" :
1906
- data = ""
1940
+ text = ""
1907
1941
else : # let other errors raise
1908
1942
raise (e )
1943
+ return text
1944
+
1945
+ for post in posts :
1946
+ summary = atom_post_text (post , post .text (lang , teaser_only = True ,
1947
+ strip_html = self .config ["FEED_PLAIN" ],
1948
+ feed_read_more_link = True ,
1949
+ feed_links_append_query = feed_append_query ))
1950
+ content = None
1951
+ if not self .config ["FEED_TEASERS" ]:
1952
+ content = atom_post_text (post , post .text (lang , teaser_only = self .config ["FEED_TEASERS" ],
1953
+ strip_html = self .config ["FEED_PLAIN" ],
1954
+ feed_read_more_link = True ,
1955
+ feed_links_append_query = feed_append_query ))
1909
1956
1910
1957
entry_root = lxml .etree .SubElement (feed_root , "entry" )
1911
1958
entry_title = lxml .etree .SubElement (entry_root , "title" )
@@ -1922,14 +1969,19 @@ def atom_link(link_rel, link_type, link_href):
1922
1969
entry_root .append (atom_link ("alternate" , "text/html" ,
1923
1970
post .permalink (lang , absolute = True ,
1924
1971
query = feed_append_query )))
1925
- if self . config [ "RSS_TEASERS" ]:
1926
- entry_summary = lxml . etree . SubElement ( entry_root , "summary" )
1927
- entry_summary .text = data
1972
+ entry_summary = lxml . etree . SubElement ( entry_root , "summary" )
1973
+ if not self . config [ "FEED_PLAIN" ]:
1974
+ entry_summary .set ( "type" , "html" )
1928
1975
else :
1976
+ entry_summary .set ("type" , "text" )
1977
+ entry_summary .text = summary
1978
+ if content :
1929
1979
entry_content = lxml .etree .SubElement (entry_root , "content" )
1930
- entry_content .set ("type" , "xhtml" )
1931
- entry_content_nsdiv = lxml .etree .SubElement (entry_content , "{http://www.w3.org/1999/xhtml}div" )
1932
- entry_content_nsdiv .text = data
1980
+ if not self .config ["FEED_PLAIN" ]:
1981
+ entry_content .set ("type" , "html" )
1982
+ else :
1983
+ entry_content .set ("type" , "text" )
1984
+ entry_content .text = content
1933
1985
for category in post .tags_for_language (lang ):
1934
1986
entry_category = lxml .etree .SubElement (entry_root , "category" )
1935
1987
entry_category .set ("term" , utils .slugify (category ))
@@ -1980,8 +2032,7 @@ def generic_index_renderer(self, lang, posts, indexes_title, template_name, cont
1980
2032
kw ['indexes_prety_page_url' ] = self .config ["INDEXES_PRETTY_PAGE_URL" ]
1981
2033
kw ['demote_headers' ] = self .config ['DEMOTE_HEADERS' ]
1982
2034
kw ['generate_atom' ] = self .config ["GENERATE_ATOM" ]
1983
- kw ['feed_link_append_query' ] = self .config ["RSS_LINKS_APPEND_QUERY" ]
1984
- kw ['feed_teasers' ] = self .config ["RSS_TEASERS" ]
2035
+ kw ['feed_link_append_query' ] = self .config ["FEED_LINKS_APPEND_QUERY" ]
1985
2036
kw ['currentfeed' ] = None
1986
2037
1987
2038
# Split in smaller lists
@@ -2072,6 +2123,9 @@ def generic_index_renderer(self, lang, posts, indexes_title, template_name, cont
2072
2123
context ["currentfeedlink" ] = kw ["currentfeed" ]
2073
2124
context ["feedpagenum" ] = i
2074
2125
context ["feedpagecount" ] = num_pages
2126
+ kw ['feed_teasers' ] = self .config ['FEED_TEASERS' ]
2127
+ kw ['feed_plain' ] = self .config ['FEED_PLAIN' ]
2128
+ kw ['feed_previewimage' ] = self .config ['FEED_PREVIEWIMAGE' ]
2075
2129
atom_task = {
2076
2130
"basename" : basename ,
2077
2131
"name" : atom_output_name ,
0 commit comments