# -*- coding: utf-8 -*- """Shared pieces of the website refresh 2026-10-08: the page map, the two navs, hreflang, file IO.""" import io, os, re, subprocess REPO = "/mnt/5_hdd/felhom.eu/git/felhom.eu" W = os.path.join(REPO, "website") SITE = "https://felhom.eu" # hu file, hu url, en file, en url, hu nav href that is "active", en nav href that is "active" PAIRS = [ ("index.html", "/", "en/index.html", "/en/", None, None), ("alkalmazasok.html", "/alkalmazasok", "en/apps.html", "/en/apps", "/alkalmazasok", "/en/apps"), ("technologiak.html", "/technologiak", "en/technology.html", "/en/technology", "/technologiak", "/en/technology"), ("biztonsagimentes.html", "/biztonsagimentes", "en/backups.html", "/en/backups", "/biztonsagimentes", "/en/backups"), ("gyik.html", "/gyik", "en/faq.html", "/en/faq", "/gyik", "/en/faq"), ("kapcsolat.html", "/kapcsolat", "en/contact.html", "/en/contact", "/kapcsolat", "/en/contact"), ("letoltes.html", "/letoltes", "en/download.html", "/en/download", None, None), ] HU_ITEMS = [("/#szolgaltatasok", "Szolgáltatások"), ("/alkalmazasok", "Alkalmazások"), ("/technologiak", "Technológiák"), ("/biztonsagimentes", "Mentések"), ("/gyik", "GYIK"), ("/kapcsolat", "Kapcsolat")] EN_ITEMS = [("/en/#services", "Services"), ("/en/apps", "Apps"), ("/en/technology", "Technology"), ("/en/backups", "Backups"), ("/en/faq", "FAQ"), ("/en/contact", "Contact")] def nav(lang, active, twin_url): items = HU_ITEMS if lang == "hu" else EN_ITEMS lis = [] for href, label in items: act = ' class="active"' if href == active else "" lis.append('
  • %s
  • ' % (href, act, label)) if lang == "hu": lis.append('
  • English
  • ' % twin_url) else: lis.append('
  • Magyar
  • ' % twin_url) home = "/" if lang == "hu" else "/en/" open_l = "Menü megnyitása" if lang == "hu" else "Open menu" return (""" """ % (home, "\n".join(lis), open_l)) FOOTER_HU = """ """ FOOTER_EN = """ """ def alternates(hu_url, en_url): return (' \n' ' \n' ' ') % (SITE, hu_url, SITE, en_url, SITE, hu_url) def head_text(path): """The file as it is at HEAD (the source every build starts from, so a re-run is idempotent).""" rel = os.path.relpath(os.path.join(W, path), REPO) out = subprocess.run(["git", "-C", REPO, "show", "HEAD:" + rel], capture_output=True) if out.returncode != 0: return None return out.stdout.decode("utf-8-sig") def read(path): return io.open(os.path.join(W, path), encoding="utf-8-sig").read() def write(path, text): full = os.path.join(W, path) os.makedirs(os.path.dirname(full), exist_ok=True) with io.open(full, "w", encoding="utf-8-sig", newline="\n") as f: f.write(text) def sub1(s, old, new, count=1): n = s.count(old) if n != count: raise SystemExit("expected %d x %r, found %d" % (count, old[:90], n)) return s.replace(old, new) def set_nav(s, lang, active, twin_url): s2, n = re.subn(r" ", lambda m: nav(lang, active, twin_url), s, count=1, flags=re.S) assert n == 1 return s2 def set_footer(s, lang): s2, n = re.subn(r" ", lambda m: FOOTER_HU if lang == "hu" else FOOTER_EN, s, count=1, flags=re.S) assert n == 1 return s2 def set_alternates(s, hu_url, en_url): """Insert (or replace) the three hreflang links right after the canonical link.""" s = re.sub(r' \n', "", s) m = re.search(r' \n', s) assert m, "no canonical" return s[:m.end()] + alternates(hu_url, en_url) + "\n" + s[m.end():]