diff --git a/clean_language_blocks.py b/clean_language_blocks.py index bb6d434..f157dd6 100644 --- a/clean_language_blocks.py +++ b/clean_language_blocks.py @@ -1,63 +1,47 @@ import os import re import shutil -import yaml SOURCE_DIR = "docs" -ENGLISH_DIR = os.path.join(SOURCE_DIR, "en") -MKDOCS_YML = "mkdocs.yml" +ENGLISH_DIR = "docs/en" -# 1. Kopiera alla filer från docs/ till docs/en/ +# Rensa tidigare engelska mappar if os.path.exists(ENGLISH_DIR): shutil.rmtree(ENGLISH_DIR) shutil.copytree(SOURCE_DIR, ENGLISH_DIR) +# --- Inline-hantering --- +def remove_other_language_inline(content, keep_lang): + def replacer(match): + lang, text = match.group(1), match.group(2) + return text if lang == keep_lang else "" + return re.sub(r"\{(sv|en):(.*?)}", replacer, content) + +# --- Block-hantering --- +def remove_other_language_blocks(content, keep_lang): + content = re.sub( + r":(sv|en)\n(.*?)\n:::", + lambda m: m.group(2) if m.group(1) == keep_lang else "", + content, + flags=re.DOTALL + ) + return content + +# --- Kombinerad rengöring --- def clean_file(path, keep_lang): with open(path, "r", encoding="utf-8") as f: content = f.read() - - # 2. Rensa block: :sv ... ::: eller :en ... ::: - if keep_lang == "sv": - content = re.sub(r":en\n.*?\n:::", "", content, flags=re.DOTALL) - elif keep_lang == "en": - content = re.sub(r":sv\n.*?\n:::", "", content, flags=re.DOTALL) - - # 3. Ta bort alla språk-taggar som :sv, :en och ::: - content = re.sub(r":(sv|en)", "", content) - content = re.sub(r":::", "", content) - - # 4. Rensa inline-översättningar - def remove_other_language_inline(text, keep_lang): - def replacer(match): - lang = match.group(1) - txt = match.group(2) - return txt if lang == keep_lang else "" - return re.sub(r"\[:(sv|en)](.*?)(?=\[:|$)", replacer, text) - + content = remove_other_language_blocks(content, keep_lang) content = remove_other_language_inline(content, keep_lang) - with open(path, "w", encoding="utf-8") as f: f.write(content.strip() + "\n") -# 5. Rensa svenska versioner +# --- Rensa svenska filer --- for filename in os.listdir(SOURCE_DIR): if filename.endswith(".md"): clean_file(os.path.join(SOURCE_DIR, filename), keep_lang="sv") -# 6. Rensa engelska versioner +# --- Rensa engelska filer --- for filename in os.listdir(ENGLISH_DIR): if filename.endswith(".md"): clean_file(os.path.join(ENGLISH_DIR, filename), keep_lang="en") - -# 7. Skapa .pages i docs/en/ från mkdocs.yml -def extract_nav_from_mkdocs_yml(path): - with open(path, "r", encoding="utf-8") as f: - data = yaml.safe_load(f) - return { - "title": data.get("site_name", "SA6ANW"), - "nav": data.get("nav", []) - } - -english_pages = extract_nav_from_mkdocs_yml(MKDOCS_YML) -with open(os.path.join(ENGLISH_DIR, ".pages"), "w", encoding="utf-8") as f: - yaml.dump(english_pages, f, allow_unicode=True) diff --git a/docs/midsomer.md b/docs/midsomer.md index ffe92c1..db8baee 100644 --- a/docs/midsomer.md +++ b/docs/midsomer.md @@ -95,7 +95,7 @@ Whether you're a licensed ham or just a loyal viewer, add your name and help us



- +