Skip to content

Commit

Permalink
Fix bug when using --dirtyreload, see #57
Browse files Browse the repository at this point in the history
  • Loading branch information
timvink committed Oct 7, 2021
1 parent 0b164d8 commit 971e375
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 16 additions & 5 deletions mkdocs_print_site_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def on_page_content(self, html, page, config, files, **kwargs):

return html

def on_page_context(self, context, page, config, nav):
def on_page_context(self, context, page, config, nav, **kwargs):
"""
The page_context event is called after the context for a page is created.
Expand All @@ -197,16 +197,27 @@ def on_page_context(self, context, page, config, nav):
if not self.config.get("enabled"):
return

# Save relative link to print page
# This can be used to customize a theme and add a print button to each page
page.url_to_print_page = self.print_file.url_relative_to(page.file)


def on_template_context(self, context, template_name, config, **kwargs):
"""
The template_context event is called immediately after the context is created
for the subject template and can be used to alter the context for that specific template only.
See https://www.mkdocs.org/dev-guide/plugins/#on_template_context
"""
if not self.config.get("enabled"):
return
# Save the page context
# We'll use the same context of the last rendered page
# And apply it to the print page as well (in on_post_build event)
self.context = context

# Save relative link to print page
# This can be used to customize a theme and add a print button to each page
page.url_to_print_page = self.print_file.url_relative_to(page.file)

def on_post_build(self, config):
def on_post_build(self, config, **kwargs):
"""
The post_build event does not alter any variables. Use this event to call post-build scripts.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name="mkdocs-print-site-plugin",
version="2.0.1",
version="2.0.2",
description="MkDocs plugin that combines all pages into one, allowing for easy export to PDF and standalone HTML.",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 971e375

Please sign in to comment.