Preserve cache-busting URL prefix on js/css - closes #11

Also ensure we ship the .map files for better browser debugging.
This commit is contained in:
Simon Willison 2018-07-06 17:45:04 -07:00
commit 8b650feca3
2 changed files with 25 additions and 6 deletions

View file

@ -1,11 +1,29 @@
from datasette import hookimpl
import glob
import os
cache = {}
static_dir = os.path.join(
os.path.dirname(__file__), 'static'
)
def cached_filepaths_for_extension(extension):
pattern = os.path.join(static_dir, '*.{}'.format(extension))
if pattern not in cache:
cache[pattern] = [
"/-/static-plugins/datasette_vega/{}".format(
os.path.basename(g)
)
for g in glob.glob(pattern)
]
return cache[pattern]
@hookimpl
def extra_css_urls():
return ["/-/static-plugins/datasette_vega/datasette-vega.css"]
return cached_filepaths_for_extension('css')
@hookimpl
def extra_js_urls():
return ["/-/static-plugins/datasette_vega/datasette-vega.js"]
return cached_filepaths_for_extension('js')

View file

@ -34,8 +34,8 @@ class BuildStatic(Command):
check_output(['npm', 'install'], cwd=ROOT)
check_output(['npm', 'run', 'build'], cwd=ROOT)
check_output(['mkdir', '-p', 'datasette_vega/static'], cwd=ROOT)
check_output("mv build/static/js/*.js datasette_vega/static/datasette-vega.js", shell=True, cwd=ROOT)
check_output("mv build/static/css/*.css datasette_vega/static/datasette-vega.css", shell=True, cwd=ROOT)
check_output("mv build/static/js/* datasette_vega/static/", shell=True, cwd=ROOT)
check_output("mv build/static/css/* datasette_vega/static/", shell=True, cwd=ROOT)
setup(
@ -55,8 +55,9 @@ setup(
},
package_data={
'datasette_vega': [
'static/datasette-vega.js',
'static/datasette-vega.css',
'static/*.js',
'static/*.css',
'static/*.map',
],
},
cmdclass={