feat: 增加成果回存示例与播客在线播放
This commit is contained in:
1 parent
706d6c3b33
commit
f710617927
6 files changed
+141
-67
No files matched your search
+14
-2
@@ -11,6 +11,7 @@ import re
|
||||
from collections import Counter
|
||||
from html.parser import HTMLParser
|
||||
from pathlib import Path
|
||||
from urllib.parse import quote
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
OUTPUT = ROOT / "index.html"
|
||||
@@ -83,6 +84,16 @@ def build():
|
||||
scripts.append("const MATERIAL_ZIP=" + json.dumps(base64.b64encode(material).decode()) + ";")
|
||||
scripts.append((ROOT / "src/runtime/player.js").read_text())
|
||||
image_types = {}
|
||||
media_urls = set()
|
||||
|
||||
def link_media(match):
|
||||
name = match[1]
|
||||
path = (ROOT / "materials" / name).resolve()
|
||||
require((ROOT / "materials").resolve() in path.parents, f"音频路径越界: {name}")
|
||||
require(path.is_file() and path.suffix.lower() == ".mp3", f"音频文件不存在或格式不支持: {name}")
|
||||
url = "materials/" + quote(name, safe="/")
|
||||
media_urls.add(url)
|
||||
return url
|
||||
|
||||
def inline_asset(match):
|
||||
name = match[1]
|
||||
@@ -117,6 +128,7 @@ def build():
|
||||
text = text.replace("{{PAGE_COUNT}}", str(len(ids)))
|
||||
# asset: paths are relative to assets/, independent of the page's location.
|
||||
text = re.sub(r"asset:([^\"'<>\s]+)", inline_asset, text)
|
||||
text = re.sub(r"media:([^\"'<>\s]+)", link_media, text)
|
||||
pages.append(text.strip())
|
||||
for css in page_styles:
|
||||
styles.append(scoped_css(css, page_id))
|
||||
@@ -138,8 +150,8 @@ def build():
|
||||
duplicates = [key for key, count in Counter(parsed.ids).items() if count > 1]
|
||||
require(not duplicates, "存在重复 HTML ID: " + ", ".join(duplicates))
|
||||
require(len(parsed.sections) == len(ids), "最终页面数不一致")
|
||||
require(all(url.startswith("data:") for url in parsed.resources),
|
||||
"播放资源必须内嵌,不能依赖网络或本地相对路径")
|
||||
require(all(url.startswith("data:") or url in media_urls for url in parsed.resources),
|
||||
"资源必须内嵌,或引用已验证的本地音频")
|
||||
return result, material, len(ids)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user