Files
boc/landvex-fix/remove_hreflang.py
T

40 lines
1.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
"""
Remove hreflang tags that point to dead domains.
"""
import os
import re
def remove_hreflang(filepath):
with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
content = f.read()
original = content
# Remove hreflang link tags
content = re.sub(r'\s*<link rel="alternate" hreflang="[^"]+" href="https://landvex\.(se|de|fr|co\.uk)/">\n?', '', content)
if content != original:
with open(filepath, 'w', encoding='utf-8') as f:
f.write(content)
return True
return False
def main():
base_dir = "/home/bernt/.openclaw/workspace/landvex-all"
count = 0
for root, dirs, files in os.walk(base_dir):
for file in files:
if file.endswith('.html'):
filepath = os.path.join(root, file)
if remove_hreflang(filepath):
count += 1
rel_path = os.path.relpath(filepath, base_dir)
print(f"Removed hreflang: {rel_path}")
print(f"\nDone: Removed hreflang from {count} files")
if __name__ == "__main__":
main()