Add CCBot to bot exceptions

This commit is contained in:
Helen Chong 2024-12-10 17:04:38 +08:00
parent c72ae31c09
commit 8e5240d1f9
1 changed files with 10 additions and 10 deletions

View File

@ -1,28 +1,28 @@
// by Robb Knight: https://rknight.me/blog/blocking-bots-with-nginx/ /*
Modified from Robb Knight's script:
https://rknight.me/blog/blocking-bots-with-nginx/
*/
import EleventyFetch from "@11ty/eleventy-fetch"; import EleventyFetch from "@11ty/eleventy-fetch";
export default async function () { export default async function () {
const url = const url = "https://raw.githubusercontent.com/ai-robots-txt/ai.robots.txt/main/robots.txt";
"https://raw.githubusercontent.com/ai-robots-txt/ai.robots.txt/main/robots.txt";
let txt = await EleventyFetch(url, { let txt = await EleventyFetch(url, {
duration: "1w", duration: "1w",
type: "text", type: "text",
}); });
const botExceptions = ["Applebot", "CCBot"];
const botExceptionsFullStr = botExceptions.map(bot => "User-agent: " + bot)
txt = txt txt = txt
.split("\n") .split("\n")
.filter((line) => line !== "User-agent: Applebot") .filter((line) => !botExceptionsFullStr.includes(line))
.join("\n"); .join("\n");
const bots = txt const bots = txt
.split("\n") .split("\n")
.filter((line) => { .filter((line) => line.startsWith("User-agent:"))
return (
line.startsWith("User-agent:") &&
line !== "User-agent: Applebot"
);
})
.map((line) => line.split(":")[1].trim().replace(/\s/gi, ".*")); .map((line) => line.split(":")[1].trim().replace(/\s/gi, ".*"));
return { return {