Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.11.2
* resource module correctly places import map before preload links
* bugfix: relative paths were stripped in cache_bust=true

# 0.11.1
* livereload fix: live server waits for daemon to terminate before restarting
* livereload fix: Fix bug for ignore_glob not firing
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "html-compose"
version = "0.11.1"
version = "0.11.2"
description = "Composable HTML generation in python"
authors = [
{ name = "jealouscloud", email = "[email protected]" }
Expand Down
2 changes: 1 addition & 1 deletion src/html_compose/resource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def to_elements(
import_map["scopes"] = scopes
# dump to json; prevent escapes
js_dump = json.dumps(import_map).replace("<", "\\u003c")
script_tags.insert(
preload_links.insert(
0, el.script(type="importmap")[unsafe_text(js_dump)]
)
style_text: list[str] = []
Expand Down
3 changes: 1 addition & 2 deletions src/html_compose/resource/util_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def _cachebust_resource_uri(source: str):
"does not exist"
) from exc

source = source.lstrip("/")
resource_path = path.join(base_dir, source)
resource_path = path.join(base_dir, source.lstrip("/"))
now = time()
ts = misc_stat_cache.get(path.join(base_dir, source), None)
update_ts = ts is None or (now - ts) > settings.stat_poll_interval
Expand Down
12 changes: 6 additions & 6 deletions tests/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ def test_js_import():
]
expected = [
"<head>",
'<link href="./static/admin.js" rel="modulepreload"/>',
'<link href="https://cdn.jsdelivr.net/npm/[email protected]/+esm" integrity="sha384-Yf57wlxlrA1+0X6Ye9NOBxQ1tpmiwI/9mFpv9tT/Rh2UAajwwAlTWHnvTGYhgv7p" crossorigin="anonymous" rel="modulepreload"/>',
'<script type="importmap">',
'{"imports": {"admin": "./static/admin.js", "alpinejs": "https://cdn.jsdelivr.net/npm/[email protected]/+esm"}}',
"</script>",
'<link href="./static/admin.js" rel="modulepreload"/>',
'<link href="https://cdn.jsdelivr.net/npm/[email protected]/+esm" integrity="sha384-Yf57wlxlrA1+0X6Ye9NOBxQ1tpmiwI/9mFpv9tT/Rh2UAajwwAlTWHnvTGYhgv7p" crossorigin="anonymous" rel="modulepreload"/>',
'<script src="./static/admin.js" type="module">',
"</script>",
'<script src="https://cdn.jsdelivr.net/npm/[email protected]/+esm" type="module" integrity="sha384-Yf57wlxlrA1+0X6Ye9NOBxQ1tpmiwI/9mFpv9tT/Rh2UAajwwAlTWHnvTGYhgv7p" crossorigin="anonymous">',
Expand Down Expand Up @@ -261,13 +261,13 @@ def test_importer():
elements = to_elements(js, css)
expected = [
"<head>",
'<script type="importmap">',
'{"imports": {"admin": "./static/admin.js", "alpinejs": "https://cdn.jsdelivr.net/npm/[email protected]/+esm"}}',
"</script>",
'<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous" as="style" rel="preload"/>',
'<link href="https://cdn.jsdelivr.net/npm/[email protected]/+esm" integrity="sha384-Yf57wlxlrA1+0X6Ye9NOBxQ1tpmiwI/9mFpv9tT/Rh2UAajwwAlTWHnvTGYhgv7p" crossorigin="anonymous" rel="modulepreload"/>',
'<link href="./static/admin.css" rel="stylesheet"/>',
'<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous" rel="stylesheet"/>',
'<script type="importmap">',
'{"imports": {"admin": "./static/admin.js", "alpinejs": "https://cdn.jsdelivr.net/npm/[email protected]/+esm"}}',
"</script>",
'<script src="./static/admin.js" type="module">',
"</script>",
'<script src="https://cdn.jsdelivr.net/npm/[email protected]/+esm" type="module" integrity="sha384-Yf57wlxlrA1+0X6Ye9NOBxQ1tpmiwI/9mFpv9tT/Rh2UAajwwAlTWHnvTGYhgv7p" crossorigin="anonymous">',
Expand Down Expand Up @@ -298,7 +298,7 @@ def test_document_generator():
title="demo", lang="en", js=js, css=css, body=[el.h1()["Hello world"]]
).stream("full")
expected = [
'<!DOCTYPE html>\n<html lang="en">\n<head><meta content="width=device-width, initial-scale=1.0" name="viewport"/><title>demo</title><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous" as="style" rel="preload"/><link href="https://cdn.jsdelivr.net/npm/[email protected]/+esm" integrity="sha384-Yf57wlxlrA1+0X6Ye9NOBxQ1tpmiwI/9mFpv9tT/Rh2UAajwwAlTWHnvTGYhgv7p" crossorigin="anonymous" rel="modulepreload"/><link href="./static/admin.css" rel="stylesheet"/><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous" rel="stylesheet"/><script type="importmap">{"imports": {"admin": "./static/admin.js", "alpinejs": "https://cdn.jsdelivr.net/npm/[email protected]/+esm"}}</script><script src="./static/admin.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/[email protected]/+esm" type="module" integrity="sha384-Yf57wlxlrA1+0X6Ye9NOBxQ1tpmiwI/9mFpv9tT/Rh2UAajwwAlTWHnvTGYhgv7p" crossorigin="anonymous"></script></head>\n\n',
'<!DOCTYPE html>\n<html lang="en">\n<head><meta content="width=device-width, initial-scale=1.0" name="viewport"/><title>demo</title><script type="importmap">{"imports": {"admin": "./static/admin.js", "alpinejs": "https://cdn.jsdelivr.net/npm/[email protected]/+esm"}}</script><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous" as="style" rel="preload"/><link href="https://cdn.jsdelivr.net/npm/[email protected]/+esm" integrity="sha384-Yf57wlxlrA1+0X6Ye9NOBxQ1tpmiwI/9mFpv9tT/Rh2UAajwwAlTWHnvTGYhgv7p" crossorigin="anonymous" rel="modulepreload"/><link href="./static/admin.css" rel="stylesheet"/><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous" rel="stylesheet"/><script src="./static/admin.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/[email protected]/+esm" type="module" integrity="sha384-Yf57wlxlrA1+0X6Ye9NOBxQ1tpmiwI/9mFpv9tT/Rh2UAajwwAlTWHnvTGYhgv7p" crossorigin="anonymous"></script></head>\n\n',
"<body>",
"<h1>",
"Hello world",
Expand Down