@@ -1986,38 +1986,27 @@ def scan_posts(self, really=False, ignore_quit=False, quiet=False):
1986
1986
sys .exit (1 )
1987
1987
signal ('scanned' ).send (self )
1988
1988
1989
- def generic_page_renderer (self , lang , post , filters , context = None ):
1990
- """Render post fragments to final HTML pages."""
1989
+ def generic_renderer (self , lang , output_name , template_name , filters , deps = [], uptodate_deps = [], pre_context = None , post_context = None , context_deps_remove = None , post_deps_dict = None ):
1990
+ """Helper function for rendering pages and post lists and other related pages."""
1991
1991
utils .LocaleBorg ().set_locale (lang )
1992
- context = context .copy () if context else {}
1993
- deps = post .deps (lang ) + \
1994
- self .template_system .template_deps (post .template_name )
1995
- deps .extend (utils .get_asset_path (x , self .THEMES ) for x in ('bundles' , 'parent' , 'engine' ))
1992
+
1993
+ deps += self .template_system .template_deps (template_name )
1996
1994
deps = list (filter (None , deps ))
1997
- context ['post' ] = post
1998
- context ['lang' ] = lang
1999
- context ['title' ] = post .title (lang )
2000
- context ['description' ] = post .description (lang )
2001
- context ['permalink' ] = post .permalink (lang )
2002
- if 'pagekind' not in context :
2003
- context ['pagekind' ] = ['generic_page' ]
2004
- if post .use_in_feeds :
2005
- context ['enable_comments' ] = True
2006
- else :
2007
- context ['enable_comments' ] = self .config ['COMMENTS_IN_STORIES' ]
2008
- extension = self .get_compiler (post .source_path ).extension ()
2009
- output_name = os .path .join (self .config ['OUTPUT_FOLDER' ],
2010
- post .destination_path (lang , extension ))
1995
+
1996
+ context = copy (pre_context ) if pre_context else {}
1997
+ context ["lang" ] = lang
1998
+ if post_context :
1999
+ context .update (post_context )
2000
+
2011
2001
deps_dict = copy (context )
2012
- deps_dict .pop ('post' )
2013
- if post .prev_post :
2014
- deps_dict ['PREV_LINK' ] = [post .prev_post .permalink (lang )]
2015
- if post .next_post :
2016
- deps_dict ['NEXT_LINK' ] = [post .next_post .permalink (lang )]
2002
+ if context_deps_remove :
2003
+ for key in context_deps_remove :
2004
+ deps_dict .pop (key )
2017
2005
deps_dict ['OUTPUT_FOLDER' ] = self .config ['OUTPUT_FOLDER' ]
2018
2006
deps_dict ['TRANSLATIONS' ] = self .config ['TRANSLATIONS' ]
2019
2007
deps_dict ['global' ] = self .GLOBAL_CONTEXT
2020
- deps_dict ['comments' ] = context ['enable_comments' ]
2008
+ if post_deps_dict :
2009
+ deps_dict .update (post_deps_dict )
2021
2010
2022
2011
for k , v in self .GLOBAL_CONTEXT ['template_hooks' ].items ():
2023
2012
deps_dict ['||template_hooks|{0}||' .format (k )] = v ._items
@@ -2027,62 +2016,83 @@ def generic_page_renderer(self, lang, post, filters, context=None):
2027
2016
2028
2017
deps_dict ['navigation_links' ] = deps_dict ['global' ]['navigation_links' ](lang )
2029
2018
2030
- if post :
2031
- deps_dict ['post_translations' ] = post .translated_to
2032
-
2033
2019
task = {
2034
2020
'name' : os .path .normpath (output_name ),
2035
- 'file_dep' : sorted (deps ),
2036
2021
'targets' : [output_name ],
2037
- 'actions' : [(self .render_template , [post .template_name ,
2038
- output_name , context ])],
2022
+ 'file_dep' : sorted (deps ),
2023
+ 'actions' : [(self .render_template , [template_name , output_name ,
2024
+ context ])],
2039
2025
'clean' : True ,
2040
- 'uptodate' : [config_changed (deps_dict , 'nikola.nikola.Nikola.generic_page_renderer ' )] + post . deps_uptodate ( lang ),
2026
+ 'uptodate' : [config_changed (deps_dict , 'nikola.nikola.Nikola.generic_renderer ' )] + uptodate_deps
2041
2027
}
2042
2028
2043
- yield utils .apply_filters (task , filters )
2029
+ return utils .apply_filters (task , filters )
2030
+
2031
+ def generic_page_renderer (self , lang , post , filters , context = None ):
2032
+ """Render post fragments to final HTML pages."""
2033
+ extension = self .get_compiler (post .source_path ).extension ()
2034
+ output_name = os .path .join (self .config ['OUTPUT_FOLDER' ],
2035
+ post .destination_path (lang , extension ))
2036
+
2037
+ deps = post .deps (lang )
2038
+ uptodate_deps = post .deps_uptodate (lang )
2039
+ deps .extend (utils .get_asset_path (x , self .THEMES ) for x in ('bundles' , 'parent' , 'engine' ))
2040
+
2041
+ post_context = {}
2042
+ post_context ['post' ] = post
2043
+ post_context ['title' ] = post .title (lang )
2044
+ post_context ['description' ] = post .description (lang )
2045
+ post_context ['permalink' ] = post .permalink (lang )
2046
+ if 'pagekind' not in context :
2047
+ post_context ['pagekind' ] = ['generic_page' ]
2048
+ if post .use_in_feeds :
2049
+ post_context ['enable_comments' ] = True
2050
+ else :
2051
+ post_context ['enable_comments' ] = self .config ['COMMENTS_IN_STORIES' ]
2052
+
2053
+ deps_dict = {}
2054
+ if post .prev_post :
2055
+ deps_dict ['PREV_LINK' ] = [post .prev_post .permalink (lang )]
2056
+ if post .next_post :
2057
+ deps_dict ['NEXT_LINK' ] = [post .next_post .permalink (lang )]
2058
+ deps_dict ['comments' ] = post_context ['enable_comments' ]
2059
+ if post :
2060
+ deps_dict ['post_translations' ] = post .translated_to
2061
+
2062
+ yield self .generic_renderer (lang , output_name , post .template_name , filters ,
2063
+ deps = deps ,
2064
+ uptodate_deps = uptodate_deps ,
2065
+ pre_context = context ,
2066
+ post_context = post_context ,
2067
+ context_deps_remove = ['post' ],
2068
+ post_deps_dict = deps_dict )
2044
2069
2045
- def generic_post_list_renderer (self , lang , posts , output_name ,
2046
- template_name , filters , extra_context ):
2070
+ def generic_post_list_renderer (self , lang , posts , output_name , template_name , filters , extra_context ):
2047
2071
"""Render pages with lists of posts."""
2048
2072
deps = []
2049
- deps += self .template_system .template_deps (template_name )
2050
2073
uptodate_deps = []
2051
2074
for post in posts :
2052
2075
deps += post .deps (lang )
2053
2076
uptodate_deps += post .deps_uptodate (lang )
2054
- context = {}
2055
- context ["posts" ] = posts
2056
- context ["title" ] = self .config ['BLOG_TITLE' ](lang )
2057
- context ["description" ] = self .config ['BLOG_DESCRIPTION' ](lang )
2058
- context ["lang" ] = lang
2059
- context ["prevlink" ] = None
2060
- context ["nextlink" ] = None
2061
- context .update (extra_context )
2062
- deps_context = copy (context )
2063
- deps_context ["posts" ] = [(p .meta [lang ]['title' ], p .permalink (lang )) for p in
2064
- posts ]
2065
- deps_context ["global" ] = self .GLOBAL_CONTEXT
2066
-
2067
- for k , v in self .GLOBAL_CONTEXT ['template_hooks' ].items ():
2068
- deps_context ['||template_hooks|{0}||' .format (k )] = v ._items
2069
-
2070
- for k in self ._GLOBAL_CONTEXT_TRANSLATABLE :
2071
- deps_context [k ] = deps_context ['global' ][k ](lang )
2072
2077
2073
- deps_context ['navigation_links' ] = deps_context ['global' ]['navigation_links' ](lang )
2074
-
2075
- task = {
2076
- 'name' : os .path .normpath (output_name ),
2077
- 'targets' : [output_name ],
2078
- 'file_dep' : sorted (deps ),
2079
- 'actions' : [(self .render_template , [template_name , output_name ,
2080
- context ])],
2081
- 'clean' : True ,
2082
- 'uptodate' : [config_changed (deps_context , 'nikola.nikola.Nikola.generic_post_list_renderer' )] + uptodate_deps
2083
- }
2084
-
2085
- return utils .apply_filters (task , filters )
2078
+ post_context = {}
2079
+ post_context ["posts" ] = posts
2080
+ post_context ["title" ] = self .config ['BLOG_TITLE' ](lang )
2081
+ post_context ["description" ] = self .config ['BLOG_DESCRIPTION' ](lang )
2082
+ post_context ["prevlink" ] = None
2083
+ post_context ["nextlink" ] = None
2084
+ if extra_context :
2085
+ post_context .update (extra_context )
2086
+
2087
+ post_deps_dict = {}
2088
+ post_deps_dict ["posts" ] = [(p .meta [lang ]['title' ], p .permalink (lang )) for p in
2089
+ posts ]
2090
+
2091
+ return self .generic_renderer (lang , output_name , template_name , filters ,
2092
+ deps = deps ,
2093
+ uptodate_deps = uptodate_deps ,
2094
+ post_context = post_context ,
2095
+ post_deps_dict = post_deps_dict )
2086
2096
2087
2097
def atom_feed_renderer (self , lang , posts , output_path , filters ,
2088
2098
extra_context ):
0 commit comments