feat: reusable registry galleries and individual HTML examples [verified]
This commit is contained in:
1 parent
55e559dcd1
commit
3bb9555e6a
67 files changed
+1229
-77
No files matched your search
+24
-14
@@ -1,7 +1,6 @@
|
||||
"""Dependency-free, offline gallery packager. Run from any directory."""
|
||||
"""Build an offline hierarchy; individual pages embed every runtime dependency."""
|
||||
from pathlib import Path
|
||||
import hashlib
|
||||
import html
|
||||
import json
|
||||
import re
|
||||
|
||||
@@ -10,18 +9,29 @@ source = root / 'assets/animejs'
|
||||
vendor = root / 'assets/vendor/anime.umd.min.js'
|
||||
entries = [entry for entry in json.loads((root / 'vendor-manifest.json').read_text(encoding='utf-8'))
|
||||
if entry['path'] == 'assets/vendor/anime.umd.min.js']
|
||||
if len(entries) != 1 or hashlib.sha256(vendor.read_bytes()).hexdigest() != entries[0]['sha256']:
|
||||
def digest(path):
|
||||
return hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
if len(entries) != 1 or digest(vendor) != entries[0]['sha256']:
|
||||
raise ValueError('Missing, duplicate or mismatched Anime vendor fingerprint')
|
||||
text = (source / 'index.html').read_text()
|
||||
text = text.replace('<link rel="stylesheet" href="gallery.css">', '<style>' + (source / 'gallery.css').read_text() + '</style>')
|
||||
for name, file in [('../vendor/anime.umd.min.js', vendor), ('examples.js', source / 'examples.js'), ('gallery.js', source / 'gallery.js')]:
|
||||
js = re.sub(r'//# sourceMappingURL=.*', '', file.read_text())
|
||||
text = text.replace(f'<script src="{name}"></script>', '<script>' + js.replace('</script', r'<\/script') + '</script>')
|
||||
text = text.replace('ANIME_LICENSE', html.escape((root / 'assets/vendor/anime-LICENSE.md').read_text()))
|
||||
out = root / 'dist/animejs-gallery-0.4.0.html'
|
||||
out.parent.mkdir(exist_ok=True)
|
||||
out.write_text(text)
|
||||
inputs = [*sorted(source.glob('*')), vendor, root / 'assets/vendor/anime-LICENSE.md']
|
||||
report = {'file': out.name, 'sha256': hashlib.sha256(out.read_bytes()).hexdigest(), 'anime':'4.5.0', 'examples':5, 'inputs':{str(p.relative_to(root)):hashlib.sha256(p.read_bytes()).hexdigest() for p in inputs if p.is_file()}}
|
||||
out = root / 'dist/animejs-gallery-0.5.0'
|
||||
files = {}
|
||||
for page in sorted(source.rglob('*.html')):
|
||||
text = page.read_text(encoding='utf-8')
|
||||
def style(match):
|
||||
return '<style>' + (page.parent / match[1]).read_text(encoding='utf-8') + '</style>'
|
||||
def script(match):
|
||||
js = re.sub(r'//# sourceMappingURL=.*', '', (page.parent / match[1]).read_text(encoding='utf-8'))
|
||||
return '<script>' + js.replace('</script', r'<\/script') + '</script>'
|
||||
text = re.sub(r'<link rel="stylesheet" href="([^"]+)">', style, text)
|
||||
text = re.sub(r'<script src="([^"]+)"></script>', script, text)
|
||||
if 'ANIME_LICENSE' in text:
|
||||
raise ValueError('Unresolved license placeholder')
|
||||
target = out / page.relative_to(source)
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_text(text, encoding='utf-8')
|
||||
files[str(target.relative_to(out))] = digest(target)
|
||||
inputs = [*sorted(source.rglob('*')), vendor, root / 'assets/vendor/anime-LICENSE.md']
|
||||
report = {'package': out.name, 'entry': 'index.html', 'anime': '4.5.0', 'examples': 5,
|
||||
'files': files, 'inputs': {str(p.relative_to(root)): digest(p) for p in inputs if p.is_file()}}
|
||||
(root / 'dist/animejs-gallery-manifest.json').write_text(json.dumps(report, indent=2) + '\n')
|
||||
print(json.dumps(report, indent=2))
|
||||
Reference in new issue
Block a user