|
11 | 11 | from email.utils import formatdate |
12 | 12 | from pathlib import Path |
13 | 13 | from re import compile as re_compile |
14 | | -from typing import List, Optional |
| 14 | +from typing import List, Literal, Optional |
15 | 15 |
|
16 | 16 | # 3rd party |
17 | 17 | from jinja2 import Environment, FileSystemLoader, select_autoescape |
@@ -55,9 +55,30 @@ class GitRssPlugin(BasePlugin[RssPluginConfig]): |
55 | 55 | # allow to set the plugin multiple times in the same mkdocs config |
56 | 56 | supports_multiple_instances = True |
57 | 57 |
|
58 | | - def __init__(self): |
| 58 | + def __init__(self, *args, **kwargs): |
59 | 59 | """Instantiation.""" |
60 | 60 | # pages storage |
| 61 | + super().__init__(*args, **kwargs) |
| 62 | + |
| 63 | + self.cmd_is_serve: bool = False |
| 64 | + |
| 65 | + def on_startup( |
| 66 | + self, *, command: Literal["build", "gh-deploy", "serve"], dirty: bool |
| 67 | + ) -> None: |
| 68 | + """The `startup` event runs once at the very beginning of an `mkdocs` invocation. |
| 69 | + Note that for initializing variables, the __init__ method is still preferred. |
| 70 | + For initializing per-build variables (and whenever in doubt), use the |
| 71 | + on_config event. |
| 72 | +
|
| 73 | + See: https://www.mkdocs.org/user-guide/plugins/#on_startup |
| 74 | +
|
| 75 | + Args: |
| 76 | + command: the command that MkDocs was invoked with, e.g. "serve" for `mkdocs serve`. |
| 77 | + dirty: whether `--dirty` flag was passed. |
| 78 | + """ |
| 79 | + # flag used command to disable some actions if serve is used |
| 80 | + self.cmd_is_serve = command == "serve" |
| 81 | + |
61 | 82 | self.pages_to_filter: List[PageInformation] = [] |
62 | 83 | # prepare output feeds |
63 | 84 | self.feed_created: dict = {} |
@@ -108,6 +129,7 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig: |
108 | 129 | cache_dir=self.cache_dir, |
109 | 130 | use_git=self.config.use_git, |
110 | 131 | integration_material_social_cards=self.integration_material_social_cards, |
| 132 | + mkdocs_command_is_on_serve=self.cmd_is_serve, |
111 | 133 | ) |
112 | 134 |
|
113 | 135 | # check template dirs |
|
0 commit comments