Skip to content

Commit 0e8e0cb

Browse files
committed
Ignore anchor tags / hash fragment (ex. #examples) in llms.txt URLs
1 parent 2e53837 commit 0e8e0cb

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

docs/src/lib/components/OpenWithButton.svelte

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@
2525
url: 'https://layerchart.com/docs',
2626
description: 'A charting/visualization library for Svelte 5'
2727
};
28-
const pageName = page.url.href.split('/').pop();
29-
const llmBaseContext = `The following is a documentation page from ${pkg.name} (${pkg.description}). The page URL for "${pageName}" is ${page.url.href}. Be ready to help answer questions about this page.`;
28+
// Use origin + pathname to exclude hash/anchor from URLs
29+
const pageUrl = $derived(`${page.url.origin}${page.url.pathname}`);
30+
const pageName = $derived(page.url.pathname.split('/').pop());
31+
const llmBaseContext = $derived(
32+
`The following is a documentation page from ${pkg.name} (${pkg.description}). The page URL for "${pageName}" is ${pageUrl}. Be ready to help answer questions about this page.`
33+
);
3034
3135
const llms = $derived([
3236
// Add source button if component page
@@ -46,7 +50,7 @@
4650
label: 'View Page Markdown',
4751
icon: SimpleIconsMarkdown,
4852
fn: async () => {
49-
markdownContent = await fetch(`${page.url.href}/llms.txt`).then((res) => res.text());
53+
markdownContent = await fetch(`${pageUrl}/llms.txt`).then((res) => res.text());
5054
openMarkdownModal = true;
5155
}
5256
},
@@ -85,7 +89,7 @@
8589
size="sm"
8690
color="primary"
8791
onclick={async () => {
88-
const md = await fetch(`${page.url.href}/llms.txt`).then((res) => res.text());
92+
const md = await fetch(`${pageUrl}/llms.txt`).then((res) => res.text());
8993
copy(md);
9094
}}
9195
>
@@ -170,14 +174,14 @@
170174
<div class="grid grid-cols-[1fr_auto] gap-3 items-center p-4">
171175
<div class="overflow-auto">
172176
<div class="text-lg font-semibold">Page Markdown</div>
173-
<div class="text-xs text-surface-content/50 truncate">{page.url.href}/llms.txt</div>
177+
<div class="text-xs text-surface-content/50 truncate">{pageUrl}/llms.txt</div>
174178
</div>
175179

176180
<Button
177181
icon={SimpleIconsMarkdown}
178182
variant="fill-light"
179183
color="primary"
180-
href="{page.url.href}/llms.txt"
184+
href="{pageUrl}/llms.txt"
181185
target="_blank"
182186
>
183187
Open Raw

0 commit comments

Comments
 (0)