File tree Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Original file line number Diff line number Diff line change 2020from psc .resources import Resources
2121from psc .resources import get_resources
2222
23-
2423templates = Jinja2Templates (directory = HERE / "templates" )
2524
2625
@@ -68,6 +67,14 @@ async def example(request: Request) -> _TemplateResponse:
6867 this_example = resources .examples [example_path ]
6968 root_path = "../../.."
7069
70+ # Set the pyscript URL to the CDN if we are being built from
71+ # the ``psc build`` command.
72+ user_agent = request .headers ["user-agent" ]
73+ if user_agent == "testclient" :
74+ pyscript_url = "https://pyscript.net/latest/pyscript.js"
75+ else :
76+ pyscript_url = f"{ root_path } /pyscript/pyscript.js"
77+
7178 return templates .TemplateResponse (
7279 "example.jinja2" ,
7380 dict (
@@ -77,6 +84,7 @@ async def example(request: Request) -> _TemplateResponse:
7784 body = this_example .body ,
7885 request = request ,
7986 root_path = root_path ,
87+ pyscript_url = pyscript_url ,
8088 ),
8189 )
8290
Original file line number Diff line number Diff line change @@ -51,7 +51,8 @@ def get_head_nodes(s: BeautifulSoup) -> str:
5151
5252def is_local (test_path : Path = PYODIDE ) -> bool :
5353 """Use a policy to decide local vs. CDN mode."""
54- return test_path .exists ()
54+ pyscript_file = test_path / "pyscript.js"
55+ return pyscript_file .exists ()
5556
5657
5758def get_body_content (s : BeautifulSoup , test_path : Path = PYODIDE ) -> str :
Original file line number Diff line number Diff line change 11{% extends "layout.jinja2" %}
22{% block extra_head %}
33 <meta name =" subtitle" content =" {{ subtitle }}" >
4- <script defer src =" {{ root_path }}/pyscript/pyscript.js " ></script >
4+ <script defer src =" {{ pyscript_url }}" ></script >
55 {{ extra_head | safe }}{% endblock %}
66{% block main %}
77 <main id =" main_container" class =" container" >
You can’t perform that action at this time.
0 commit comments