Fix Windows MAX_PATH failures for percent-encoded wiki filenames.

Cap encoded slug length and use \\?\ long-path writes (0.3.6).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
mihailkudravcev
2026-07-24 10:55:31 +03:00
parent d91c454099
commit dc8be1bd1a
6 changed files with 106 additions and 49 deletions
+14 -15
View File
@@ -4,7 +4,6 @@ from __future__ import annotations
import json
import re
import shutil
from dataclasses import dataclass
from datetime import datetime, timezone
from pathlib import Path
@@ -13,6 +12,7 @@ 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.fscompat import copy_file, ensure_dir, remove_file, write_text
from export1c_help.lifecycle import (
LifecycleResult,
PageRecord,
@@ -247,6 +247,8 @@ def export_help(
link_map = build_link_title_map(pages, titles)
if clean and out_dir.exists():
import shutil
for child in out_dir.iterdir():
if child.name == ".git" or child.name.startswith("wiki_clone"):
# never wipe an in-tree wiki working clone
@@ -254,8 +256,8 @@ def export_help(
if child.is_dir():
shutil.rmtree(child)
else:
child.unlink()
out_dir.mkdir(parents=True, exist_ok=True)
remove_file(child)
ensure_dir(out_dir)
def rewrite(href: str, text: str) -> str:
return default_link_rewrite(href, text, link_map)
@@ -300,7 +302,7 @@ def export_help(
for rec in life.active:
body = body_by_meta[rec.meta_key]
md = body.rstrip() + _page_footer(rec, identity=identity)
(out_dir / rec.filename).write_text(md, encoding="utf-8")
write_text(out_dir / rec.filename, md)
stats.pages_written += 1
help_dir = src_root / Path(rec.source).parent
@@ -309,7 +311,7 @@ def export_help(
if img.suffix.lower() in {".png", ".jpg", ".jpeg", ".gif", ".bmp", ".webp"}:
target = out_dir / img.name
if not target.exists():
shutil.copy2(img, target)
copy_file(img, target)
stats.images_copied += 1
label = source_label or str(src_root)
@@ -343,7 +345,8 @@ def export_help(
deduped.append(row)
prev_exports = deduped[:50]
(out_dir / "Home.md").write_text(
write_text(
out_dir / "Home.md",
build_home(
written_pages,
titles,
@@ -351,19 +354,15 @@ def export_help(
identity=identity,
life=life,
),
encoding="utf-8",
)
(out_dir / "_Sidebar.md").write_text(
build_sidebar(written_pages, titles),
encoding="utf-8",
)
(out_dir / "History.md").write_text(
write_text(out_dir / "_Sidebar.md", build_sidebar(written_pages, titles))
write_text(
out_dir / "History.md",
build_history(
identity=identity,
life=life,
prev_exports=prev_exports,
),
encoding="utf-8",
)
exported_at = datetime.now(timezone.utc).isoformat()
@@ -403,8 +402,8 @@ def export_help(
"pages": [r.to_dict() for r in life.active],
"deleted_pages": [r.to_dict() for r in life.deleted],
}
(out_dir / "manifest.json").write_text(
write_text(
out_dir / "manifest.json",
json.dumps(manifest, ensure_ascii=False, indent=2) + "\n",
encoding="utf-8",
)
return stats