Skip to content

Commit dc9ba7a

Browse files
authored
Update llms-txt-validation.js
1 parent cfd4af3 commit dc9ba7a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

dist/llms-txt-validation.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
//[llms-txt-valid]
2-
return fetch('/llms.txt')
2+
3+
const fetchWithTimeout = (url) => {
4+
var controller = new AbortController();
5+
setTimeout(() => {controller.abort()}, 5000);
6+
return fetch(url, {signal: controller.signal});
7+
}
8+
9+
return fetchWithTimeout('/llms.txt')
310
.then(response => {
4-
if (!response.ok) return JSON.stringify({valid:0, error: "Non OK status code"});
11+
if (!response.ok) return JSON.stringify({valid:0, message:response.status, error: "Non OK status code"});
512
const ct = response.headers.get('Content-Type')||'';
613
if (!ct.toLowerCase().includes('text/plain')) return JSON.stringify({valid:0,error: "Invalid content type"});
714
return response.text().then(text => {
815
const m = s=> (text.match(new RegExp(`\\${s}`,'g'))||[]).length;
9-
if ((text.match(/```/g)||[]).length %2) return JSON.stringify({valid:0,error:""});
10-
if (m('[')!==m(']')||m('(')!==m(')')) return JSON.stringify({valid:0,error:""});
16+
if ((text.match(/```/g)||[]).length %2) return JSON.stringify({valid:0, error:"Invalid markdown fences"});
17+
if (m('[')!==m(']')||m('(')!==m(')')) return JSON.stringify({valid:0, error:"Unmatch braces"});
1118
return JSON.stringify({valid:1});
1219
});
1320
})
1421
.catch(error => {
15-
return JSON.stringify({valid:0,message: error.message, error: error});
22+
return JSON.stringify({valid:0, message: error.message, error: error});
1623
});

0 commit comments

Comments
 (0)