diff --git a/netlify/edge-functions/index.js b/netlify/edge-functions/index.js index 07878ee..a05456a 100644 --- a/netlify/edge-functions/index.js +++ b/netlify/edge-functions/index.js @@ -1,28 +1,29 @@ -// import { Context } from "netlify:edge"; - export default async (request, context) => { - const agent = request.headers.get("user-agent"); + const useragent = request.headers.get("user-agent"); let url = new URL(request.url); let path = url.pathname; - - if (agent.indexOf("Twitterbot") != -1 || agent.indexOf("curl") != -1 || agent.indexOf("facebookexternalhit") != -1 || agent.indexOf("Slackbot-LinkExpanding") != -1 || agent.indexOf("Discordbot") != -1) { + let metadataBots = [ "Twitterbot", "curl", "facebookexternalhit", "Slackbot-LinkExpanding", "Discordbot"] + let isMetadataBot = metadataBots.some(bot => useragent.indexOf(bot) != -1); + if (isMetadataBot) { let components = path.split("/"); components.shift(); - components.pop(); let title = decodeURIComponent(components.shift()).replace("_", " "); let desc = decodeURIComponent(components.shift()).replace("_", " "); let image = decodeURIComponent(components.join("/")); - let content = ""; - if (title) content += `