feat: add tested Anime.js example registries and offline gallery
This commit is contained in:
1 parent
6854138486
commit
55e559dcd1
17 files changed
+388
-6
No files matched your search
@@ -0,0 +1,27 @@
|
||||
"""Dependency-free, offline gallery packager. Run from any directory."""
|
||||
from pathlib import Path
|
||||
import hashlib
|
||||
import html
|
||||
import json
|
||||
import re
|
||||
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
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']:
|
||||
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()}}
|
||||
(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