File tree 3 files changed +12
-3
lines changed
3 files changed +12
-3
lines changed Original file line number Diff line number Diff line change 20
20
from psc .resources import Resources
21
21
from psc .resources import get_resources
22
22
23
-
24
23
templates = Jinja2Templates (directory = HERE / "templates" )
25
24
26
25
@@ -68,6 +67,14 @@ async def example(request: Request) -> _TemplateResponse:
68
67
this_example = resources .examples [example_path ]
69
68
root_path = "../../.."
70
69
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
+
71
78
return templates .TemplateResponse (
72
79
"example.jinja2" ,
73
80
dict (
@@ -77,6 +84,7 @@ async def example(request: Request) -> _TemplateResponse:
77
84
body = this_example .body ,
78
85
request = request ,
79
86
root_path = root_path ,
87
+ pyscript_url = pyscript_url ,
80
88
),
81
89
)
82
90
Original file line number Diff line number Diff line change @@ -51,7 +51,8 @@ def get_head_nodes(s: BeautifulSoup) -> str:
51
51
52
52
def is_local (test_path : Path = PYODIDE ) -> bool :
53
53
"""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 ()
55
56
56
57
57
58
def get_body_content (s : BeautifulSoup , test_path : Path = PYODIDE ) -> str :
Original file line number Diff line number Diff line change 1
1
{% extends "layout.jinja2" %}
2
2
{% block extra_head %}
3
3
<meta name =" subtitle" content =" {{ subtitle }}" >
4
- <script defer src =" {{ root_path }}/pyscript/pyscript.js " ></script >
4
+ <script defer src =" {{ pyscript_url }}" ></script >
5
5
{{ extra_head | safe }}{% endblock %}
6
6
{% block main %}
7
7
<main id =" main_container" class =" container" >
You can’t perform that action at this time.
0 commit comments