diff --git a/src/psc/app.py b/src/psc/app.py
index 55fd890..875cfd2 100644
--- a/src/psc/app.py
+++ b/src/psc/app.py
@@ -20,7 +20,6 @@
from psc.resources import Resources
from psc.resources import get_resources
-
templates = Jinja2Templates(directory=HERE / "templates")
@@ -68,6 +67,14 @@ async def example(request: Request) -> _TemplateResponse:
this_example = resources.examples[example_path]
root_path = "../../.."
+ # Set the pyscript URL to the CDN if we are being built from
+ # the ``psc build`` command.
+ user_agent = request.headers["user-agent"]
+ if user_agent == "testclient":
+ pyscript_url = "https://pyscript.net/latest/pyscript.js"
+ else:
+ pyscript_url = f"{root_path}/pyscript/pyscript.js"
+
return templates.TemplateResponse(
"example.jinja2",
dict(
@@ -77,6 +84,7 @@ async def example(request: Request) -> _TemplateResponse:
body=this_example.body,
request=request,
root_path=root_path,
+ pyscript_url=pyscript_url,
),
)
diff --git a/src/psc/resources.py b/src/psc/resources.py
index bf96c22..808b4bf 100644
--- a/src/psc/resources.py
+++ b/src/psc/resources.py
@@ -51,7 +51,8 @@ def get_head_nodes(s: BeautifulSoup) -> str:
def is_local(test_path: Path = PYODIDE) -> bool:
"""Use a policy to decide local vs. CDN mode."""
- return test_path.exists()
+ pyscript_file = test_path / "pyscript.js"
+ return pyscript_file.exists()
def get_body_content(s: BeautifulSoup, test_path: Path = PYODIDE) -> str:
diff --git a/src/psc/templates/example.jinja2 b/src/psc/templates/example.jinja2
index 3939624..a766282 100644
--- a/src/psc/templates/example.jinja2
+++ b/src/psc/templates/example.jinja2
@@ -1,7 +1,7 @@
{% extends "layout.jinja2" %}
{% block extra_head %}
-
+
{{ extra_head | safe }}{% endblock %}
{% block main %}