aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2023-06-04 01:40:30 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2023-06-04 01:40:30 +0200
commite62d89d3c33242c6ba14975c07b07c523e17e539 (patch)
tree1a572b2963487348485e5f9ad054c097f7b53b41
parentLoad modules list in documentation. (diff)
downloadmuppet-strings-e62d89d3c33242c6ba14975c07b07c523e17e539.tar.gz
muppet-strings-e62d89d3c33242c6ba14975c07b07c523e17e539.tar.xz
Add summary to main index page.
-rw-r--r--muppet/__main__.py26
-rw-r--r--templates/index.html8
2 files changed, 26 insertions, 8 deletions
diff --git a/muppet/__main__.py b/muppet/__main__.py
index d2880ca..88d6968 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 693c6f3..8703117 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') %}
+ &mdash; {{ module.metadata['summary'] }}
+ {%- endif -%}
</li>
{% endfor %}
</ul>