mirror of
https://github.com/simonw/datasette-vega.git
synced 2026-09-10 18:44:21 +02:00
28 lines
700 B
Python
28 lines
700 B
Python
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(view_name):
|
|
if view_name == "table":
|
|
return cached_filepaths_for_extension("css")
|
|
|
|
|
|
@hookimpl
|
|
def extra_js_urls(view_name):
|
|
if view_name == "table":
|
|
return cached_filepaths_for_extension("js")
|