import os
import re
# === CONFIG ===
html_dir = 'site/' # Folder containing all 900 HTML files
old_logo_pattern = re.compile(r'
]+src="[^"]*old-logo[^"]*"[^>]*>', re.IGNORECASE)
new_logo_html = '
'
max_keyword_uses = 3
keyword = "Trezor Suite"
replacement_terms = [
"the wallet interface", "Trezor's platform", "the crypto dashboard",
"Trezor", "your secure wallet", "this suite", "Trezor tool"
]
def limit_keyword_use(text, keyword, max_uses):
occurrences = [m.start() for m in re.finditer(re.escape(keyword), text)]
if len(occurrences) <= max_uses:
return text
# Replace excess occurrences
for i in range(max_uses, len(occurrences)):
alt = replacement_terms[i % len(replacement_terms)]
text = text[:occurrences[i]] + alt + text[occurrences[i] + len(keyword):]
return text
# === PROCESSING ===
for filename in os.listdir(html_dir):
if filename.endswith('.html'):
filepath = os.path.join(html_dir, filename)
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
# Replace old logo
content = old_logo_pattern.sub(new_logo_html, content)
# Limit keyword use
content = limit_keyword_use(content, keyword, max_keyword_uses)
# Save file
with open(filepath, 'w', encoding='utf-8') as f:
f.write(content)
print(f"Updated: {filename}")
print("✅ All HTML pages updated.")