mirror of
https://github.com/sipeed/sipeed_wiki.git
synced 2026-11-09 17:44:31 -06:00
fix(tools): resolve site-absolute image paths the way teedoc does
构建产物核验发现检查器有 3 个误报,成因是绝对路径解析不全: - /news/... 由 blog 插件发布,site_config 的 route 里没有登记 - 不匹配任何路由的绝对路径,teedoc 是按「该文档所属路由的根」解析, 而不是站点根。例如 /assets/x.jpg 出现在 docs/soft/maixpy/en/ 的 页面里,实际指向 docs/soft/maixpy/assets/x.jpg 补上这两条回退后,断链 121 -> 118,基线同步更新。 拿构建产物复核:118 项里 112 项在生成的网站里确实取不到。
This commit is contained in:
@@ -47,6 +47,8 @@ def load_routes():
|
||||
for url, targets in (cfg.get("translate", {}).get("docs") or {}).items():
|
||||
for t in targets:
|
||||
routes[t["url"]] = t["src"]
|
||||
# news/ 由 blog 插件发布在 /news/ 下,site_config 的 route 里没有登记
|
||||
routes.setdefault("/news/", "news")
|
||||
return dict(sorted(routes.items(), key=lambda kv: -len(kv[0])))
|
||||
|
||||
|
||||
@@ -62,6 +64,16 @@ def resolve(ref, page_path, routes):
|
||||
for url, path in routes.items():
|
||||
if ref.startswith(url):
|
||||
return os.path.normpath(os.path.join(ROOT, path, ref[len(url):]))
|
||||
# 不匹配任何路由时,teedoc 把绝对路径按「该文档所属路由的根」解析,
|
||||
# 而不是站点根。例如 /assets/x.jpg 出现在 docs/soft/maixpy/en/ 下的页面里,
|
||||
# 实际指向 docs/soft/maixpy/assets/x.jpg。
|
||||
rel_page = os.path.relpath(page_path, ROOT)
|
||||
for _url, path in routes.items():
|
||||
if rel_page.startswith(path + os.sep):
|
||||
cand = os.path.normpath(
|
||||
os.path.join(ROOT, os.path.dirname(path), ref.lstrip("/")))
|
||||
if os.path.exists(cand):
|
||||
return cand
|
||||
return os.path.normpath(os.path.join(ROOT, ref.lstrip("/")))
|
||||
return os.path.normpath(os.path.join(os.path.dirname(page_path), ref))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user