From 668456be13293569818302a69031d788903ff924 Mon Sep 17 00:00:00 2001 From: Robert Jansen Date: Fri, 10 Jan 2025 14:05:40 +0000 Subject: [PATCH] smart embed thingy --- browse/extensions/index.html | 13 +----- browse/index.html | 13 +----- functions/[[any]].js | 77 ++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 24 deletions(-) create mode 100644 functions/[[any]].js diff --git a/browse/extensions/index.html b/browse/extensions/index.html index 2f0aae2..dd728c9 100644 --- a/browse/extensions/index.html +++ b/browse/extensions/index.html @@ -12,18 +12,7 @@ - - - - - - - - - - - - + diff --git a/browse/index.html b/browse/index.html index b120388..0cd6d1f 100644 --- a/browse/index.html +++ b/browse/index.html @@ -12,18 +12,7 @@ - - - - - - - - - - - - + diff --git a/functions/[[any]].js b/functions/[[any]].js new file mode 100644 index 0000000..a077989 --- /dev/null +++ b/functions/[[any]].js @@ -0,0 +1,77 @@ +import BrowseHtml from "../browse/index.html" +import ExtensionHtml from "../browse/extensions/index.html" + +function insertMetadata(data, html) { + let meta = '' + + for (const key in data) { + meta += `` + } + + return html.replace('', meta) +} + +export const onRequest = async(context) => { + const url = new URL(context.request.url) + + const meta = { + 'theme-color': '#4642f5', + 'description': 'Powerful, fast and developer-friendly extension framework for Pterodactyl. Utilize extension APIs, inject HTML, modify stylesheets, package extensions and so much more.', + 'og:description': 'Powerful, fast and developer-friendly extension framework for Pterodactyl. Utilize extension APIs, inject HTML, modify stylesheets, package extensions and so much more.', + 'og:title': 'blueprint.zip', + 'og:image': '/.assets/brand/og.jpg', + 'og:url': context.request.url, + 'og:type': 'website', + 'twitter:card': 'summary_large_image', + 'twitter:url': context.request.url, + 'twitter:title': 'blueprint.zip', + 'twitter:description': 'Powerful, fast and developer-friendly extension framework for Pterodactyl. Utilize extension APIs, inject HTML, modify stylesheets, package extensions and so much more.', + 'twitter:image': '/.assets/brand/og.jpg', + } + + if (url.pathname.startsWith('/browse')) { + if (url.hash.startsWith('#')) { + const data = await fetch(`https://api.blueprintframe.work/api/extensions/${url.hash.slice(1)}`).then((res) => res.json()).catch(() => null) + if (!data) return Response.redirect('/browse', 301) + + return new Response(insertMetadata({ + ...meta, + 'og:title': `blueprint.zip | ${data.name}`, + 'description': `${meta.description}\n\n${data.summary}`, + 'og:description': `${meta['og:description']}\n\n${data.summary}`, + 'og:image': data.banner, + 'twitter:title': `blueprint.zip | ${data.name}`, + 'twitter:description': `${meta['twitter:description']}\n\n${data.summary}`, + 'twitter:image': data.banner + }, ExtensionHtml), { + headers: { + 'Content-Type': 'text/html' + } + }) + } + + const data = await fetch('https://api.blueprintframe.work/api/extensions').then((res) => res.json()).catch(() => null) + if (data) { + return new Response(insertMetadata({ + ...meta, + 'og:title': 'blueprint.zip | Browse Extensions', + 'description': `${meta.description}\n\nBrowse ${data.length} extensions for blueprint.zip.`, + 'og:description': `${meta['og:description']}\n\nBrowse ${data.length} extensions for blueprint.zip.`, + 'twitter:title': 'blueprint.zip | Browse Extensions', + 'twitter:description': `${meta['twitter:description']}\n\nBrowse ${data.length} extensions for blueprint.zip.` + }, BrowseHtml), { + headers: { + 'Content-Type': 'text/html' + } + }) + } + + return new Response(insertMetadata(meta, BrowseHtml), { + headers: { + 'Content-Type': 'text/html' + } + }) + } + + return context.env.ASSETS.fetch(url) +} \ No newline at end of file