Skip to content

Commit

Permalink
chore: merge pull request #14 from oprypin/master
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienbrignon authored Dec 3, 2023
2 parents 4d0054c + df32eaf commit 1ba6103
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 29 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,25 @@ pip install mkdocs-exporter

Three plugins are currently available:

- `mkdocs/exporter` (*required*): base plugin which must precede the others
- `mkdocs/exporter/pdf` (*optional*): plugin that exports your pages as individual PDF documents
- `mkdocs/exporter/extras` (*optional*): provides extra functionalities (buttons, HTML utilities...)
- `exporter` (*required*): base plugin which must precede the others
- `exporter-pdf` (*optional*): plugin that exports your pages as individual PDF documents
- `exporter-extras` (*optional*): provides extra functionalities (buttons, HTML utilities...)

### Example

The following configuration excerpt from [`mkdocs.yml`](./mkdocs.yml) should cover the basic functionalities of this plugin:

```yaml
plugins:
- mkdocs/exporter
- mkdocs/exporter/pdf:
- exporter
- exporter-pdf:
concurrency: 8
covers:
front: resources/templates/covers/front.html.j2
back: resources/templates/covers/back.html.j2
stylesheets:
- resources/stylesheets/pdf.scss
- mkdocs/exporter/extras:
- exporter-extras:
buttons:
- title: Download as PDF
enabled: !!python/name:mkdocs_exporter.plugins.pdf.button.enabled
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ You can now register the plugin in your configuration file:

```yaml
plugins:
- mkdocs/exporter
- exporter
```
Check out the [setup guides](../setup/setting-up-documents) for more details about how to use and configure the plugin.
10 changes: 5 additions & 5 deletions docs/setup/setting-up-buttons.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ You can define custom buttons at the top of your pages.

## Configuration

This feature is provided by the `mkdocs/exporter/extras` plugin, you'll need to add it to your list of plugins:
This feature is provided by the `exporter-extras` plugin, you'll need to add it to your list of plugins:

```yaml
plugins:
- mkdocs/exporter
- mkdocs/exporter/extras
- exporter
- exporter-extras
```
## Usage
Expand All @@ -34,7 +34,7 @@ This example will add a download button at the top of all pages that have a corr
```yaml
plugins:
- mkdocs/exporter/extras:
- exporter-extras:
buttons:
- title: Download as PDF
icon: material-file-download-outline
Expand Down Expand Up @@ -71,7 +71,7 @@ Then, we can define the button and specify the path to the previously defined fu

```yaml
plugins:
- mkdocs/exporter/extras:
- exporter-extras:
buttons:
- title: Search on Google
icon: material-google
Expand Down
20 changes: 10 additions & 10 deletions docs/setup/setting-up-documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ playwright install --with-deps

## Configuration

First of all, you'll need to register the `mkdocs/exporter/pdf` plugin (**after** the `mkdocs/exporter` one) to your configuration:
First of all, you'll need to register the `exporter-pdf` plugin (**after** the `exporter` one) to your configuration:

```yaml
plugins:
- mkdocs/exporter
- mkdocs/exporter/pdf
- exporter
- exporter-pdf
```
???+ question "Why multiple plugins?"
Expand All @@ -39,7 +39,7 @@ plugins:
This architecture reduces code duplication and maintains a generic base that can be used to export
your pages to formats other than PDF (although this is currently the only format supported).
To sum things up, the `mkdocs/exporter` should always be registered first as it provides a common ground for
To sum things up, the `exporter` should always be registered first as it provides a common ground for
other plugins to rely on.

## Usage
Expand All @@ -51,8 +51,8 @@ This feature is particularly useful during your development processes: when you

```yaml
plugins:
- mkdocs/exporter
- mkdocs/exporter/pdf:
- exporter
- exporter-pdf:
enabled: ![MKDOCS_EXPORTER_ENABLED, true]
```

Expand All @@ -73,8 +73,8 @@ Here's how cover pages are set up for this documentation.

```yaml
plugins:
- mkdocs/exporter
- mkdocs/exporter/pdf:
- exporter
- exporter-pdf:
stylesheets:
- resources/stylesheets/pdf.scss
covers:
Expand Down Expand Up @@ -136,7 +136,7 @@ You may want to override the default value of **4**, depending on your hardware.

```yaml
plugins:
- mkdocs/exporter/pdf:
- exporter-pdf:
concurrency: 16
```

Expand All @@ -163,7 +163,7 @@ This behaviour is called the `explicit` mode, it can be enabled in your configur

