Skip to content

Commit 5b4d1c1

Browse files
authored
Validated print-site plugin for PDF (#769)
* Validated print-site plugin for PDF
1 parent b911d05 commit 5b4d1c1

11 files changed

+153
-41
lines changed

CONTRIBUTING.md

+16-9
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ There are several active versions of the documentation. Each version derives fro
3030

3131
Each version has a branch in the repository named accordingly:
3232

33-
- 11
34-
- 12
35-
- 13
33+
- 11 (EOL)
34+
- 12 (EOL)
35+
- 13 (EOL)
3636
- 14
3737
- 15
3838
- 16
39+
- 17
3940

4041
The source .md files are in the ``docs`` directory.
4142

@@ -146,14 +147,17 @@ The PDF document is in the ``site/pdf`` folder.
146147
```
147148

148149
6. To build the PDF documentation, do the following:
149-
- Install [mkdocs-with-pdf plugin](https://pypi.org/project/mkdocs-with-pdf/)
150+
- Install [mkdocs-print-site-plugin](https://timvink.github.io/mkdocs-print-site-plugin/index.html)
150151
- Run the following command
151152

152153
```sh
153154
mkdocs build -f mkdocs-pdf.yml
154155
```
155156

156-
The PDF document is in the ``site/pdf`` folder.
157+
This creates a single HTML page for the whole doc project. You can find the page at `site/print_page.html`.
158+
159+
7. Open the `site/print_page.html` in your browser and save as PDF. Depending on the browser, you may need to select the Export to PDF, Print - Save as PDF or just Save and select PDF as the output format.
160+
157161

158162
## Repository structure
159163

@@ -167,13 +171,16 @@ The repository includes the following directories and files:
167171
- `_images` - Images, logos and favicons
168172
- `css` - Styles
169173
- `js` - Javascript files
170-
- `_resource`:
171-
- `templates`:
174+
- `templates`:
172175
- ``styles.scss`` - Styling for PDF documents
173-
- `theme`:
176+
- `pdf_cover_page.tpl` - The PDF cover page template
177+
- `_resource`:
178+
- `overrides` - The directory with customized templates for HTML output
174179
- `main.html` - The layout template for hosting the documentation on Percona website
175-
- overrides - The folder with the Material theme template customization for builds
180+
- `_resourcepdf`:
181+
- `overrides` - The directory with customized layout templates for PDF
176182
- `.github`:
177183
- `workflows`:
178184
- `main.yml` - The workflow configuration for building documentation with a GitHub action. (The documentation is built with `mike` tool to a dedicated `publish` branch)
179185
- `site` - This is where the output HTML files are put after the build
186+
- `snippets` - The folder with pieces of documentation used in multiple places

_resourcepdf/overrides/404.html

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{#-
2+
This file was automatically generated - do not edit
3+
-#}
4+
{% extends "main.html" %}
5+
{% block content %}
6+
<h1>404 - Not found</h1>
7+
<p>
8+
We can't find the page you are looking for. Try using the Search or <a href= "{{ config.extra.homepage | d(nav.homepage.url, true) | url }}"> return to homepage </a>. </p>
9+
{% endblock %}

_resourcepdf/overrides/main.html

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{#
2+
MkDocs template for builds with Material theme to customize docs layout
3+
by adding marketing-requested elements
4+
#}
5+
6+
{# Import the theme's layout. #}
7+
{% extends "base.html" %}
8+
9+
10+
{% block site_nav %}
11+
{% if nav %}
12+
{% if page.meta and page.meta.hide %}
13+
{% set hidden = "hidden" if "navigation" in page.meta.hide %}
14+
{% endif %}
15+
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" {{ hidden }}>
16+
<div class="md-sidebar__scrollwrap">
17+
<div class="md-sidebar__inner">
18+
{% include "partials/nav.html" %}
19+
<br>
20+
<label class="md-nav__title" for="__drawer">
21+
<a href="https://learn.percona.com/download-manual-percona-distribution-for-postgresql-13" onclick="_gaq.push(['b._trackEvent', 'Percona Distribution for PostgreSQL', 'Download', 'Download Manual Distribution for PostgreSQL']);" class="md-nav__link md-nav__link--active" style="font-size: .7rem;">
22+
Download PDF
23+
</a>
24+
</label>
25+
</div>
26+
</div>
27+
</div>
28+
{% endif %}
29+
{% if "toc.integrate" not in features %}
30+
{% if page.meta and page.meta.hide %}
31+
{% set hidden = "hidden" if "toc" in page.meta.hide %}
32+
{% endif %}
33+
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" {{ hidden }}>
34+
<div class="md-sidebar__scrollwrap">
35+
<div class="md-sidebar__inner">
36+
{% include "partials/toc.html" %}
37+
</div>
38+
<div class="md-sidebar__inner">
39+
{% include "partials/banner.html" %}
40+
</div>
41+
</div>
42+
</div>
43+
{% endif %}
44+
{% endblock %}
45+
46+
{% block content%}
47+
48+
{{ super() }}
49+
50+
51+
<script>
52+
window.addEventListener('beforeprint', (event) => {
53+
for (const detailEl of document.querySelectorAll('details')) {
54+
if (detailEl.getAttribute('open') == null) {
55+
detailEl.setAttribute('data-was-closed', 'true')
56+
}
57+
detailEl.setAttribute('open', '')
58+
}
59+
})
60+
window.addEventListener('afterprint', (event) => {
61+
for (const detailEl of document.querySelectorAll('details')) {
62+
if (detailEl.getAttribute('data-was-closed') != null) {
63+
detailEl.removeAttribute('data-was-closed')
64+
detailEl.removeAttribute('open')
65+
}
66+
}
67+
})
68+
</script>
69+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<div data-banner="data-banner">
2+
<p><svg style="display:block;margin:-1em 0 0.75em" width="78" height="69" viewBox="0 0 78 69" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M56.7281 30.7666C62.6528 26.8938 64.5914 18.9942 61.0059 12.7854C59.2094 9.67113 56.3053 7.44082 52.8311 6.50951C49.6122 5.64535 46.2502 5.99872 43.2912 7.49366L39.251 0.5L30.8648 15.0245L11.4811 48.5937H67.021L56.7281 30.7666ZM51.881 10.0674C54.4064 10.7401 56.5079 12.3616 57.8168 14.6194C60.3895 19.0701 59.053 24.7153 54.8808 27.5665L45.1362 10.6905C47.2355 9.68104 49.6034 9.46087 51.881 10.0674ZM39.251 7.87125L60.6339 44.907H48.1228L32.9927 18.7102L39.2499 7.87235L39.251 7.87125ZM17.8682 44.907L30.8637 22.4035L43.8592 44.907H17.8682Z" fill="url(#paint0_linear_2899_1968)"></path><path style="fill:var(--md-typeset-color)" d="M4.981 64.943H3.157V68.207H.756V57.323H5.217C7.822 57.323 9.397 58.861 9.397 61.086V61.116C9.397 63.635 7.433 64.94 4.984 64.94L4.981 64.943V64.943ZM6.961 61.134C6.961 60.061 6.213 59.485 5.011 59.485H3.154V62.812H5.056C6.258 62.812 6.958 62.096 6.958 61.163V61.134H6.961ZM10.738 68.208V57.323H18.973V59.455H13.124V61.664H18.27V63.796H13.124V66.082H19.051V68.214H10.738V68.208 68.208ZM27.557 68.208 25.218 64.726H23.332V68.208H20.931V57.323H25.921C28.496 57.323 30.039 58.677 30.039 60.915V60.945C30.039 62.702 29.088 63.807 27.7 64.32L30.367 68.207H27.556L27.557 68.208ZM27.605 61.041C27.605 60.016 26.887 59.485 25.719 59.485H23.333V62.61H25.767C26.936 62.61 27.605 61.987 27.605 61.071V61.042 61.041ZM36.922 68.499C33.668 68.499 31.249 65.994 31.249 62.825V62.795C31.249 59.659 33.619 57.091 37.019 57.091 39.105 57.091 40.356 57.783 41.383 58.792L39.834 60.571C38.98 59.798 38.113 59.327 37.004 59.327 35.141 59.327 33.795 60.871 33.795 62.762V62.793C33.795 64.684 35.107 66.257 37.004 66.257 38.268 66.257 39.043 65.753 39.913 64.964L41.462 66.524C40.322 67.738 39.059 68.493 36.925 68.493L36.922 68.499ZM47.885 68.499C44.47 68.499 42.021 65.962 42.021 62.825V62.795C42.021 59.659 44.503 57.091 47.915 57.091 51.327 57.091 53.779 59.628 53.779 62.765V62.795C53.779 65.931 51.297 68.499 47.885 68.499ZM51.237 62.795C51.237 60.904 49.846 59.331 47.885 59.331 45.925 59.331 44.567 60.874 44.567 62.766V62.796C44.567 64.688 45.959 66.261 47.919 66.261 49.879 66.261 51.237 64.717 51.237 62.826V62.795 62.795ZM67.001 68.217 72.374 57.091 77.746 68.218H75.052L72.374 62.681 69.705 68.218H67.001V68.217ZM66.007 57.327V68.5L57.813 61.884V68.199H55.264V57.091L63.458 63.681V57.327H66.007Z"></path><defs><linearGradient id="paint0_linear_2899_1968" x1="18.1513" y1="44.7152" x2="61.4356" y2="20.9786" gradientUnits="userSpaceOnUse"><stop stop-color="#FC3519"></stop><stop offset="1" stop-color="#F0D136"></stop></linearGradient></defs></svg></p>
3+
<p>For help, click the link below to get free database assistance or contact our experts for personalized support.</p>
4+
5+
<div class="actions">
6+
7+
<a href="https://docs.percona.com/postgresql/13/get-help.html" style="color: var(--md-typeset-a-color);">Get help from Percona</a>
8+
</div>
9+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{#-
2+
This file was automatically generated - do not edit
3+
-#}
4+
<div class="md-copyright">
5+
<div class="md-copyright__highlight">
6+
<a href='https://percona.com' target='_blank'>Percona LLC and/or its affiliates, </a> &copy; {{ build_date_utc.strftime('%Y') }} — <a href="#" onclick="Osano.cm.showDrawer('osano-cm-dom-info-dialog-open')">Cookie Preferences</a>
7+
</div>
8+
{% if not config.extra.generator == false %}
9+
Made with
10+
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
11+
Material for MkDocs
12+
</a>
13+
{% endif %}
14+
</div>

docs/enable-extensions.md

-3
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ After the installation, enable the following option in `postgresql.conf` configu
136136
wal_level = logical
137137
```
138138

139-
<<<<<<< HEAD
140-
=======
141139
Start / restart the server to apply the changes.
142140

143141
## pgvector
@@ -148,7 +146,6 @@ To get started, enable the extension for the database where you want to use it:
148146
CREATE EXTENSION vector;
149147
```
150148

151-
>>>>>>> 7845a94c... PG-1214 Documented install and enable pgvector steps
152149
## Next steps
153150

154151
[Connect to PostgreSQL :material-arrow-right:](connect.md){.md-button}

docs/templates/pdf_cover_page.tpl

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!--<h1>'{{ config.site_name }}'</h1>-->
2+
{{ config.extra.added_key }}
3+
<p>
4+
<img src="_images/Percona_Logo_Color.png" />
5+
</p>
6+
<h1>Distribution for PostgreSQL</h1>
7+
{% if config.site_description %}
8+
<h1>{{ config.site_description }}</h1>
9+
{% endif %}
10+
<h2>13.20 (March 6, 2025)</h2>
11+
<!--<h3>Percona Technical Documentation Team</h3>-->
12+

mkdocs-base.yml

+19-14
Original file line numberDiff line numberDiff line change
@@ -138,31 +138,36 @@ plugins:
138138
macros:
139139
include_yaml:
140140
- 'variables.yml' # Use in markdown as '{{ VAR }}'
141-
# exclude: # Don't process these files
142-
# glob:
143-
# - file.md
144-
with-pdf: # https://github.com/orzih/mkdocs-with-pdf
145-
output_path: '_pdf/PerconaDistributionPostgreSQL-13.pdf'
146-
cover_title: 'Distribution for PostgreSQL Documentation'
147-
cover_subtitle: 13.20 (March 6, 2025)
148-
author: 'Percona Technical Documentation Team'
149-
cover_logo: docs/_images/Percona_Logo_Color.png
150-
debug_html: false
151-
custom_template_path: _resource/templates
152-
enabled_if_env: ENABLE_PDF_EXPORT
153-
154141
mike:
155142
version_selector: true
156143
css_dir: css
157144
javascript_dir: js
158145
canonical_version: null
146+
print-site:
147+
add_to_navigation: false
148+
print_page_title: 'Percona Distribution for PostgreSQL documentation'
149+
add_print_site_banner: false
150+
# Table of contents
151+
add_table_of_contents: true
152+
toc_title: 'Table of Contents'
153+
toc_depth: 2
154+
# Content-related
155+
add_full_urls: false
156+
enumerate_headings: false
157+
enumerate_headings_depth: 1
158+
enumerate_figures: true
159+
add_cover_page: true
160+
cover_page_template: "docs/templates/pdf_cover_page.tpl"
161+
path_to_pdf: ""
162+
include_css: true
163+
enabled: true
159164

160165
extra:
161166
version:
162167
provider: mike
163168
#homepage:
164169
# https://docs.percona.com
165-
postgresrecommended: 16
170+
postgresrecommended: 13
166171

167172
nav:
168173
- 'Home': 'index.md'

mkdocs-pdf.yml

-10
This file was deleted.

mkdocs.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ INHERIT: mkdocs-base.yml
55

66
site_url: "https://docs.percona.com/postgresql/"
77

8+
theme:
9+
name: material
10+
custom_dir: _resourcepdf/overrides/
811

912
extra:
1013
analytics:
@@ -26,8 +29,4 @@ extra:
2629
<a href="https://docs.google.com/forms/d/1bkWACehjqlwA0AKf-qTJcXvYbOSYgze8iTPXjntqmNo/edit" target="_blank" rel="noopener">
2730
feedback form</a>.
2831
29-
#markdown_extensions:
30-
# - pymdownx.tabbed:
31-
# alternate_style: true
32-
3332

requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ mkdocs-htmlproofer-plugin
1515
mkdocs-meta-descriptions-plugin
1616
mike
1717
Pillow > 10.1.0
18-
mkdocs-open-in-new-tab
18+
mkdocs-open-in-new-tab
19+
mkdocs-print-site-plugin

0 commit comments

Comments
 (0)