Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ See <https://llmstxt.org> for the convention.

### 2. Point at it

In your page's `<head>` (a `<link>` in the body is ignored, so page content can't redirect the
reader):

```html
<link rel="llms" href="/llms.txt" />
```
Expand Down
4 changes: 3 additions & 1 deletion src/human-machine-swapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
}

function linkedHref() {
const link = document.querySelector('link[rel="llms"]');
// <head> only: the reader fetches this URL with same-origin cookies, so markup that page
// content can inject (a <link> in the body) must not be able to choose it.
const link = document.head && document.head.querySelector('link[rel="llms"]');
return link ? link.getAttribute("href") : null;
}

Expand Down
6 changes: 6 additions & 0 deletions test/component.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,9 @@ test("it sends cookies to its own origin, so the reader works behind a login", (
assert.equal((SOURCE.match(/credentials:\s*"same-origin"/g) || []).length, 2);
});

test("the discovery link is read from <head> only", () => {
// The reader fetches that URL with same-origin cookies; body markup must not choose it.
assert.ok(/document\.head\.querySelector\('link\[rel="llms"\]'\)/.test(SOURCE));
assert.ok(!/document\.querySelector\('link\[rel="llms"\]'\)/.test(SOURCE));
});

Loading