diff --git a/.gitignore b/.gitignore index 5b987b5..6cfae0f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ *.log *.DS_Store package-lock.json -node_modules \ No newline at end of file +node_modules +# Local Netlify folder +.netlify diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 0000000..4b3c238 --- /dev/null +++ b/netlify.toml @@ -0,0 +1,8 @@ +[[edge_functions]] +path = "/*/*" +function = "index" + +[[redirects]] + from = "/*" + to = "/index.html" + status = 200 \ No newline at end of file diff --git a/netlify/edge-functions/index.js b/netlify/edge-functions/index.js new file mode 100644 index 0000000..f7bb9a0 --- /dev/null +++ b/netlify/edge-functions/index.js @@ -0,0 +1,49 @@ +// import { Context } from "netlify:edge"; + + +export default async (request, context) => { + const agent = 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 components = path.split("/"); + components.shift(); + components.pop(); + let title = decodeURIComponent(components.shift()).replace("_", " "); + let desc = decodeURIComponent(components.shift()).replace("_", " "); + let image = decodeURIComponent(components.join("/")); + console.log("components", title, desc, image) + + let content = ""; + if (title) content += `