feat: enhance scripts with filtering and offline-package support

### Changes:

1. **scripts/gen_docs_manifest.py**
   - Added --include parameter with default "docs"
   - Filters documentation files to only include specified directories
   - Can be provided multiple times for multiple directories
   - Updated docstring to document the new parameter

2. **scripts/gen_mirror_manifest.py**
   - Added generation of offline-package.json file
   - Filters listings to only include offline-package directory entries
   - Writes to the same output directory alongside manifest.json

### Usage:

For gen_docs_manifest.py:
  python3 scripts/gen_docs_manifest.py \
    --root /data/update-server/docs \
    --base-url-prefix https://dl.svc.plus/docs \
    --include docs

For gen_mirror_manifest.py:
  python3 scripts/gen_mirror_manifest.py \
    --root /data/update-server \
    --include offline-package \
    --output dl-index/

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Haitao Pan 2025-11-11 17:53:36 +08:00
parent cdcaccc6d9
commit d4a4dc186b
2 changed files with 25 additions and 3 deletions

View File

@ -16,7 +16,8 @@ Usage example::
python3 scripts/gen_docs_manifest.py \
--root /data/update-server/docs \
--base-url-prefix https://dl.svc.plus/docs
--base-url-prefix https://dl.svc.plus/docs \
--include docs
The command is idempotent and safe to rerun. Hidden files/directories (prefixed
with ``.``) are ignored. Only ``.pdf`` and ``.html`` assets are considered for
@ -239,8 +240,9 @@ def create_entry(parts: Tuple[str, ...]) -> DocEntry:
)
def collect_docs(root: Path, base_prefix: str) -> List[DocEntry]:
def collect_docs(root: Path, base_prefix: str, include: List[str]) -> List[DocEntry]:
entries: Dict[Tuple[str, ...], DocEntry] = {}
include_set = set(include)
for file_path in root.rglob("*"):
if not file_path.is_file():
@ -251,6 +253,10 @@ def collect_docs(root: Path, base_prefix: str) -> List[DocEntry]:
if should_skip(rel):
continue
# Check if file is in an included directory
if rel.parts and rel.parts[0] not in include_set:
continue
parts = rel.parts[:-1] + (file_path.stem,)
if not parts:
continue
@ -290,6 +296,12 @@ def parse_args() -> argparse.Namespace:
parser.add_argument("--base-url-prefix", default="/docs", help="URL prefix to prepend to asset paths")
parser.add_argument("--output", default="all.json", help="Output filename (default: all.json)")
parser.add_argument("--quiet", action="store_true", help="Suppress progress output")
parser.add_argument(
"--include",
default=["docs"],
action="append",
help="Directory names to include in the manifest. Can be provided multiple times. (default: docs)",
)
return parser.parse_args()
@ -299,7 +311,7 @@ def main() -> None:
if not root.exists() or not root.is_dir():
raise SystemExit(f"Root path does not exist or is not a directory: {root}")
entries = collect_docs(root, args.base_url_prefix)
entries = collect_docs(root, args.base_url_prefix, args.include)
if not args.quiet:
print(f"Discovered {len(entries)} documentation entries under {root}")

View File

@ -261,5 +261,15 @@ def main():
if not args.quiet:
print(f"Wrote {output_path / 'manifest.json'}")
# Create offline-package.json specifically for offline-package directory
offline_package_listings = [
listing for listing in listings
if listing.get('path', '').startswith('offline-package/') or listing.get('path', '') == 'offline-package/'
]
if offline_package_listings:
write_json(output_path / "offline-package.json", offline_package_listings)
if not args.quiet:
print(f"Wrote {output_path / 'offline-package.json'}")
if __name__ == "__main__":
main()