2024-06-19 13:12:33 +10:00
|
|
|
import os
|
|
|
|
|
2025-01-04 20:11:35 +11:00
|
|
|
def cleanSite(path:str):
|
2024-06-19 13:12:33 +10:00
|
|
|
# Check if the file is sitemap.xml
|
2025-01-04 20:11:35 +11:00
|
|
|
if path.endswith('sitemap.xml'):
|
2024-06-19 13:12:33 +10:00
|
|
|
# Open the file
|
2025-01-04 20:11:35 +11:00
|
|
|
with open(path, 'r') as f:
|
2024-06-19 13:12:33 +10:00
|
|
|
# Read the content
|
|
|
|
content = f.read()
|
|
|
|
# Replace all .html with empty string
|
|
|
|
content = content.replace('.html', '')
|
|
|
|
# Write the content back to the file
|
2025-01-04 20:11:35 +11:00
|
|
|
with open(path, 'w') as f:
|
2024-06-19 13:12:33 +10:00
|
|
|
f.write(content)
|
|
|
|
# Skip the file
|
2025-01-04 20:11:35 +11:00
|
|
|
return
|
2024-06-19 13:12:33 +10:00
|
|
|
|
|
|
|
# If the file is not an html file, skip it
|
2025-01-04 20:11:35 +11:00
|
|
|
if not path.endswith('.html'):
|
|
|
|
if os.path.isdir(path):
|
|
|
|
for file in os.listdir(path):
|
|
|
|
cleanSite(path + '/' + file)
|
|
|
|
|
|
|
|
return
|
2024-06-19 13:12:33 +10:00
|
|
|
|
|
|
|
# Open the file
|
2025-01-04 20:11:35 +11:00
|
|
|
with open(path, 'r') as f:
|
2024-06-19 13:12:33 +10:00
|
|
|
# Read and remove all .html
|
|
|
|
content = f.read().replace('.html"', '"')
|
|
|
|
# Write the cleaned content back to the file
|
2025-01-04 20:11:35 +11:00
|
|
|
with open(path, 'w') as f:
|
|
|
|
f.write(content)
|
|
|
|
|
|
|
|
|
|
|
|
for file in os.listdir('templates'):
|
|
|
|
cleanSite('templates/' + file)
|