```yaml
plugins:
- mkdocs/exporter/pdf:
- exporter-pdf:
explicit: true
```

Expand Down
6 changes: 3 additions & 3 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ extra:
link: https://pypi.org/project/mkdocs-exporter

plugins:
- mkdocs/exporter:
- mkdocs/exporter/pdf:
- exporter:
- exporter-pdf:
concurrency: 16
stylesheets:
- resources/stylesheets/pdf.scss
Expand All @@ -50,7 +50,7 @@ plugins:
browser:
debug: false
headless: true
- mkdocs/exporter/extras:
- exporter-extras:
buttons:
- title: Download as PDF
icon: material-file-download-outline
Expand Down
9 changes: 9 additions & 0 deletions mkdocs_exporter/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from mkdocs.plugins import event_priority
from mkdocs_exporter.config import Config
from mkdocs.structure.files import File, Files
from mkdocs_exporter.logging import logger
from mkdocs_exporter.preprocessor import Preprocessor
from mkdocs_exporter.themes.factory import Factory as ThemeFactory

Expand Down Expand Up @@ -69,3 +70,11 @@ def on_post_build(self, **kwargs) -> None:
content = self.theme.stylesheet(reader.read())
with open(stylesheet.abs_dest_path, 'w+', encoding='utf-8') as writer:
writer.write(content)


class PluginDeprecated(Plugin):
def on_config(self, config: dict) -> None:
logger.warning(
"The plugin name 'mkdocs/exporter/extras' will stop working soon, please replace it with 'exporter-extras'"
)
super().on_config(config)
8 changes: 8 additions & 0 deletions mkdocs_exporter/plugins/extras/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from mkdocs.plugins import BasePlugin
from mkdocs_exporter.page import Page
from mkdocs.plugins import event_priority
from mkdocs_exporter.logging import logger
from mkdocs_exporter.preprocessor import Preprocessor
from mkdocs_exporter.plugins.extras.config import Config

Expand Down Expand Up @@ -37,3 +38,10 @@ def resolve(object):
preprocessor.button(**resolve(button))

return preprocessor.done()


class PluginDeprecated(Plugin):
def on_config(self, config: dict) -> None:
logger.warning(
"The plugin name 'mkdocs/exporter' will stop working soon, please replace it with 'exporter'"
)
11 changes: 10 additions & 1 deletion mkdocs_exporter/plugins/pdf/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def on_pre_page(self, page: Page, config: dict, **kwargs):
if not self._enabled():
return
if not hasattr(page, 'html'):
raise Exception('Missing `mkdocs/exporter` plugin or your plugins are not ordered properly!')
raise Exception('Missing `exporter` plugin or your plugins are not ordered properly!')

directory = os.path.dirname(page.file.abs_dest_path)
filename = os.path.splitext(os.path.basename(page.file.abs_dest_path))[0] + '.pdf'
Expand Down Expand Up @@ -168,3 +168,12 @@ def _enabled(self, page: Page = None) -> bool:
return False

return True



class PluginDeprecated(Plugin):
def on_config(self, config: dict) -> None:
logger.warning(
"The plugin name 'mkdocs/exporter/pdf' will stop working soon, please replace it with 'exporter-pdf'"
)
super().on_config(config)
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ importlib-metadata = ">=6.0"
nest-asyncio = ">=1.5.6"

[tool.poetry.plugins."mkdocs.plugins"]
"mkdocs/exporter" = "mkdocs_exporter.plugin:Plugin"
"mkdocs/exporter/pdf" = "mkdocs_exporter.plugins.pdf.plugin:Plugin"
"mkdocs/exporter/extras" = "mkdocs_exporter.plugins.extras.plugin:Plugin"
"exporter" = "mkdocs_exporter.plugin:Plugin"
"exporter-pdf" = "mkdocs_exporter.plugins.pdf.plugin:Plugin"
"exporter-extras" = "mkdocs_exporter.plugins.extras.plugin:Plugin"
"mkdocs/exporter" = "mkdocs_exporter.plugin:PluginDeprecated"
"mkdocs/exporter/pdf" = "mkdocs_exporter.plugins.pdf.plugin:PluginDeprecated"
"mkdocs/exporter/extras" = "mkdocs_exporter.plugins.extras.plugin:PluginDeprecated"

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/adrienbrignon/mkdocs-exporter/issues"
Expand Down

0 comments on commit 1ba6103

Please sign in to comment.