mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-16 01:40:15 +08:00
chore: ruff format .
This commit is contained in:
@@ -291,7 +291,9 @@ class LinkResolver:
|
||||
self.source_pages = discover_source_pages(str(self.source_root))
|
||||
|
||||
def resolve_base_target(
|
||||
self, base_target: str, source_path: str,
|
||||
self,
|
||||
base_target: str,
|
||||
source_path: str,
|
||||
) -> ResolutionResult:
|
||||
return resolve_link_path(
|
||||
base_target=base_target,
|
||||
@@ -301,7 +303,9 @@ class LinkResolver:
|
||||
)
|
||||
|
||||
def resolve_markdown_target(
|
||||
self, target: str, source_path: str,
|
||||
self,
|
||||
target: str,
|
||||
source_path: str,
|
||||
) -> tuple[str | None, str]:
|
||||
parsed_target = parse_doc_target(target)
|
||||
if parsed_target is None:
|
||||
@@ -403,7 +407,8 @@ def find_unresolved_doc_links(source_root: Path) -> list[str]:
|
||||
content = (root / source_path).read_text(encoding="utf-8")
|
||||
for link in iter_markdown_links(content):
|
||||
resolved_path, _ = resolver.resolve_markdown_target(
|
||||
link.target, source_path,
|
||||
link.target,
|
||||
source_path,
|
||||
)
|
||||
if resolved_path is not None:
|
||||
continue
|
||||
@@ -522,7 +527,9 @@ def build_sidebar(page_infos: list[PageInfo]) -> str:
|
||||
|
||||
|
||||
def build_page_info(
|
||||
source_root: Path, source_path: str, resolver: LinkResolver,
|
||||
source_root: Path,
|
||||
source_path: str,
|
||||
resolver: LinkResolver,
|
||||
) -> PageInfo:
|
||||
source_file = source_root / source_path
|
||||
content = source_file.read_text(encoding="utf-8")
|
||||
@@ -634,7 +641,8 @@ def main() -> int:
|
||||
return 0
|
||||
|
||||
sync_docs_to_wiki(
|
||||
source_root=Path(args.source_root), wiki_root=Path(args.wiki_root),
|
||||
source_root=Path(args.source_root),
|
||||
wiki_root=Path(args.wiki_root),
|
||||
)
|
||||
return 0
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@ IMAGE_EXTS = {
|
||||
|
||||
MD_IMAGE_RE = re.compile(r"!\[[^\]]*\]\(([^)]+)\)")
|
||||
HTML_IMG_RE = re.compile(
|
||||
r"<img\b[^>]*\bsrc\s*=\s*([\"'])([^\"']+)\1[^>]*>", re.IGNORECASE,
|
||||
r"<img\b[^>]*\bsrc\s*=\s*([\"'])([^\"']+)\1[^>]*>",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
|
||||
|
||||
@@ -48,10 +49,14 @@ def parse_args() -> argparse.Namespace:
|
||||
help="docs root to scan for .md files (default: current directory)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--dry-run", action="store_true", help="preview uploads without sending files",
|
||||
"--dry-run",
|
||||
action="store_true",
|
||||
help="preview uploads without sending files",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--list-only", action="store_true", help="only print matched image files",
|
||||
"--list-only",
|
||||
action="store_true",
|
||||
help="only print matched image files",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--rewrite-markdown",
|
||||
@@ -135,7 +140,8 @@ def find_markdown_files(root: Path) -> list[Path]:
|
||||
|
||||
|
||||
def collect_images(
|
||||
root: Path, md_files: Sequence[Path],
|
||||
root: Path,
|
||||
md_files: Sequence[Path],
|
||||
) -> tuple[set[Path], list[tuple[Path, str]]]:
|
||||
images: set[Path] = set()
|
||||
missing: list[tuple[Path, str]] = []
|
||||
@@ -191,7 +197,10 @@ def build_public_url(base: str, object_path: str) -> str:
|
||||
|
||||
|
||||
def run_rclone_upload(
|
||||
root: Path, target: str, rel_files: Iterable[str], dry_run: bool,
|
||||
root: Path,
|
||||
target: str,
|
||||
rel_files: Iterable[str],
|
||||
dry_run: bool,
|
||||
) -> None:
|
||||
if shutil.which("rclone") is None:
|
||||
raise RuntimeError("rclone not found in PATH")
|
||||
@@ -262,7 +271,9 @@ def rewrite_markdown_files(
|
||||
if not url:
|
||||
return match.group(0)
|
||||
return match.group(0).replace(
|
||||
f"src={quote_ch}{raw}{quote_ch}", f"src={quote_ch}{url}{quote_ch}", 1,
|
||||
f"src={quote_ch}{raw}{quote_ch}",
|
||||
f"src={quote_ch}{url}{quote_ch}",
|
||||
1,
|
||||
)
|
||||
|
||||
updated = MD_IMAGE_RE.sub(md_repl, text)
|
||||
|
||||
Reference in New Issue
Block a user