diff options
| author | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2020-03-25 18:48:12 +0100 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2020-03-25 21:13:44 +0100 |
| commit | 1b7eebb3563dab36584247bcab1d8e3b4e78833b (patch) | |
| tree | dfff7b3bf09b749795cf7d451c2a1fa8a4f60334 /repo/www/make-index.py | |
| parent | 355b77c1fff8132cd3445c375140cf51e736d8a0 (diff) | |
| download | memory-leaks-1b7eebb3563dab36584247bcab1d8e3b4e78833b.tar.xz | |
Split index generation and HTML conversion
So that I can re-use generate-index.py for READMEs.
Diffstat (limited to 'repo/www/make-index.py')
| -rwxr-xr-x | repo/www/make-index.py | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/repo/www/make-index.py b/repo/www/make-index.py deleted file mode 100755 index ef699f0..0000000 --- a/repo/www/make-index.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python3 - -from os import path -from subprocess import run -from sys import argv, exit - -from git import Repo - -from helpers import compute_directories - - -def parse_arguments(args): - if len(args) != 3: - exit(f'Usage: {argv[0]} EXTENSIONS FOLDER') - - return argv[1].split(), argv[2] - - -def list_files(extensions, folder): - directories = compute_directories( - extensions, Repo(search_parent_directories=True) - ) - return directories[folder].subfolders, directories[folder].files - - -def generate_index_page(title, directories, files): - lines = (f'% {title}',) + tuple( - f'- [{d}/]({d}/index.html)' for d in directories - ) + tuple( - f'- [{f}]({f}.html)' for f in files - ) - mdown = '\n'.join(lines) - - return run( - ('pandoc', '-s'), text=True, check=True, capture_output=True, - input=mdown - ).stdout - - -def main(arguments): - extensions, folder = parse_arguments(arguments) - - title = path.basename(folder) if folder else 'index' - - folders, files = list_files(extensions, folder) - - parsed_filenames = (path.splitext(f) for f in files) - names = tuple(name for name, _ in parsed_filenames) - - print(generate_index_page(title, folders, names)) - - -if __name__ == '__main__': - main(argv) |
