Skip to content

Commit 292649a

Browse files
tombreittimvink
authored andcommitted
New config option: enabled_on_serve
1 parent 859a90e commit 292649a

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

docs/options.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ plugins:
1515
exclude:
1616
- index.md
1717
enabled: true
18+
enabled_on_serve: true
1819
strict: true
1920
```
2021
@@ -88,6 +89,10 @@ export ENABLED_GIT_AUTHORS=false
8889
mkdocs serve
8990
```
9091

92+
## `enabled_on_serve`
93+
94+
Default is `true`. Allows you to deactivate this plugin when `mkdocs` is called with the command `serve`. A possible use case is local development where you might want faster build times and/or do not have git available.
95+
9196
## `strict`
9297

9398
Default is `true`. When enabled, the logs will show warnings when something is wrong but a fallback has been used. When disabled, the logger will use the INFO level instead.

mkdocs_git_authors_plugin/plugin.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class GitAuthorsPlugin(BasePlugin):
2121
("fallback_to_empty", config_options.Type(bool, default=False)),
2222
("exclude", config_options.Type(list, default=[])),
2323
("enabled", config_options.Type(bool, default=True)),
24+
("enabled_on_serve", config_options.Type(bool, default=True)),
2425
("sort_authors_by", config_options.Type(str, default="name")),
2526
("authorship_threshold_percent", config_options.Type(int, default=0)),
2627
("strict", config_options.Type(bool, default=True)),
@@ -31,6 +32,10 @@ class GitAuthorsPlugin(BasePlugin):
3132
def __init__(self):
3233
self._repo = None
3334
self._fallback = False
35+
self.is_serve = False
36+
37+
def on_startup(self, command, dirty):
38+
self.is_serve = command == "serve"
3439

3540
def on_config(self, config, **kwargs):
3641
"""
@@ -51,7 +56,8 @@ def on_config(self, config, **kwargs):
5156
Returns:
5257
(updated) configuration object
5358
"""
54-
if not self.config.get("enabled"):
59+
60+
if not self._is_enabled():
5561
return config
5662

5763
assert self.config["authorship_threshold_percent"] >= 0
@@ -99,7 +105,7 @@ def on_files(self, files, config, **kwargs):
99105
Returns:
100106
global files collection
101107
"""
102-
if not self.config.get("enabled"):
108+
if not self._is_enabled():
103109
return
104110
if self._fallback:
105111
return
@@ -138,7 +144,7 @@ def on_page_content(self, html, page, config, files, **kwargs):
138144
Returns:
139145
str: HTML text of page as string
140146
"""
141-
if not self.config.get("enabled"):
147+
if not self._is_enabled():
142148
return html
143149

144150
# Exclude pages specified in config
@@ -195,7 +201,7 @@ def on_page_context(self, context, page, config, nav, **kwargs):
195201
Returns:
196202
dict: template context variables
197203
"""
198-
if not self.config.get("enabled"):
204+
if not self._is_enabled():
199205
return context
200206
if self._fallback:
201207
return context
@@ -235,3 +241,20 @@ def repo(self):
235241
Reference to the Repo object of the current project.
236242
"""
237243
return self._repo
244+
245+
def _is_enabled(self):
246+
"""
247+
Consider this plugin to be disabled in the following two conditions:
248+
* config.enabled is false
249+
* config.enabled is true and
250+
config.enabled_on_serve is false and
251+
executed via `serve` command
252+
"""
253+
is_enabled = True
254+
255+
if not self.config.get("enabled"):
256+
is_enabled = False
257+
elif self.is_serve and not self.config.get("enabled_on_serve"):
258+
is_enabled = False
259+
260+
return is_enabled

0 commit comments

Comments
 (0)