diff --git a/muppet/__main__.py b/muppet/__main__.py index d2880cab7bb3210bc2c8fae6887bfefa38efbd63..88d696852478127c0a96a00a60e6e299362f8b1f 100644 --- a/muppet/__main__.py +++ b/muppet/__main__.py @@ -67,6 +67,7 @@ class ModuleEntry: name: str path: str strings_output: bytes + metadata: dict[str, Any] def file(self, path: str) -> str: """Return the absolute path of a path inside the module.""" @@ -125,7 +126,13 @@ def get_modules(dir: str) -> list[ModuleEntry]: path = os.path.join(env, entry) strings_data = get_puppet_strings(path) - modules.append(ModuleEntry(name, path, strings_data)) + try: + with open(os.path.join(path, 'metadata.json')) as f: + metadata = json.load(f) + except FileNotFoundError: + metadata = {} + + modules.append(ModuleEntry(name, path, strings_data, metadata)) return modules @@ -171,7 +178,7 @@ def isprivate(entry: dict[str, Any]) -> bool: return False -def setup_index(base: str) -> None: +def setup_index(base: str, modules: list[ModuleEntry]) -> None: """Create the main index.html file.""" template = jinja.get_template('index.html') with open(os.path.join(base, 'index.html'), 'w') as f: @@ -403,9 +410,14 @@ def setup_module(base: str, module: ModuleEntry) -> None: # data['resource_types'] -modules = get_modules(env) +def __main() -> None: + modules = get_modules(env) + setup_index('output', modules) + + for module in modules: + # print(module) + setup_module('output', module) + -setup_index('output') -for module in modules: - # print(module) - setup_module('output', module) +if __name__ == '__main__': + __main() diff --git a/templates/index.html b/templates/index.html index 693c6f3a06bd8d2a98a66617e0254cc1241aac10..8703117b7b690944f4e62d7d6d98cfb3a6703ad8 100644 --- a/templates/index.html +++ b/templates/index.html @@ -17,9 +17,15 @@ <ul> {% for module in modules %} <li> - <a href="/{{ module.name }}" + {%- if module.metadata.get('name') -%} + {{ module.metadata['name'].split('-')[0] }}/ + {%- endif -%} + <a href="{{ module.name }}" class="{{ 'error' if module.strings_output == None }}" >{{ module.name }}</a> + {%- if module.metadata.get('summary') %} + — {{ module.metadata['summary'] }} + {%- endif -%} </li> {% endfor %} </ul>