@forge42/seo-tools
Version:
Framework agnostic set of helpers designed to help you create, maintain and develop your SEO
1 lines • 1.95 kB
Source Map (JSON)
{"version":3,"sources":["../src/robots.ts"],"sourcesContent":["export interface RobotsEntry {\n\t/**\n\t * Array of paths to allow crawling\n\t */\n\tallow?: string[]\n\t/**\n\t * Array of paths to disallow crawling\n\t */\n\tdisallow?: string[]\n\t/**\n\t * Sitemap to use for the policy\n\t */\n\tsitemap?: string[]\n\t/**\n\t * User agent to apply the policy to\n\t */\n\tuserAgent: string\n\t/**\n\t * Crawl delay for the user agent\n\t */\n\tcrawlDelay?: number\n}\n\n/**\n * Helper method used to generate a robots.txt from all the provided policies.\n *\n * @param policies - Array of policies to generate from\n * @returns Robots.txt as a string\n */\nexport function generateRobotsTxt(policies: RobotsEntry[] = []) {\n\tconst robotsTxt = policies\n\t\t.map((policy) => {\n\t\t\tconst policyText = Object.entries(policy)\n\t\t\t\t.map(([key, value]) => {\n\t\t\t\t\tif (key === \"userAgent\") {\n\t\t\t\t\t\treturn `User-agent: ${value}`\n\t\t\t\t\t}\n\t\t\t\t\tif (key === \"crawlDelay\") {\n\t\t\t\t\t\treturn `Crawl-delay: ${value}`\n\t\t\t\t\t}\n\t\t\t\t\tif (key === \"allow\") {\n\t\t\t\t\t\treturn value.map((path: string) => `Allow: ${path}`).join(\"\\n\")\n\t\t\t\t\t}\n\t\t\t\t\tif (key === \"disallow\") {\n\t\t\t\t\t\treturn value.map((path: string) => `Disallow: ${path}`).join(\"\\n\")\n\t\t\t\t\t}\n\t\t\t\t\treturn `Sitemap: ${value}`\n\t\t\t\t})\n\t\t\t\t.join(\"\\n\")\n\t\t\treturn policyText\n\t\t})\n\t\t.join(\"\\n\")\n\n\treturn robotsTxt\n}\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"]}