import re with open("site/index.html", "r") as f: site = f.read() # Fix DOCTYPE site = site.replace("", "") # Fix self-closing meta, link, img site = re.sub(r'(<(?:meta|link|img)[^>]*?)\s*/>', r'\1>', site) # Fix "photo" in alt attributes site = site.replace('alt="Photos page light"', 'alt="Library page light mode"') site = site.replace('alt="Photos page dark"', 'alt="Library page dark mode"') # Rewrite figure as button to fix tabIndex warning site = re.sub(r'
', r'
', '') site = site.replace('
', '') site = site.replace('
', '') # Rewrite modal as old_modal = """ """ new_modal = """ """ site = site.replace(old_modal, new_modal) # Also update the JS to use dialog.showModal() and dialog.close() js_old_1 = """ modal.classList.add("visible"); modal.setAttribute("aria-hidden", "false"); document.body.style.overflow = "hidden"; // Prevent background scrolling""" js_new_1 = """ modal.showModal(); modal.classList.add("visible"); document.body.style.overflow = "hidden";""" site = site.replace(js_old_1, js_new_1) js_old_2 = """ const closeModal = () => { modal.classList.remove("visible"); modal.setAttribute("aria-hidden", "true"); document.body.style.overflow = ""; };""" js_new_2 = """ const closeModal = () => { modal.classList.remove("visible"); modal.close(); document.body.style.overflow = ""; };""" site = site.replace(js_old_2, js_new_2) # Fix JS querySelectorAll for screenshot-item since it's a button now site = site.replace('const figure = img.parentElement;', 'const figure = img.closest(".screenshot-item");') with open("site/index.html", "w") as f: f.write(site)