mirror of
https://github.com/Theodor-Springmann-Stiftung/documentamusica.git
synced 2025-10-29 09:05:31 +00:00
Saving the website
This commit is contained in:
84
update_menus.py
Normal file
84
update_menus.py
Normal file
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Update all menu files to add Katalog/Catalog/Catalogue link
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
def update_menu_file(file_path, lang):
|
||||
"""Update a single menu file to add the catalog link"""
|
||||
|
||||
# Define the catalog label based on language
|
||||
labels = {
|
||||
'de': 'Katalog',
|
||||
'en': 'Catalog',
|
||||
'fr': 'Catalogue'
|
||||
}
|
||||
|
||||
catalog_label = labels.get(lang, 'Katalog')
|
||||
|
||||
# Read the file
|
||||
with open(file_path, 'r', encoding='iso-8859-1', errors='replace') as f:
|
||||
content = f.read()
|
||||
|
||||
# Check if already has katalog link
|
||||
if 'katalog' in content.lower():
|
||||
print(f" {file_path.name} - already has catalog link, skipping")
|
||||
return False
|
||||
|
||||
# Find the biographies cell and add catalog after it
|
||||
bio_pattern = r'(<td>\s*<a href="' + lang + r'-bio\.html" target="_parent">\s*.*?</a></td>)'
|
||||
|
||||
# Create the new catalog cell
|
||||
catalog_cell = f'''<td>
|
||||
<a href="{lang}-katalog.html" target="_parent">
|
||||
{catalog_label}</a></td>'''
|
||||
|
||||
# Replace - add catalog cell after bio cell
|
||||
new_content = re.sub(bio_pattern, r'\1\n ' + catalog_cell, content)
|
||||
|
||||
if new_content == content:
|
||||
print(f" {file_path.name} - pattern not found, manual update needed")
|
||||
return False
|
||||
|
||||
# Write back
|
||||
with open(file_path, 'w', encoding='iso-8859-1', errors='replace') as f:
|
||||
f.write(new_content)
|
||||
|
||||
print(f" ✓ {file_path.name}")
|
||||
return True
|
||||
|
||||
|
||||
def main():
|
||||
html_dir = Path(__file__).parent / 'src' / 'html'
|
||||
|
||||
# Define which menus to update (exclude katalog-menu.html and special menus)
|
||||
menus_to_update = {
|
||||
'de': ['de-intro-menu.html', 'de-bio-menu.html', 'de-formular-menu.html',
|
||||
'de-klaviatur-menu.html', 'de-quellen-menu.html', 'de-impressum-menu.html'],
|
||||
'en': ['en-intro-menu.html', 'en-bio-menu.html', 'en-formular-menu.html',
|
||||
'en-klaviatur-menu.html', 'en-quellen-menu.html', 'en-impressum-menu.html'],
|
||||
'fr': ['fr-intro-menu.html', 'fr-bio-menu.html', 'fr-formular-menu.html',
|
||||
'fr-klaviatur-menu.html', 'fr-quellen-menu.html', 'fr-impressum-menu.html']
|
||||
}
|
||||
|
||||
print("Updating navigation menus...\n")
|
||||
|
||||
total_updated = 0
|
||||
for lang, menu_files in menus_to_update.items():
|
||||
print(f"{lang.upper()} menus:")
|
||||
for menu_file in menu_files:
|
||||
file_path = html_dir / menu_file
|
||||
if file_path.exists():
|
||||
if update_menu_file(file_path, lang):
|
||||
total_updated += 1
|
||||
else:
|
||||
print(f" {menu_file} - not found")
|
||||
print()
|
||||
|
||||
print(f"✅ Updated {total_updated} menu files")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user