Skip to content

Commit 92e2b60

Browse files
committed
add a pdf export target
1 parent e198629 commit 92e2b60

7 files changed

Lines changed: 595 additions & 20 deletions

File tree

Taskfile.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,29 @@ tasks:
7474
cmds:
7575
- poetry run mkdocs serve
7676

77+
pdf:
78+
desc: Build a single PDF of the whole site via headless Chrome
79+
summary: |
80+
Builds the site (which exposes /print_page/ via mkdocs-print-site-plugin),
81+
then runs tools/build_pdf.py to serve it locally and print to PDF.
82+
83+
Tunables (env vars):
84+
CHROME - path to a Chromium-family binary
85+
(default: macOS Google Chrome.app)
86+
PORT - local port for the temporary http server
87+
(default: auto-picked free port)
88+
BUILD_VERSION - version stamped on the cover and folded into the
89+
default filename (default: {{.CURRENT_VERSION}})
90+
PDF_OUT - explicit output path; overrides the default
91+
(default: dist/documentation-eccenca-com-<ver>.pdf)
92+
deps:
93+
- task: install
94+
env:
95+
BUILD_VERSION: '{{.CURRENT_VERSION}}'
96+
cmds:
97+
- poetry run mkdocs build
98+
- poetry run python tools/build_pdf.py
99+
77100
use:public:
78101
desc: switch to public package (non insider)
79102
cmds:

docs/assets/extra.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,25 @@ img.bordered {
163163
margin-top: 0.125em;
164164
}
165165

166+
/**
167+
* Override mkdocs-print-site-plugin's @page footer styling.
168+
* The plugin sets `content: 'Page ' counter(page)` but no font-family or
169+
* font-size, so Chrome's print-to-pdf falls back to a large serif. Pin
170+
* Roboto and shrink to match body proportions.
171+
*/
172+
@page {
173+
@bottom-right {
174+
font-family: Roboto, "Helvetica Neue", Arial, sans-serif !important;
175+
font-size: 9pt !important;
176+
color: #666 !important;
177+
}
178+
@bottom-center {
179+
font-family: Roboto, "Helvetica Neue", Arial, sans-serif !important;
180+
font-size: 9pt !important;
181+
color: #666 !important;
182+
}
183+
}
184+
166185
/**
167186
* simplify layout for print:
168187
* - only use logo and page title from header
@@ -202,4 +221,12 @@ img.bordered {
202221
#__comments, .giscus {
203222
display: none !important;
204223
}
224+
/* hide cookie consent dialog + backdrops in PDF output */
225+
.md-consent,
226+
.md-consent__overlay,
227+
.md-overlay,
228+
[data-md-component="consent"],
229+
[data-md-component="dialog"] {
230+
display: none !important;
231+
}
205232
}

mkdocs.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,23 @@ plugins:
299299
'cmemc.md': 'automate/cmemc-command-line-interface/index.md'
300300
# https://squidfunk.github.io/mkdocs-material/reference/#built-in-meta-plugin
301301
- meta
302+
# https://timvink.github.io/mkdocs-print-site-plugin/
303+
# Combines all pages into a single /print_page/ — rendered to PDF by `task pdf`.
304+
# MUST remain the last plugin entry.
305+
- print-site:
306+
add_to_navigation: false
307+
print_page_title: "documentation.eccenca.com"
308+
add_print_site_banner: false
309+
add_table_of_contents: true
310+
toc_title: "Table of contents"
311+
toc_depth: 3
312+
add_full_urls: false
313+
enumerate_headings: false
314+
enumerate_figures: false
315+
add_cover_page: true
316+
cover_page_template: "overrides/print_cover.html"
317+
include_css: true
318+
path_to_pdf: ""
302319
# }}}
303320

304321
# {{{ Less important mkdocs configuration

overrides/print_cover.html

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{# Cover page template for mkdocs-print-site-plugin.
2+
Rendered as the first page of /print_page/. Context exposes `config`. #}
3+
<style>
4+
.print-cover-page {
5+
page-break-after: always;
6+
break-after: page;
7+
height: 100vh;
8+
display: flex;
9+
flex-direction: column;
10+
justify-content: space-between;
11+
align-items: stretch;
12+
padding: 3cm 2.5cm;
13+
box-sizing: border-box;
14+
font-family: Roboto, "Helvetica Neue", Arial, sans-serif;
15+
color: #1a1a1a;
16+
}
17+
.print-cover-page__brand {
18+
display: flex;
19+
align-items: center;
20+
gap: 0.6em;
21+
}
22+
.print-cover-page__brand img {
23+
width: 1.8cm;
24+
height: 1.8cm;
25+
}
26+
.print-cover-page__brand span {
27+
font-size: 14pt;
28+
font-weight: 500;
29+
color: #555;
30+
}
31+
.print-cover-page__body {
32+
margin-top: 4cm;
33+
}
34+
.print-cover-page__title {
35+
font-size: 34pt;
36+
font-weight: 700;
37+
margin: 0 0 0.3em 0;
38+
line-height: 1.15;
39+
}
40+
.print-cover-page__subtitle {
41+
font-size: 16pt;
42+
color: #555;
43+
font-weight: 400;
44+
margin: 0;
45+
}
46+
.print-cover-page__rule {
47+
border: none;
48+
border-top: 3px solid #0a6cb2;
49+
width: 6cm;
50+
margin: 1.5cm 0 1cm 0;
51+
}
52+
.print-cover-page__edition {
53+
display: grid;
54+
grid-template-columns: auto 1fr;
55+
column-gap: 1.2em;
56+
row-gap: 0.3em;
57+
margin: 0;
58+
font-size: 11pt;
59+
}
60+
.print-cover-page__edition dt {
61+
color: #666;
62+
font-weight: 500;
63+
}
64+
.print-cover-page__edition dd {
65+
margin: 0;
66+
color: #1a1a1a;
67+
}
68+
.print-cover-page__meta {
69+
font-size: 10pt;
70+
color: #666;
71+
line-height: 1.5;
72+
}
73+
.print-cover-page__meta a { color: inherit; text-decoration: none; }
74+
.print-cover-page__meta p { margin: 0.1em 0; }
75+
</style>
76+
77+
<article class="print-cover-page">
78+
<header class="print-cover-page__brand">
79+
<img src="../assets/favicon.svg" alt="">
80+
<span>eccenca</span>
81+
</header>
82+
83+
<section class="print-cover-page__body">
84+
<h1 class="print-cover-page__title">{{ config.site_name }}</h1>
85+
<p class="print-cover-page__subtitle">Corporate Memory Documentation</p>
86+
<hr class="print-cover-page__rule">
87+
<dl class="print-cover-page__edition">
88+
<dt>Version</dt>
89+
<dd><span id="print-cover-version">unset</span></dd>
90+
<dt>Generated</dt>
91+
<dd><span id="print-cover-date">unset</span></dd>
92+
</dl>
93+
</section>
94+
95+
<footer class="print-cover-page__meta">
96+
<p><a href="{{ config.site_url }}">{{ config.site_url }}</a></p>
97+
<p>{{ config.copyright | safe }}</p>
98+
</footer>
99+
</article>

0 commit comments

Comments
 (0)