diff --git a/netlify.toml b/netlify.toml index 473dad1..292421d 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,3 +1,9 @@ +[functions] + external_node_modules = [ + "sharp" + ] + directory = "functions/" + [[edge_functions]] path = "/*" function = "metadata" diff --git a/netlify/edge-functions/metadata.js b/netlify/edge-functions/metadata.js index 402d14c..9d8edf4 100644 --- a/netlify/edge-functions/metadata.js +++ b/netlify/edge-functions/metadata.js @@ -3,6 +3,14 @@ function decodePrettyComponent(s) { return decodeURIComponent(s.replace(/-+/g, e => replacements[e] ?? '-')) } +function decodeURL(s) { + if (s.startsWith("http")) return s; + return atob(s.replace(/=/g,'')); +} + +function atou(b64) { return decodeURIComponent(escape(atob(b64))); } +function utoa(data) { return btoa(unescape(encodeURIComponent(data))); } + function pathToMetadata(path) { let components = path.substring(1).split("/"); let info = {title: decodePrettyComponent(components.shift())} @@ -17,6 +25,10 @@ function pathToMetadata(path) { return info; } +function mProp(prop, content) { return `` } +function mName(name, content) { return `` } + +// Valid URL Chars A-Za-z0-9-._~:?@!$&()*;=+/ export default async (request, context) => { try { const ua = request.headers.get("user-agent"); @@ -26,14 +38,9 @@ export default async (request, context) => { let uaArray = Deno.env.get("UA_ARRAY")?.split(",") || []; let uaMatch = uaArray.some(a => ua.indexOf(a) != -1); - - if (uaMatch) { - //console.log("Redirecting legacy client", ) - return new Response('', { status: 401 }); - } + if (uaMatch) { return new Response('', { status: 401 }); } if (path != "/" ) { - // context.log(path, request.headers, geo); let metadataBots = [ "Twitterbot", "curl", "facebookexternalhit", "Slackbot-LinkExpanding", "Discordbot", "snapchat"] let isMetadataBot = metadataBots.some(bot => ua.indexOf(bot) != -1); @@ -41,37 +48,37 @@ export default async (request, context) => { let info = pathToMetadata(path) let content = ['']; - if (info.title) { content.push(`