summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@gmail.com>2020-03-29 23:24:35 +0200
committerKévin Le Gouguec <kevin.legouguec@gmail.com>2020-03-29 23:24:35 +0200
commita9ec31367187bc0159100688e13400ca86b2709a (patch)
treeacffacad68843b10cfb7ab895af30402d61b0160
parent006c863ee184389324d7346f65e93728d8d587b9 (diff)
downloadmemory-leaks-a9ec31367187bc0159100688e13400ca86b2709a.tar.xz
Unify recipe for regular and automated indices
Also don't run pandoc in a pipeline within a Makefile recipe: pipefail is not set, so generate-index.py failures will not be bubbled up.
-rw-r--r--repo/www/Makefile14
-rw-r--r--repo/www/TODO2
-rwxr-xr-xrepo/www/generate-deps.py28
-rwxr-xr-xrepo/www/generate-index.py14
4 files changed, 26 insertions, 32 deletions
diff --git a/repo/www/Makefile b/repo/www/Makefile
index 913aa65..bc9933a 100644
--- a/repo/www/Makefile
+++ b/repo/www/Makefile
@@ -9,8 +9,8 @@ dirname = $(patsubst %/,%,$(dir $(1)))
text_patterns = $(foreach ext,$(TEXT_FILES),'$(TOP_DIR)/**.$(ext)')
text_folders = $(sort $(call dirname,$(shell git ls-files $(text_patterns))))
-
page_folders = $(patsubst $(TOP_DIR)%,$(OUT_DIR)%,$(text_folders))
+indices = $(addsuffix /index.html,$(page_folders))
all: site
@@ -20,7 +20,7 @@ include $(dependencies)
$(dependencies): generate-deps.py $(text_folders)
python3 $< "$(TEXT_FILES)" $(OUT_DIR)
-site: $(pages) $(indices) $(autoindices)
+site: $(pages) $(indices)
$(page_folders):
mkdir -p $@
@@ -28,14 +28,10 @@ $(page_folders):
$(pages):
pandoc -s $< -o $@
-$(indices):
- python3 generate-index.py "$(TEXT_FILES)" $(dir $<) | pandoc -s > $@
-
# ⚠ 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)% generate-index.py | $(OUT_DIR)%
- python3 generate-index.py "$(TEXT_FILES)" $< | pandoc -s > $@
+# top-level index.html.
+$(indices): $(OUT_DIR)%/index.html: $(TOP_DIR)% generate-index.py | $(OUT_DIR)%
+ python3 generate-index.py "$(TEXT_FILES)" "$<" $@
clean:
-rm $(dependencies)
diff --git a/repo/www/TODO b/repo/www/TODO
index 96617e6..5e9f2d2 100644
--- a/repo/www/TODO
+++ b/repo/www/TODO
@@ -1,3 +1,4 @@
+- generate indices for folders containing only subfolders
- set HTML title to "${blog_title} - ${folder}"
- compute "leak count" on toplevel index
- autogenerate nav
@@ -5,3 +6,4 @@
- get stylin'
- pandoc template
- tufte css? at least sidenotes rather than footnotes
+- do something with "tags"
diff --git a/repo/www/generate-deps.py b/repo/www/generate-deps.py
index d88d333..f17e950 100755
--- a/repo/www/generate-deps.py
+++ b/repo/www/generate-deps.py
@@ -37,42 +37,26 @@ def pjoin(directory, item):
def write_dependencies(deps_file, directories, top_dir, out_dir):
pages = list()
- indices = list()
- autoindices = list()
for dpath, d in directories.items():
- autoindex = True
-
src_dir = pjoin(top_dir, dpath)
+ html_dir = pjoin(out_dir, dpath)
for f in d.files:
src_path = path.join(src_dir, f)
-
name, _ = path.splitext(f)
- deps = [src_path]
- target = pages
if name == 'README':
- name = 'index'
- deps.append(src_dir)
- target = indices
- autoindex = False
+ html_path = path.join(html_dir, 'index.html')
+ print(f'{html_path}: {src_path}', file=deps_file)
+ continue
- html_dir = pjoin(out_dir, dpath)
html_path = path.join(html_dir, name+'.html')
-
- print(f'{html_path}: {" ".join(deps)} | {html_dir}', file=deps_file)
- target.append(html_path)
-
- if autoindex:
- autoindices.append(
- path.join(out_dir, dpath, 'index.html')
- )
+ print(f'{html_path}: {src_path} | {html_dir}', file=deps_file)
+ pages.append(html_path)
print(file=deps_file)
print(f'pages = {" ".join(pages)}', file=deps_file)
- print(f'indices = {" ".join(indices)}', file=deps_file)
- print(f'autoindices = {" ".join(autoindices)}', file=deps_file)
def main(arguments):
diff --git a/repo/www/generate-index.py b/repo/www/generate-index.py
index d4b087c..3f777b9 100755
--- a/repo/www/generate-index.py
+++ b/repo/www/generate-index.py
@@ -2,6 +2,7 @@
from argparse import ArgumentParser
from os import path
+from subprocess import run
from git import Repo
@@ -17,6 +18,9 @@ def parse_arguments():
parser.add_argument(
'target', help='Folder to generate an index for.'
)
+ parser.add_argument(
+ 'output', help='Path to the output file.'
+ )
return parser.parse_args()
@@ -48,6 +52,11 @@ def generate_index_page(title, directories, files, intro_file):
{file_list}
'''
+def convert_page(content, output):
+ run(
+ ('pandoc', '-s', '-o', output), input=content, check=True, text=True
+ )
+
def main(arguments):
repo = Repo(search_parent_directories=True)
@@ -73,7 +82,10 @@ def main(arguments):
title = path.basename(target) if target else 'index'
- print(generate_index_page(title, folders, names, intro))
+ convert_page(
+ generate_index_page(title, folders, names, intro),
+ arguments.output
+ )
if __name__ == '__main__':