Skip to content

Commit

Permalink
Run startup (and shutdown) events when loading MkDocs config; resolves
Browse files Browse the repository at this point in the history
…#193

I'm not totally convinced this is the right thing to do, since mike doesn't have
the same lifecycle as MkDocs, but whatever...
  • Loading branch information
jimporter committed Dec 28, 2023
1 parent 533e996 commit 01446f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changes

## v2.1.0 (in progress)

### Bug fixes
- When loading an MkDocs config, mike now runs the `startup` and `shutdown`
events

---

## v2.0.0 (2023-11-02)

### New features
Expand Down
10 changes: 9 additions & 1 deletion mike/mkdocs_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import mkdocs.config
import mkdocs.plugins
import mkdocs.utils
import os
import re
Expand Down Expand Up @@ -30,7 +31,14 @@ def _open_config(config_file=None):
def load_config(config_file=None, **kwargs):
with _open_config(config_file) as f:
cfg = mkdocs.config.load_config(f, **kwargs)
return cfg['plugins'].run_event('config', cfg)

if 'startup' in mkdocs.plugins.EVENTS:
cfg['plugins'].run_event('startup', command='mike', dirty=False)
cfg = cfg['plugins'].run_event('config', cfg)
if 'shutdown' in mkdocs.plugins.EVENTS:
cfg['plugins'].run_event('shutdown')

return cfg


@contextmanager
Expand Down

0 comments on commit 01446f8

Please # to comment.