setup/mathjax: fallback to using packed versions of resources

Some mathjax distributions come with the unpacked versions removed as
per the upstream instructions for optimizing an installation. Only use
the unpacked versions if they exist; otherwise fallback on the packed
versions.

Also filter the .woff files to make sure they are actually .woff files,
since they may be files like fonts.dir, fonts.scale, .uuid (created by
xorg-mkfontdir, xorg-mkfontscale, fontconfig).
This commit is contained in:
Eli Schwartz 2018-12-19 02:14:00 -05:00
parent b5dff9ba89
commit 6adedd8603

View File

@ -47,12 +47,13 @@ class MathJax(Command):
with open(dest, 'wb') as f: with open(dest, 'wb') as f:
f.write(raw) f.write(raw)
def add_tree(self, base, prefix): def add_tree(self, base, prefix, ignore=lambda n:False):
for dirpath, dirnames, filenames in os.walk(base): for dirpath, dirnames, filenames in os.walk(base):
for fname in filenames: for fname in filenames:
f = os.path.join(dirpath, fname) f = os.path.join(dirpath, fname)
name = prefix + '/' + os.path.relpath(f, base).replace(os.sep, '/') name = prefix + '/' + os.path.relpath(f, base).replace(os.sep, '/')
self.add_file(f, name) if not ignore(name):
self.add_file(f, name)
def clean(self): def clean(self):
self.mathjax_dir = self.j(self.RESOURCES, 'mathjax') self.mathjax_dir = self.j(self.RESOURCES, 'mathjax')
@ -68,10 +69,11 @@ class MathJax(Command):
try: try:
src = opts.path_to_mathjax or self.download_mathjax_release(tdir, opts.mathjax_url) src = opts.path_to_mathjax or self.download_mathjax_release(tdir, opts.mathjax_url)
self.info('Adding MathJax...') self.info('Adding MathJax...')
self.add_file(self.j(src, 'unpacked', 'MathJax.js'), 'MathJax.js') unpacked = 'unpacked' if self.e(self.j(src, 'unpacked')) else ''
self.add_tree(self.j(src, 'fonts', 'HTML-CSS', self.FONT_FAMILY, 'woff'), 'fonts/HTML-CSS/%s/woff' % self.FONT_FAMILY) self.add_file(self.j(src, unpacked, 'MathJax.js'), 'MathJax.js')
self.add_tree(self.j(src, 'fonts', 'HTML-CSS', self.FONT_FAMILY, 'woff'), 'fonts/HTML-CSS/%s/woff' % self.FONT_FAMILY, lambda x: not x.endswith('.woff'))
for d in 'extensions jax/element jax/input jax/output/CommonHTML'.split(): for d in 'extensions jax/element jax/input jax/output/CommonHTML'.split():
self.add_tree(self.j(src, 'unpacked', *d.split('/')), d) self.add_tree(self.j(src, unpacked, *d.split('/')), d)
etag = self.h.hexdigest() etag = self.h.hexdigest()
with open(self.j(self.RESOURCES, 'mathjax', 'manifest.json'), 'wb') as f: with open(self.j(self.RESOURCES, 'mathjax', 'manifest.json'), 'wb') as f:
f.write(json.dumps({'etag': etag, 'files': self.mathjax_files}, indent=2).encode('utf-8')) f.write(json.dumps({'etag': etag, 'files': self.mathjax_files}, indent=2).encode('utf-8'))