Skip to content

Commit d9f8045

Browse files
authored
llms.txt: fix issue with custom layout (#14127)
1 parent 5749d48 commit d9f8045

3 files changed

Lines changed: 54 additions & 1 deletion

File tree

src/project/types/website/website-llms.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,12 @@ function extractMainContent(doc: Document): string {
147147
}
148148

149149
// Get the main content area
150+
// Note: use querySelector("body") instead of clone.body because
151+
// deno-dom's cloneNode() doesn't preserve the .body convenience getter
150152
const main = clone.querySelector("main") ||
151153
clone.querySelector("#quarto-document-content") ||
152154
clone.querySelector("article") ||
153-
clone.body;
155+
clone.querySelector("body");
154156

155157
if (!main) {
156158
return "";

tests/docs/smoke-all/website/llms-txt/_quarto.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ website:
1111
- href: index.qmd
1212
text: Home
1313
- about.qmd
14+
- custom-layout.qmd
1415
sidebar:
1516
contents:
1617
- section: Info
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
pagetitle: "Custom Layout Page"
3+
page-layout: custom
4+
section-divs: false
5+
toc: false
6+
_quarto:
7+
tests:
8+
html:
9+
ensureLlmsMdExists: true
10+
ensureLlmsMdRegexMatches:
11+
- ["Welcome to the Custom Page", "Feature One", "Feature Two", "Learn more"]
12+
- []
13+
---
14+
15+
::: {.hero-banner}
16+
::: {.content-block}
17+
18+
# Welcome to the Custom Page
19+
20+
### A page using custom layout
21+
22+
- This tests that llms-txt works with page-layout: custom.
23+
- Custom layout pages lack a `<main>` element in the rendered HTML.
24+
25+
:::
26+
:::
27+
28+
::: {.content-block}
29+
::: {.features}
30+
31+
::: {.feature}
32+
### Feature One
33+
Description of the first feature.
34+
35+
::: {.learn-more}
36+
[Learn more »](about.qmd)
37+
:::
38+
:::
39+
40+
::: {.feature}
41+
### Feature Two
42+
Description of the second feature.
43+
44+
::: {.learn-more}
45+
[Learn more »](about.qmd)
46+
:::
47+
:::
48+
49+
:::
50+
:::

0 commit comments

Comments
 (0)