memory-leaks

Still reachable: lots of words in many pages.
git clone https://git.kevinlegouguec.net/memory-leaks
Log | Files | Refs | README | LICENSE

commit 1b7eebb3563dab36584247bcab1d8e3b4e78833b
parent 355b77c1fff8132cd3445c375140cf51e736d8a0
Author: Kévin Le Gouguec <kevin.legouguec@gmail.com>
Date:   Wed, 25 Mar 2020 18:48:12 +0100

Split index generation and HTML conversion

So that I can re-use generate-index.py for READMEs.

Diffstat:
Mrepo/www/Makefile | 8+++++---
Rrepo/www/make-deps.py -> repo/www/generate-deps.py | 0
Arepo/www/generate-index.py | 48++++++++++++++++++++++++++++++++++++++++++++++++
Drepo/www/make-index.py | 54------------------------------------------------------
4 files changed, 53 insertions(+), 57 deletions(-)

diff --git a/repo/www/Makefile b/repo/www/Makefile @@ -15,7 +15,7 @@ all: site dependencies = deps.mk include $(dependencies) -$(dependencies): make-deps.py $(text_folders) +$(dependencies): generate-deps.py $(text_folders) python3 $< "$(TEXT_FILES)" $(OUT_DIR) site: $(pages) $(indices) $(autoindices) @@ -28,8 +28,10 @@ $(pages) $(indices): # ⚠ When tweaking this rule, check whether it still works for the # top-level index.html, i.e. when there is no top-level README. -$(autoindices): $(OUT_DIR)%/index.html: $(TOP_DIR)% make-index.py | $(OUT_DIR)% - python3 make-index.py "$(TEXT_FILES)" "$(*:/%=%)" > $@ +$(autoindices): \ +$(OUT_DIR)%/index.html: $(TOP_DIR)% generate-index.py | $(OUT_DIR)% + python3 generate-index.py "$(TEXT_FILES)" "$(*:/%=%)" | \ + pandoc -s > $@ clean: -rm $(dependencies) diff --git a/repo/www/make-deps.py b/repo/www/generate-deps.py diff --git a/repo/www/generate-index.py b/repo/www/generate-index.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 + +from os import path +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 + ) + return '\n'.join(lines) + + +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) diff --git a/repo/www/make-index.py b/repo/www/make-index.py @@ -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)