Skip to content

Commit b52cb74

Browse files
committed
clean up full page detection
1 parent d132f50 commit b52cb74

20 files changed

+136
-145
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ ChatGPT, Claude, and Copilot won’t give useful answers about it. To fix
9090
that problem, we’ve provided an LLM-friendly guide that teaches them how
9191
to use FastHTML. To use it, add this link for your AI helper to use:
9292

93-
- [/llms-ctx.txt](https://docs.fastht.ml/llms-ctx.txt)
93+
- [/llms-ctx.txt](https://www.fastht.ml/docs/llms-ctx.txt)
9494

9595
This example is in a format based on recommendations from Anthropic for
9696
use with [Claude
@@ -114,8 +114,8 @@ Start with the official sources to learn more about FastHTML:
114114

115115
- [About](https://fastht.ml/about): Learn about the core ideas behind
116116
FastHTML
117-
- [Documentation](https://docs.fastht.ml): Learn from examples how to
118-
write FastHTML code
117+
- [Documentation](https://www.fastht.ml/docs): Learn from examples how
118+
to write FastHTML code
119119
- [Idiomatic
120120
app](https://github.com/AnswerDotAI/fasthtml/blob/main/examples/adv_app.py):
121121
Heavily commented source code walking through a complete application,

docs/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<meta http-equiv="refresh" content="0; url=https://docs.fastht.ml" />
4+
<meta http-equiv="refresh" content="0; url=https://www.fastht.ml/docs" />
55
<title>Redirecting...</title>
66
</head>
77
<body>
8-
<p>If you are not redirected automatically, <a href="answerdotai.github.io/fasthtml">click here</a>.</p>
8+
<p>If you are not redirected automatically, <a href="www.fastht.ml/docs">click here</a>.</p>
99
</body>
1010
</html>

fasthtml/_modidx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Autogenerated by nbdev
22

33
d = { 'settings': { 'branch': 'main',
4-
'doc_baseurl': '/',
5-
'doc_host': 'https://docs.fastht.ml',
4+
'doc_baseurl': '/docs/',
5+
'doc_host': 'https://www.fastht.ml',
66
'git_url': 'https://github.com/AnswerDotAI/fasthtml',
77
'lib_path': 'fasthtml'},
88
'syms': { 'fasthtml.authmw': {},

fasthtml/core.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,8 @@ def respond(req, heads, bdy):
390390

391391
# %% ../nbs/api/00_core.ipynb
392392
def is_full_page(req, resp):
393-
is_frag = 'hx-request' in req.headers and 'hx-history-restore-request' not in req.headers
394-
return (resp and not is_frag and not any(getattr(o, 'tag', '')=='html' for o in resp))
393+
if resp and any(getattr(o, 'tag', '')=='html' for o in resp): return True
394+
return 'hx-request' in req.headers and 'hx-history-restore-request' not in req.headers
395395

396396
# %% ../nbs/api/00_core.ipynb
397397
def _part_resp(req, resp):
@@ -414,7 +414,7 @@ def _xt_cts(req, resp):
414414
hdr_tags = 'title','meta','link','style','base'
415415
resp = tuplify(resp)
416416
heads,bdy = partition(resp, lambda o: getattr(o, 'tag', '') in hdr_tags)
417-
if is_full_page(req, resp):
417+
if not is_full_page(req, resp):
418418
title = [] if any(getattr(o, 'tag', '')=='title' for o in heads) else [Title(req.app.title)]
419419
resp = respond(req, [*heads, *title], bdy)
420420
return _to_xml(req, resp, indent=fh_cfg.indent)
@@ -424,7 +424,7 @@ def _is_ft_resp(resp): return isinstance(resp, _iter_typs+(HttpHeader,FT)) or ha
424424

425425
# %% ../nbs/api/00_core.ipynb
426426
def _resp(req, resp, cls=empty, status_code=200):
427-
if not resp: resp=()
427+
if not resp: resp=''
428428
if hasattr(resp, '__response__'): resp = resp.__response__(req)
429429
if cls in (Any,FT): cls=empty
430430
if isinstance(resp, FileResponse) and not os.path.exists(resp.path): raise HTTPException(404, resp.path)

nbs/CNAME

Lines changed: 0 additions & 1 deletion
This file was deleted.

nbs/_quarto.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ format:
1616
css: styles.css
1717
toc: true
1818
keep-md: true
19+
canonical-url: true
1920
commonmark: default
2021

2122
website:
2223
favicon: favicon.ico
2324
twitter-card:
2425
creator: "@jeremyphoward"
2526
site: "@answerdotai"
26-
image: https://docs.fastht.ml/og-image.png
27+
image: https://www.fastht.ml/docs/og-image.png
2728
open-graph: true
2829
repo-actions: [issue]
2930
navbar:

nbs/api/00_core.ipynb

Lines changed: 36 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
{
132132
"data": {
133133
"text/plain": [
134-
"datetime.datetime(2025, 5, 17, 14, 0)"
134+
"datetime.datetime(2025, 5, 19, 14, 0)"
135135
]
136136
},
137137
"execution_count": null,
@@ -754,6 +754,7 @@
754754
"name": "stdout",
755755
"output_type": "stream",
756756
"text": [
757+
"b'{}'\n",
757758
"[<starlette.requests.Request object>, <starlette.applications.Starlette object>, '']\n"
758759
]
759760
}
@@ -788,6 +789,7 @@
788789
"name": "stdout",
789790
"output_type": "stream",
790791
"text": [
792+
"b'{}'\n",
791793
"Missing required field: a\n"
792794
]
793795
}
@@ -1176,8 +1178,8 @@
11761178
"source": [
11771179
"#| export\n",
11781180
"def is_full_page(req, resp):\n",
1179-
" is_frag = 'hx-request' in req.headers and 'hx-history-restore-request' not in req.headers\n",
1180-
" return (resp and not is_frag and not any(getattr(o, 'tag', '')=='html' for o in resp))"
1181+
" if resp and any(getattr(o, 'tag', '')=='html' for o in resp): return True\n",
1182+
" return 'hx-request' in req.headers and 'hx-history-restore-request' not in req.headers"
11811183
]
11821184
},
11831185
{
@@ -1216,7 +1218,7 @@
12161218
" hdr_tags = 'title','meta','link','style','base'\n",
12171219
" resp = tuplify(resp)\n",
12181220
" heads,bdy = partition(resp, lambda o: getattr(o, 'tag', '') in hdr_tags)\n",
1219-
" if is_full_page(req, resp):\n",
1221+
" if not is_full_page(req, resp):\n",
12201222
" title = [] if any(getattr(o, 'tag', '')=='title' for o in heads) else [Title(req.app.title)]\n",
12211223
" resp = respond(req, [*heads, *title], bdy)\n",
12221224
" return _to_xml(req, resp, indent=fh_cfg.indent)"
@@ -1242,7 +1244,7 @@
12421244
"source": [
12431245
"#| export\n",
12441246
"def _resp(req, resp, cls=empty, status_code=200):\n",
1245-
" if not resp: resp=()\n",
1247+
" if not resp: resp=''\n",
12461248
" if hasattr(resp, '__response__'): resp = resp.__response__(req)\n",
12471249
" if cls in (Any,FT): cls=empty\n",
12481250
" if isinstance(resp, FileResponse) and not os.path.exists(resp.path): raise HTTPException(404, resp.path)\n",
@@ -1948,43 +1950,6 @@
19481950
"assert '<title>FastHTML page</title>' in txt and '<h1>bar</h1>' in txt and '<html>' in txt"
19491951
]
19501952
},
1951-
{
1952-
"cell_type": "code",
1953-
"execution_count": null,
1954-
"id": "4beffa04",
1955-
"metadata": {},
1956-
"outputs": [
1957-
{
1958-
"name": "stdout",
1959-
"output_type": "stream",
1960-
"text": [
1961-
" <!doctype html>\n",
1962-
" <html>\n",
1963-
" <head>\n",
1964-
" <title>FastHTML page</title>\n",
1965-
" <meta charset=\"utf-8\">\n",
1966-
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, viewport-fit=cover\">\n",
1967-
"<script src=\"https://cdn.jsdelivr.net/npm/htmx.org@2.0.4/dist/htmx.min.js\"></script><script src=\"https://cdn.jsdelivr.net/gh/answerdotai/fasthtml-js@1.0.12/fasthtml.js\"></script><script src=\"https://cdn.jsdelivr.net/gh/answerdotai/surreal@main/surreal.js\"></script><script src=\"https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js\"></script><script>\n",
1968-
" function sendmsg() {\n",
1969-
" window.parent.postMessage({height: document.documentElement.offsetHeight}, '*');\n",
1970-
" }\n",
1971-
" window.onload = function() {\n",
1972-
" sendmsg();\n",
1973-
" document.body.addEventListener('htmx:afterSettle', sendmsg);\n",
1974-
" document.body.addEventListener('htmx:wsAfterMessage', sendmsg);\n",
1975-
" };</script> </head>\n",
1976-
" <body>\n",
1977-
" <h1>bar</h1>\n",
1978-
" </body>\n",
1979-
" </html>\n",
1980-
"\n"
1981-
]
1982-
}
1983-
],
1984-
"source": [
1985-
"print(txt)"
1986-
]
1987-
},
19881953
{
19891954
"cell_type": "code",
19901955
"execution_count": null,
@@ -2649,7 +2614,15 @@
26492614
"execution_count": null,
26502615
"id": "73363a37",
26512616
"metadata": {},
2652-
"outputs": [],
2617+
"outputs": [
2618+
{
2619+
"name": "stdout",
2620+
"output_type": "stream",
2621+
"text": [
2622+
"b'{\"b\": \"Lorem\", \"a\": 15}'\n"
2623+
]
2624+
}
2625+
],
26532626
"source": [
26542627
"# Testing POST with Content-Type: application/json\n",
26552628
"@app.post(\"/\")\n",
@@ -2742,13 +2715,13 @@
27422715
"name": "stdout",
27432716
"output_type": "stream",
27442717
"text": [
2745-
"Set to 2025-05-17 09:47:52.421243\n"
2718+
"Set to 2025-05-19 11:46:01.972924\n"
27462719
]
27472720
},
27482721
{
27492722
"data": {
27502723
"text/plain": [
2751-
"'Session time: 2025-05-17 09:47:52.421243'"
2724+
"'Session time: 2025-05-19 11:46:01.972924'"
27522725
]
27532726
},
27542727
"execution_count": null,
@@ -3263,13 +3236,30 @@
32633236
"name": "stdout",
32643237
"output_type": "stream",
32653238
"text": [
3239+
" <!doctype html>\n",
3240+
" <html>\n",
3241+
" <head>\n",
3242+
" <title>FastHTML page</title>\n",
3243+
" <meta charset=\"utf-8\">\n",
3244+
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, viewport-fit=cover\">\n",
3245+
"<script src=\"https://cdn.jsdelivr.net/npm/htmx.org@2.0.4/dist/htmx.min.js\"></script><script src=\"https://cdn.jsdelivr.net/gh/answerdotai/fasthtml-js@1.0.12/fasthtml.js\"></script><script src=\"https://cdn.jsdelivr.net/gh/answerdotai/surreal@main/surreal.js\"></script><script src=\"https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js\"></script><script>\n",
3246+
" function sendmsg() {\n",
3247+
" window.parent.postMessage({height: document.documentElement.offsetHeight}, '*');\n",
3248+
" }\n",
3249+
" window.onload = function() {\n",
3250+
" sendmsg();\n",
3251+
" document.body.addEventListener('htmx:afterSettle', sendmsg);\n",
3252+
" document.body.addEventListener('htmx:wsAfterMessage', sendmsg);\n",
3253+
" };</script> </head>\n",
3254+
" <body></body>\n",
3255+
" </html>\n",
32663256
"\n"
32673257
]
32683258
},
32693259
{
32703260
"data": {
32713261
"text/plain": [
3272-
"'Cookie was set at time 09:47:53.179943'"
3262+
"'Cookie was set at time 11:46:35.877920'"
32733263
]
32743264
},
32753265
"execution_count": null,

nbs/api/05_svg.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"cell_type": "markdown",
9898
"metadata": {},
9999
"source": [
100-
"You can also use libraries such as [fa6-icons](https://docs.fastht.ml/fa6-icons/).\n",
100+
"You can also use libraries such as [fa6-icons](https://www.fastht.ml/docs/fa6-icons/).\n",
101101
"\n",
102102
"To create and modify SVGs using a Python API, use the FT elements in `fasthtml.svg`, discussed below.\n",
103103
"\n",

nbs/api/08_oauth.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"id": "507cd009",
2828
"metadata": {},
2929
"source": [
30-
"See the [docs page](https://docs.fastht.ml/explains/oauth.html) for an explanation of how to use this."
30+
"See the [docs page](https://www.fastht.ml/docs/explains/oauth.html) for an explanation of how to use this."
3131
]
3232
},
3333
{
@@ -430,7 +430,7 @@
430430
"id": "d978e813",
431431
"metadata": {},
432432
"source": [
433-
"After logging in via the provider, the user will be redirected back to the supplied redirect URL. The request to this URL will contain a `code` parameter, which is used to get an access token and fetch the user's profile information. See [the explanation here](https://docs.fastht.ml/explains/oauth.html) for a worked example. You can either:\n",
433+
"After logging in via the provider, the user will be redirected back to the supplied redirect URL. The request to this URL will contain a `code` parameter, which is used to get an access token and fetch the user's profile information. See [the explanation here](https://www.fastht.ml/docs/explains/oauth.html) for a worked example. You can either:\n",
434434
"\n",
435435
"- Use client.retr_info(code) to get all the profile information, or\n",
436436
"- Use client.retr_id(code) to get just the user's ID.\n",

nbs/explains/minidataapi.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"db = database('test.db')\n",
5151
"```\n",
5252
":::\n",
53+
"\n",
5354
"::: {.column width=\"79%\" style=\"padding-left: 10px;\"}\n",
5455
"FastSQL version\n",
5556
"```python\n",

nbs/index.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
"source": [
111111
"Because FastHTML is newer than most LLMs, AI systems like Cursor, ChatGPT, Claude, and Copilot won't give useful answers about it. To fix that problem, we've provided an LLM-friendly guide that teaches them how to use FastHTML. To use it, add this link for your AI helper to use:\n",
112112
"\n",
113-
"- [/llms-ctx.txt](https://docs.fastht.ml/llms-ctx.txt)\n",
113+
"- [/llms-ctx.txt](https://www.fastht.ml/docs/llms-ctx.txt)\n",
114114
"\n",
115115
"This example is in a format based on recommendations from Anthropic for use with [Claude Projects](https://support.anthropic.com/en/articles/9517075-what-are-projects). This works so well that we've actually found that Claude can provide even better information than our own documentation! For instance, read through [this annotated Claude chat](https://gist.github.com/jph00/9559b0a563f6a370029bec1d1cc97b74) for some great getting-started information, entirely generated from a project using the above text file as context.\n",
116116
"\n",
@@ -131,7 +131,7 @@
131131
"Start with the official sources to learn more about FastHTML:\n",
132132
"\n",
133133
"- [About](https://fastht.ml/about): Learn about the core ideas behind FastHTML\n",
134-
"- [Documentation](https://docs.fastht.ml): Learn from examples how to write FastHTML code\n",
134+
"- [Documentation](https://www.fastht.ml/docs): Learn from examples how to write FastHTML code\n",
135135
"- [Idiomatic app](https://github.com/AnswerDotAI/fasthtml/blob/main/examples/adv_app.py): Heavily commented source code walking through a complete application, including custom authentication, JS library connections, and database use.\n",
136136
"\n",
137137
"We also have a 1-hour intro video:\n",

0 commit comments

Comments
 (0)