mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
script type=module support, closes #1186
This commit is contained in:
parent
640ac7071b
commit
fa0c3777b8
6 changed files with 74 additions and 24 deletions
|
|
@ -864,19 +864,23 @@ class Datasette:
|
|||
if isinstance(url_or_dict, dict):
|
||||
url = url_or_dict["url"]
|
||||
sri = url_or_dict.get("sri")
|
||||
module = bool(url_or_dict.get("module"))
|
||||
else:
|
||||
url = url_or_dict
|
||||
sri = None
|
||||
module = False
|
||||
if url in seen_urls:
|
||||
continue
|
||||
seen_urls.add(url)
|
||||
if url.startswith("/"):
|
||||
# Take base_url into account:
|
||||
url = self.urls.path(url)
|
||||
script = {"url": url}
|
||||
if sri:
|
||||
output.append({"url": url, "sri": sri})
|
||||
else:
|
||||
output.append({"url": url})
|
||||
script["sri"] = sri
|
||||
if module:
|
||||
script["module"] = True
|
||||
output.append(script)
|
||||
return output
|
||||
|
||||
def app(self):
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
<link rel="stylesheet" href="{{ url.url }}"{% if url.sri %} integrity="{{ url.sri }}" crossorigin="anonymous"{% endif %}>
|
||||
{% endfor %}
|
||||
{% for url in extra_js_urls %}
|
||||
<script src="{{ url.url }}"{% if url.sri %} integrity="{{ url.sri }}" crossorigin="anonymous"{% endif %}></script>
|
||||
<script {% if url.module %}type="module" {% endif %}src="{{ url.url }}"{% if url.sri %} integrity="{{ url.sri }}" crossorigin="anonymous"{% endif %}></script>
|
||||
{% endfor %}
|
||||
{% block extra_head %}{% endblock %}
|
||||
</head>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue