feat: add darkvisitors API to robots.txt

This commit is contained in:
Devin Haska 2024-04-07 12:53:28 -07:00
parent e37fa50b6b
commit adf3c3b38f
3 changed files with 40 additions and 0 deletions

33
src/_data/robots.js Normal file
View file

@ -0,0 +1,33 @@
require("dotenv").config();
const EleventyFetch = require("@11ty/eleventy-fetch");
const accessToken = process.env.DARK_VISITORS_ACCESS_TOKEN;
const fetchRobotsTxt = async () => {
const url = "https://api.darkvisitors.com/robots-txts";
const body = JSON.stringify({
agent_types: ["AI Assistant", "AI Data Scraper", "AI Search Crawler"],
disallow: "/",
});
const response = await EleventyFetch(url, {
duration: "1d",
type: "text",
fetchOptions: {
method: "POST",
headers: {
Authorization: `Bearer ${accessToken}`,
["Content-Type"]: "application/json",
},
body,
},
});
return response.toString();
};
module.exports = async function () {
const robotsTxt = await fetchRobotsTxt();
return robotsTxt;
};