...
 
Commits (21)
......@@ -14,6 +14,26 @@ def read_file():
return _link_mappings
def flatten_links(_link_mappings):
remaining_rounds = 10
while remaining_rounds != 0:
found = False
for key, value in _link_mappings.items():
if value and value.startswith("/"):
found = True
print(f"Detected internal link: {key} -> {value}")
if value not in _link_mappings.keys():
print(f"ERROR: Target {value} not found!")
_link_mappings[key] = None
else:
print(f"Replacing {value} with {_link_mappings[value]}")
_link_mappings[key] = _link_mappings[value]
remaining_rounds = remaining_rounds - 1
if not found:
print("No (remaining) internal links found, quitting loop")
remaining_rounds = 0
def write_redirect_html(sub_path, target_url):
out_path = os.path.join("public", sub_path.lstrip(os.path.sep), "index.html")
os.makedirs(os.path.dirname(out_path), exist_ok=True)
......@@ -40,6 +60,8 @@ def write_redirect_html(sub_path, target_url):
if __name__ == '__main__':
link_mappings = read_file()
flatten_links(link_mappings)
for path, url in link_mappings.items():
print(f"Writing redirect for {path}")
write_redirect_html(path, url)
if url:
print(f"Writing redirect for {path}")
write_redirect_html(path, url)
This diff is collapsed.