Skip to content

Commit 8461f5c

Browse files
authored
Create llms-txt-validation.js
Fetches /llms.txt and returns a simple validity flag (1 or 0). It checks that the response: - Succeeds (HTTP 2xx) - Has a Content-Type of text/plain - Contains balanced Markdown code fences (…) - Has matching counts of [ vs. ] and ( vs. ) If any check fails, it returns 0; otherwise it returns 1.
1 parent ce799a4 commit 8461f5c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

llms-txt-validation.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[llms-txt-valid]
2+
return fetch('/llms.txt')
3+
.then(response => {
4+
if (!response.ok) return 0;
5+
const ct = response.headers.get('Content-Type')||'';
6+
if (!ct.toLowerCase().includes('text/plain')) return 0;
7+
return response.text().then(text => {
8+
const m = s=> (text.match(new RegExp(`\\${s}`,'g'))||[]).length;
9+
if ((text.match(/```/g)||[]).length %2) return 0;
10+
if (m('[')!==m(']')||m('(')!==m(')')) return 0;
11+
return 1;
12+
});
13+
})
14+
.catch(()=>0);

0 commit comments

Comments
 (0)