Skip to content

Commit 9dfd0f2

Browse files
committed
Prep first release and blacken code
1 parent c27a9d8 commit 9dfd0f2

File tree

4 files changed

+35
-27
lines changed

4 files changed

+35
-27
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
# mkdocs-print-site-plugin
1010

11-
> ⚠️ **This plugin is under development and the first version has not yet been released. Expected end of August :)**
12-
1311
[MkDocs](https://www.mkdocs.org/) plugin that adds a page to your site combining all pages, allowing your site visitors to *File > Print > Save as PDF* the entire site.
1412

1513
## Features :star2:

mkdocs_print_site_plugin/plugin.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,35 @@ class PrintSitePlugin(BasePlugin):
2424

2525
def on_config(self, config, **kwargs):
2626

27-
# Because other plugins can alter the navigation
27+
# Because other plugins can alter the navigation
2828
# (and thus which pages should be in the print page)
2929
# it is important 'print-site' is defined last in the 'plugins'
30-
plugins = config.get('plugins')
31-
print_site_position = [*dict(plugins)].index('print-site')
30+
plugins = config.get("plugins")
31+
print_site_position = [*dict(plugins)].index("print-site")
3232
if print_site_position != len(plugins) - 1:
33-
warnings.warn("[mkdocs-print-site] 'print-site' should be defined as the *last* plugin, to ensure the print page has any changes other plugins make. Please update the 'plugins:' section in your mkdocs.yml")
34-
33+
warnings.warn(
34+
"[mkdocs-print-site] 'print-site' should be defined as the *last* plugin, to ensure the print page has any changes other plugins make. Please update the 'plugins:' section in your mkdocs.yml"
35+
)
36+
3537
# Create the (empty) print page file in temp directory
3638
tmp_dir = tempfile.gettempdir()
3739
tmp_path = os.path.join(tmp_dir, "print_page.md")
3840
f = open(tmp_path, "w")
3941
f.write("")
4042
f.close()
4143
assert os.path.exists(tmp_path)
42-
44+
4345
self.print_file = File(
4446
path="print_page.md",
4547
src_dir=tmp_dir,
4648
dest_dir=config["site_dir"],
47-
use_directory_urls=config.get('use_directory_urls'),
49+
use_directory_urls=config.get("use_directory_urls"),
4850
)
4951

5052
# Insert 'print page' to the end of the nav, if it exists
5153
# We'll optionally remove the print page from navigation later on
5254
# Because when nav is not defined, all files incl print_page are part of the nav
53-
if config.get('nav'):
55+
if config.get("nav"):
5456
config.get("nav").append({"updated_later_on": "print_page.md"})
5557

5658
# Warn if we don't have CSS styles corresponding to current theme
@@ -72,7 +74,7 @@ def on_files(self, files, config, **kwargs):
7274
# This ensures we can capture all other page HTMLs
7375
# before inserting all of them into the print page.
7476
files.append(self.print_file)
75-
77+
7678
# Add all plugin CSS files to files directory
7779
# Note we only insert the relevant css files per theme into the print page file
7880
css_dest_dir = os.path.join(config["site_dir"], "css")
@@ -93,8 +95,8 @@ def on_nav(self, nav, config, files, **kwargs):
9395
# Save print file
9496
self.print_page = self.print_file.page
9597
self.print_page.title = self.config.get("print_page_title")
96-
self.print_page.edit_url = None # Ensure no edit icon on the print page.
97-
98+
self.print_page.edit_url = None # Ensure no edit icon on the print page.
99+
98100
# Save the (order of) pages in the navigation
99101
nav_pages = [p for p in nav.pages if p != self.print_page]
100102
self.renderer.pages = nav_pages

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
from setuptools import setup, find_packages
22

33
# Read README in UTF-8
4-
with open("README.md", 'r',encoding='UTF-8') as f:
4+
with open("README.md", "r", encoding="UTF-8") as f:
55
long_description = ""
66
for line in f:
77
long_description += line
88

99

1010
setup(
1111
name="mkdocs-print-site-plugin",
12-
version="0.0.1",
13-
description="Add print site page",
12+
version="0.1",
13+
description="MkDocs plugin that adds a page to your site combining all pages, allowing your site visitors to *File > Print > Save as PDF* the entire site.",
1414
long_description=long_description,
1515
long_description_content_type="text/markdown",
16-
keywords="mkdocs plugin",
16+
keywords="mkdocs plugin print pdf",
1717
url="https://github.com/timvink/mkdocs-print-site-plugin",
1818
author="Tim Vink",
1919
author_email="[email protected]",

tests/test_building.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def setup_clean_mkdocs_folder(mkdocs_yml_path, output_path):
4545
"""
4646

4747
assert os.path.exists(mkdocs_yml_path)
48-
48+
4949
testproject_path = output_path / "testproject"
5050

5151
# Create empty 'testproject' folder
@@ -78,7 +78,7 @@ def build_docs_setup(testproject_path):
7878

7979
cwd = os.getcwd()
8080
os.chdir(str(testproject_path))
81-
81+
8282
try:
8383
run = CliRunner().invoke(build_command, catch_exceptions=True)
8484
os.chdir(cwd)
@@ -93,8 +93,13 @@ def check_build(tmp_path, project_mkdocs, exit_code=0):
9393
"tests/fixtures/projects/%s" % project_mkdocs, tmp_path
9494
)
9595
result = build_docs_setup(tmp_proj)
96-
97-
msg = "cwd: %s, result: %s, exception: %s, exc_info: %s" % (os.getcwd(), result, result.exception, result.exc_info)
96+
97+
msg = "cwd: %s, result: %s, exception: %s, exc_info: %s" % (
98+
os.getcwd(),
99+
result,
100+
result.exception,
101+
result.exc_info,
102+
)
98103
assert result.exit_code == exit_code, msg
99104
return tmp_proj
100105

@@ -109,20 +114,23 @@ def text_in_page(tmp_proj, page_path, text):
109114
#### Tests ####
110115

111116

112-
113117
def test_add_to_nav_works(tmp_path):
114118
prj_path = check_build(tmp_path, "basic/mkdocs_addtonav_false.yml")
115-
119+
116120
# print page should not be in navigation
117-
assert not text_in_page(prj_path, "print_page/index.html", "class=\"nav-link\">Print Site</a>")
118-
121+
assert not text_in_page(
122+
prj_path, "print_page/index.html", 'class="nav-link">Print Site</a>'
123+
)
124+
119125

120126
def test_basic_build(tmp_path):
121127
prj_path = check_build(tmp_path, "basic/mkdocs.yml")
122128

123129
# Print page should be in the navigation
124-
assert text_in_page(prj_path, "print_page/index.html", "class=\"nav-link\">Print Site</a>")
125-
130+
assert text_in_page(
131+
prj_path, "print_page/index.html", 'class="nav-link">Print Site</a>'
132+
)
133+
126134
# Make sure all 3 pages are combined and present
127135
assert text_in_page(
128136
prj_path, "print_page/index.html", '<h1 id="index-homepage">Homepage'

0 commit comments

Comments
 (0)