mirror of
https://github.com/sigmasternchen/grimoire-ssg
synced 2025-03-15 01:58:54 +00:00
feat: Allow loading of external modules
This commit is contained in:
parent
b2d8198d1d
commit
7ad0d3eb40
4 changed files with 27 additions and 1 deletions
8
example/config.yml
Normal file
8
example/config.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
load_modules:
|
||||
- external_module_test
|
||||
|
||||
enabled_modules:
|
||||
- tags
|
||||
- markdown
|
||||
- templating
|
||||
- test
|
8
external_module_test/__init__.py
Normal file
8
external_module_test/__init__.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
from grimoiressg.modules import available_modules
|
||||
|
||||
|
||||
def test(data, context):
|
||||
print("This is test module.")
|
||||
|
||||
|
||||
available_modules["test"] = test
|
|
@ -1,7 +1,7 @@
|
|||
import yaml
|
||||
from yaml import Loader
|
||||
|
||||
from grimoiressg.modules import available_modules
|
||||
from grimoiressg.modules import available_modules, load_external_module
|
||||
|
||||
|
||||
def default_config():
|
||||
|
@ -21,9 +21,15 @@ def read_config(context):
|
|||
print("No config file given; using default config")
|
||||
config = default_config()
|
||||
else:
|
||||
print("Loading config file...")
|
||||
with open(config_file, "r") as file:
|
||||
config = yaml.load(file, Loader) or {}
|
||||
|
||||
for module in config.get("load_modules", []):
|
||||
print(f" Loading external module {module}")
|
||||
load_external_module(module)
|
||||
print()
|
||||
|
||||
print("Enabled modules:")
|
||||
for module in config.get("enabled_modules", []):
|
||||
print(f" - {module}")
|
||||
|
|
|
@ -7,3 +7,7 @@ available_modules = {
|
|||
"markdown": compile_markdown,
|
||||
"templating": render_templates
|
||||
}
|
||||
|
||||
|
||||
def load_external_module(module):
|
||||
__import__(module)
|
||||
|
|
Loading…
Reference in a new issue