Release 0.3.8: translit wiki slugs and relative md links

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
mihailkudravcev
2026-07-29 11:12:38 +03:00
parent 98cbb88461
commit 7dd699dab5
6 changed files with 105 additions and 48 deletions
+17 -10
View File
@@ -11,7 +11,7 @@ from pathlib import Path
from export1c_help.__version__ import __version__
from export1c_help.config_version import ConfigIdentity, read_config_identity
from export1c_help.convert import default_link_rewrite, extract_h1, html_to_markdown
from export1c_help.discover import HelpPage, build_link_title_map, discover_help_pages
from export1c_help.discover import HelpPage, build_link_map, discover_help_pages
from export1c_help.fscompat import copy_file, ensure_dir, remove_file, write_text
from export1c_help.lifecycle import (
LifecycleResult,
@@ -70,6 +70,7 @@ def _page_footer(rec: PageRecord, *, identity: ConfigIdentity) -> str:
def build_home(
pages: list[HelpPage],
titles: dict[str, str],
files: dict[str, str],
*,
source_label: str,
identity: ConfigIdentity,
@@ -104,20 +105,24 @@ def build_home(
lines.append("")
for p in group:
title = titles[p.meta_key]
lines.append(f"- [[{title}]]")
lines.append(f"- [{title}]({files[p.meta_key]})")
lines.append("")
return "\n".join(lines).rstrip() + "\n"
def build_sidebar(pages: list[HelpPage], titles: dict[str, str]) -> str:
def build_sidebar(
pages: list[HelpPage],
titles: dict[str, str],
files: dict[str, str],
) -> str:
by_type: dict[str, list[HelpPage]] = {}
for p in pages:
by_type.setdefault(p.type_dir, []).append(p)
lines = [
"# Справка",
"",
"[[Home|Оглавление]]",
"[[History|История выгрузок]]",
"[Оглавление](Home.md)",
"[История выгрузок](History.md)",
"",
]
for type_dir in sorted(by_type, key=lambda d: DIR_TO_RU.get(d, d)):
@@ -127,9 +132,9 @@ def build_sidebar(pages: list[HelpPage], titles: dict[str, str]) -> str:
objs = [p for p in by_type[type_dir] if not p.is_form]
objs.sort(key=lambda p: titles[p.meta_key].casefold())
for p in objs[:80]:
lines.append(f"- [[{titles[p.meta_key]}]]")
lines.append(f"- [{titles[p.meta_key]}]({files[p.meta_key]})")
if len(objs) > 80:
lines.append(f"- … ещё {len(objs) - 80} (см. [[Home]])")
lines.append(f"- … ещё {len(objs) - 80} (см. [Оглавление](Home.md))")
lines.append("")
return "\n".join(lines).rstrip() + "\n"
@@ -244,7 +249,7 @@ def export_help(
h1_by_meta[p.meta_key] = extract_h1(html)
titles, files = assign_titles(pages, h1_by_meta)
link_map = build_link_title_map(pages, titles)
link_map = build_link_map(pages, titles, files)
if clean and out_dir.exists():
import shutil
@@ -268,7 +273,8 @@ def export_help(
for p in pages:
html = html_cache[p.meta_key]
title = titles[p.meta_key]
md = html_to_markdown(html, rewrite_link=rewrite, strip_first_h1=title)
md_body = html_to_markdown(html, rewrite_link=rewrite, strip_first_h1=title)
md = f"# {title}\n\n{md_body.lstrip()}"
if skip_empty and _is_effectively_empty(md):
stats.pages_skipped_empty += 1
continue
@@ -350,12 +356,13 @@ def export_help(
build_home(
written_pages,
titles,
files,
source_label=label,
identity=identity,
life=life,
),
)
write_text(out_dir / "_Sidebar.md", build_sidebar(written_pages, titles))
write_text(out_dir / "_Sidebar.md", build_sidebar(written_pages, titles, files))
write_text(
out_dir / "History.md",
build_history(