From c0a818c8e4a6064733b9417e2dc58be0c00158ee Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Tue, 29 Jun 2021 11:55:25 -0400 Subject: [PATCH] correctly determine canonical URLs for subfolders --- build.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/build.py b/build.py index a211060..88759c2 100644 --- a/build.py +++ b/build.py @@ -32,9 +32,6 @@ for (dirpath, _, filenames) in os.walk(static_directory): shutil.copy2(source, dest) -out_filenames = [] - - for (dirpath, _, filenames) in os.walk(input_directory): for filename in filenames: markdown_filename = os.path.join(dirpath, filename) @@ -59,20 +56,19 @@ for (dirpath, _, filenames) in os.walk(input_directory): out_filename = os.path.basename(markdown_filename).replace('.md', '.html') + out_dirpath = os.path.join(output_directory, dirpath) + out_dirpath = out_dirpath.replace('/content', '', 1) + out_fullpath = os.path.join(out_dirpath, out_filename) + page_url = out_fullpath.replace('output/', '', 1) + if page_url.endswith('index.html'): # strip off index.html + page_url = page_url[:-len('index.html')] + html = markdown.markdown(text, extensions=md_extensions, output_format='html5') output = template.replace('__TITLE_GOES_HERE__', title) output = output.replace('__CONTENT_GOES_HERE__', html) - - page_url = out_filename - if page_url.endswith('index.html'): # strip off index.html - page_url = page_url[:-len('index.html')] output = output.replace('__PAGE_URL_GOES_HERE__', page_url) - out_filenames.append(out_filename) - out_dirpath = os.path.join(output_directory, dirpath) - out_dirpath = out_dirpath.replace('/content', '', 1) os.makedirs(out_dirpath, exist_ok=True) - out_fullpath = os.path.join(out_dirpath, out_filename) print_file(markdown_filename, out_fullpath) out_file = open(out_fullpath, 'w') out_file.write(output)