@forge42/seo-tools
Version:
Framework agnostic set of helpers designed to help you create, maintain and develop your SEO
1 lines • 2.06 kB
Source Map (JSON)
{"version":3,"sources":["../src/robots.ts"],"sourcesContent":["export interface RobotsEntry {\r\n\t/**\r\n\t * Array of paths to allow crawling\r\n\t */\r\n\tallow?: string[]\r\n\t/**\r\n\t * Array of paths to disallow crawling\r\n\t */\r\n\tdisallow?: string[]\r\n\t/**\r\n\t * Sitemap to use for the policy\r\n\t */\r\n\tsitemap?: string[]\r\n\t/**\r\n\t * User agent to apply the policy to\r\n\t */\r\n\tuserAgent: string\r\n\t/**\r\n\t * Crawl delay for the user agent\r\n\t */\r\n\tcrawlDelay?: number\r\n}\r\n\r\n/**\r\n * Helper method used to generate a robots.txt from all the provided policies.\r\n *\r\n * @param policies - Array of policies to generate from\r\n * @returns Robots.txt as a string\r\n */\r\nexport function generateRobotsTxt(policies: RobotsEntry[] = []) {\r\n\tconst robotsTxt = policies\r\n\t\t.map((policy) => {\r\n\t\t\tconst policyText = Object.entries(policy)\r\n\t\t\t\t.map(([key, value]) => {\r\n\t\t\t\t\tif (key === \"userAgent\") {\r\n\t\t\t\t\t\treturn `User-agent: ${value}`\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (key === \"crawlDelay\") {\r\n\t\t\t\t\t\treturn `Crawl-delay: ${value}`\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (key === \"allow\") {\r\n\t\t\t\t\t\treturn value.map((path: string) => `Allow: ${path}`).join(\"\\n\")\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (key === \"disallow\") {\r\n\t\t\t\t\t\treturn value.map((path: string) => `Disallow: ${path}`).join(\"\\n\")\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn `Sitemap: ${value}`\r\n\t\t\t\t})\r\n\t\t\t\t.join(\"\\n\")\r\n\t\t\treturn policyText\r\n\t\t})\r\n\t\t.join(\"\\n\")\r\n\r\n\treturn robotsTxt\r\n}\r\n"],"mappings":"AA6BO,SAASA,EAAkBC,EAA0B,CAAC,EAAG,CAwB/D,OAvBkBA,EAChB,IAAKC,GACc,OAAO,QAAQA,CAAM,EACtC,IAAI,CAAC,CAACC,EAAKC,CAAK,IACZD,IAAQ,YACJ,eAAeC,CAAK,GAExBD,IAAQ,aACJ,gBAAgBC,CAAK,GAEzBD,IAAQ,QACJC,EAAM,IAAKC,GAAiB,UAAUA,CAAI,EAAE,EAAE,KAAK;AAAA,CAAI,EAE3DF,IAAQ,WACJC,EAAM,IAAKC,GAAiB,aAAaA,CAAI,EAAE,EAAE,KAAK;AAAA,CAAI,EAE3D,YAAYD,CAAK,EACxB,EACA,KAAK;AAAA,CAAI,CAEX,EACA,KAAK;AAAA,CAAI,CAGZ","names":["generateRobotsTxt","policies","policy","key","value","path"]}