correctly determine canonical URLs for subfolders

This commit is contained in:
Colin McMillen 2021-06-29 11:55:25 -04:00
parent eac976e1e9
commit c0a818c8e4

View File

@ -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)