# -*- coding: utf-8 -*-
import io, sys, re, os, json
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
b = r"D:\work buddy\2026-11-05-14-15-52"
t = open(os.path.join(b, "index_main.html"), encoding="utf-8").read()
ext = re.findall(r'(?:src|href)="([^"]+)"', t)
loc = [x for x in ext if not x.startswith("http") and not x.startswith("#") and not x.startswith("mailto")]
from collections import Counter
print("本地/相对引用数:", len(loc))
print(Counter(loc).most_common(10))
print("外链样例:", [x for x in ext if x.startswith("http")][:5])
# 提取引用的详情页集合
det = set(re.findall(r'"(details/[^"]+\.html)"', t))
print("主文件引用详情页数:", len(det))
# 磁盘上详情页
disk = set("details/" + n for n in os.listdir(os.path.join(b, "details")) if n.endswith(".html"))
print("磁盘详情页:", len(disk))
print("引用但磁盘缺失:", len(det - disk))
print("磁盘有但未引用(可不带):", len(disk - det))
json.dump(sorted(det), open(os.path.join(b, "_publish_det.json"), "w", encoding="utf-8"), ensure_ascii=False)
