MCPcopy
hub / github.com/lissy93/web-check / parseRobotsTxt

Function parseRobotsTxt

api/robots-txt.js:7–15  ·  view source on GitHub ↗
(content)

Source from the content-addressed store, hash-verified

5
6// Extract User-agent / Allow / Disallow rules from a robots.txt body
7const parseRobotsTxt = (content) => {
8 const rules = [];
9 for (let line of content.split('\n')) {
10 line = line.trim();
11 const ruleMatch = line.match(/^(Allow|Disallow|User-agent):\s*(\S*)$/i);
12 if (ruleMatch) rules.push({ lbl: ruleMatch[1], val: ruleMatch[2] });
13 }
14 return { robots: rules };
15};
16
17const robotsHandler = async (url) => {
18 const { protocol, hostname } = parseTarget(url);

Callers 1

robotsHandlerFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected