@@ -71,27 +71,23 @@ def on_config(self, config, **kwargs):
7171 # Check if 'hooks' is defined in the 'plugins' section
7272 if isinstance (config .get ("hooks" ), dict ):
7373 position_offset += len (config .get ("hooks" ))
74-
74+
7575 if print_site_position != len (plugins ) - position_offset :
7676 msg = "[mkdocs-print-site] 'print-site' should be defined as the *last* plugin,"
7777 msg += "to ensure the print page has any changes other plugins make."
7878 msg += "Please update the 'plugins:' section in your mkdocs.yml"
7979 logger .warning (msg )
8080
8181 if "--dirtyreload" in sys .argv :
82- msg = (
83- "[mkdocs-print-site] Note the 'print-site' page does render all pages "
84- )
82+ msg = "[mkdocs-print-site] Note the 'print-site' page does render all pages "
8583 msg += "when using the --dirtyreload option."
8684 logger .warning (msg )
8785
8886 # Get abs path to cover_page_template
8987 self .cover_page_template_path = ""
9088 if self .config .get ("add_cover_page" ):
9189 if self .config .get ("cover_page_template" ) == "" :
92- self .cover_page_template_path = os .path .join (
93- HERE , "templates" , "cover_page.tpl"
94- )
90+ self .cover_page_template_path = os .path .join (HERE , "templates" , "cover_page.tpl" )
9591 else :
9692 self .cover_page_template_path = os .path .join (
9793 os .path .dirname (config .get ("config_file_path" )),
@@ -101,17 +97,13 @@ def on_config(self, config, **kwargs):
10197 msg = "[print-site-plugin]: Path specified in 'cover_page_template' not found."
10298 msg += "\n Make sure to use the URL relative to your mkdocs.yml file."
10399 logger .warning (msg )
104- raise FileNotFoundError (
105- "File not found: %s" % self .cover_page_template_path
106- )
100+ raise FileNotFoundError ("File not found: %s" % self .cover_page_template_path )
107101
108102 # Get abs path to print_site_banner_template
109103 self .banner_template_path = ""
110104 if self .config .get ("add_print_site_banner" ):
111105 if self .config .get ("print_site_banner_template" ) == "" :
112- self .banner_template_path = os .path .join (
113- HERE , "templates" , "print_site_banner.tpl"
114- )
106+ self .banner_template_path = os .path .join (HERE , "templates" , "print_site_banner.tpl" )
115107 else :
116108 self .banner_template_path = os .path .join (
117109 os .path .dirname (config .get ("config_file_path" )),
@@ -121,9 +113,7 @@ def on_config(self, config, **kwargs):
121113 msg = "[print-site-plugin]: Path specified in 'print_site_banner_template' not found."
122114 msg += "\n Make sure to use the URL relative to your mkdocs.yml file."
123115 logger .warning (msg )
124- raise FileNotFoundError (
125- "File not found: %s" % self .banner_template_path
126- )
116+ raise FileNotFoundError ("File not found: %s" % self .banner_template_path )
127117
128118 # Add pointer to print-site javascript
129119 config ["extra_javascript" ] = ["js/print-site.js" ] + config ["extra_javascript" ]
@@ -146,7 +136,6 @@ def on_config(self, config, **kwargs):
146136
147137 config ["extra_css" ] = self .enum_css_files + config ["extra_css" ]
148138
149-
150139 # Create MkDocs Page and File instances
151140 self .print_file = File (
152141 path = self .config .get ("print_page_basename" ) + ".md" ,
@@ -217,9 +206,7 @@ def on_page_content(self, html, page, config, files, **kwargs):
217206 if is_external (pdf_url ):
218207 page .url_to_pdf = pdf_url
219208 else :
220- page .url_to_pdf = get_relative_url (
221- pdf_url , page .file .url
222- )
209+ page .url_to_pdf = get_relative_url (pdf_url , page .file .url )
223210
224211 return html
225212
@@ -262,11 +249,14 @@ def on_template_context(self, context, template_name, config, **kwargs):
262249 if template_name == "404.html" :
263250 self .context = context
264251 # Make sure paths are OK
265- if config .get ('extra_css' ):
266- self .context ['extra_css' ] = [get_relative_url (f , self .print_page .file .url ) for f in config .get ('extra_css' )]
267- if config .get ('extra_javascript' ):
268- self .context ['extra_javascript' ] = [get_relative_url (str (f ), self .print_page .file .url ) for f in config .get ('extra_javascript' )]
269-
252+ if config .get ("extra_css" ):
253+ self .context ["extra_css" ] = [
254+ get_relative_url (f , self .print_page .file .url ) for f in config .get ("extra_css" )
255+ ]
256+ if config .get ("extra_javascript" ):
257+ self .context ["extra_javascript" ] = [
258+ get_relative_url (str (f ), self .print_page .file .url ) for f in config .get ("extra_javascript" )
259+ ]
270260
271261 def on_post_build (self , config , ** kwargs ):
272262 """
@@ -292,25 +282,19 @@ def on_post_build(self, config, **kwargs):
292282 # Add print-site.css
293283 css_output_base_path = os .path .join (config ["site_dir" ], "css" )
294284 css_file_path = os .path .join (css_output_base_path , "print-site.css" )
295- copy_file (
296- os .path .join (os .path .join (HERE , "css" ), "print-site.css" ), css_file_path
297- )
285+ copy_file (os .path .join (os .path .join (HERE , "css" ), "print-site.css" ), css_file_path )
298286
299287 # Add enumeration css
300288 for f in self .enum_css_files :
301289 f = f .replace ("/" , os .sep )
302290 css_file_path = os .path .join (config ["site_dir" ], f )
303- copy_file (
304- os .path .join (HERE , f ), css_file_path
305- )
291+ copy_file (os .path .join (HERE , f ), css_file_path )
306292
307293 # Add theme CSS file
308294 css_file = "print-site-%s.css" % get_theme_name (config )
309295 if css_file in os .listdir (os .path .join (HERE , "css" )):
310296 css_file_path = os .path .join (css_output_base_path , css_file )
311- copy_file (
312- os .path .join (os .path .join (HERE , "css" ), css_file ), css_file_path
313- )
297+ copy_file (os .path .join (os .path .join (HERE , "css" ), css_file ), css_file_path )
314298
315299 # Combine the HTML of all pages present in the navigation
316300 self .print_page .content , self .print_page .toc = self .renderer .write_combined ()
@@ -325,38 +309,30 @@ def on_post_build(self, config, **kwargs):
325309
326310 # Remove lazy loading attributes from images
327311 # https://regex101.com/r/HVpKPs/1
328- html = re .sub (r"(\<img.+)(loading=\"lazy\")" , r"\1" , html )
312+ html = re .sub (r"(\<img.+)(loading=\"lazy\")" , r"\1" , html )
329313
330314 # Compatiblity with mkdocs-chart-plugin
331315 # As this plugin adds some javascript to every page
332316 # It should be included in the print site also
333317 if config .get ("plugins" , {}).get ("charts" ):
334- html = (
335- config .get ("plugins" , {})
336- .get ("charts" )
337- .add_javascript_variables (html , self .print_page , config )
338- )
318+ html = config .get ("plugins" , {}).get ("charts" ).add_javascript_variables (html , self .print_page , config )
339319
340320 # Compatibility with mkdocs-drawio
341321 # As this plugin adds renderer html for every drawio diagram
342322 # referenced in your markdown files. This rendering happens
343323 # in the on_post_page event, which is skipped by this plugin
344- # therefore we need to manual execute the drawio plugin renderer here.
324+ # therefore we need to manual execute the drawio plugin renderer here.
345325 if config .get ("plugins" , {}).get ("drawio" ):
346- html = (
347- config .get ("plugins" , {})
348- .get ("drawio" )
349- .render_drawio_diagrams (html , self .print_page )
350- )
326+ html = config .get ("plugins" , {}).get ("drawio" ).render_drawio_diagrams (html , self .print_page )
351327
352328 # Compatibility with https://github.com/g-provost/lightgallery-markdown
353329 # This plugin insert link hrefs with double dashes, f.e.
354330 # <link href="//assets/css/somecss.css">
355331 # Details https://github.com/timvink/mkdocs-print-site-plugin/issues/68
356332 htmls = html .split ("</head>" )
357333 base_url = "../" if config .get ("use_directory_urls" ) else ""
358- htmls [0 ] = htmls [0 ].replace (" href=\ " //" , f" href=\ "{ base_url } " )
359- htmls [0 ] = htmls [0 ].replace (" src=\ " //" , f" src=\ "{ base_url } " )
334+ htmls [0 ] = htmls [0 ].replace (' href="//' , f' href="{ base_url } ' )
335+ htmls [0 ] = htmls [0 ].replace (' src="//' , f' src="{ base_url } ' )
360336 html = "</head>" .join (htmls )
361337
362338 # Determine calls to required javascript functions
@@ -379,7 +355,4 @@ def on_post_build(self, config, **kwargs):
379355 html = html .replace ("</head>" , print_site_js + "</head>" )
380356
381357 # Write the print_page file to the output folder
382- write_file (
383- html .encode ("utf-8" , errors = "xmlcharrefreplace" ),
384- self .print_page .file .abs_dest_path
385- )
358+ write_file (html .encode ("utf-8" , errors = "xmlcharrefreplace" ), self .print_page .file .abs_dest_path )
0 commit comments