Skip to content

Commit

Permalink
Merge pull request #39 from 0x7d8/main
Browse files Browse the repository at this point in the history
smart embed thingy
  • Loading branch information
prplwtf authored Jan 10, 2025
2 parents c4e2f8c + 668456b commit 8fca065
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 24 deletions.
13 changes: 1 addition & 12 deletions browse/extensions/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,7 @@

<script defer data-domain="blueprint.zip" src="https://plausible.prpl.wtf/js/script.hash.outbound-links.js"></script>

<!-- Social Embeds -->
<meta property="theme-color" content="#3b7cfe">
<meta property="og:title" content="blueprint.zip">
<meta property="og:description" content="Powerful, fast and developer-friendly extension framework for Pterodactyl. Utilize extension APIs, inject HTML, modify stylesheets, package extensions and so much more.">
<meta property="og:url" content="https://blueprint.zip">
<meta property="og:image" content="/.assets/brand/og-browse.jpg">
<meta property="og:type" content="website">
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://blueprint.zip">
<meta property="twitter:title" content="blueprint.zip">
<meta property="twitter:description" content="Powerful, fast and developer-friendly extension framework for Pterodactyl. Utilize extension APIs, inject HTML, modify stylesheets, package extensions and so much more.">
<meta property="twitter:image" content="/.assets/brand/og-browse.jpg">
<!-- META -->
</head>

<body data-bs-theme="dark">
Expand Down
13 changes: 1 addition & 12 deletions browse/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,7 @@

<script defer data-domain="blueprint.zip" src="https://plausible.prpl.wtf/js/script.hash.outbound-links.js"></script>

<!-- Social Embeds -->
<meta property="theme-color" content="#3b7cfe">
<meta property="og:title" content="blueprint.zip">
<meta property="og:description" content="Powerful, fast and developer-friendly extension framework for Pterodactyl. Utilize extension APIs, inject HTML, modify stylesheets, package extensions and so much more.">
<meta property="og:url" content="https://blueprint.zip">
<meta property="og:image" content="/.assets/brand/og-browse.jpg">
<meta property="og:type" content="website">
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://blueprint.zip">
<meta property="twitter:title" content="blueprint.zip">
<meta property="twitter:description" content="Powerful, fast and developer-friendly extension framework for Pterodactyl. Utilize extension APIs, inject HTML, modify stylesheets, package extensions and so much more.">
<meta property="twitter:image" content="/.assets/brand/og-browse.jpg">
<!-- META -->
</head>

<body data-bs-theme="dark">
Expand Down
77 changes: 77 additions & 0 deletions functions/[[any]].js
Original file line number Diff line number Diff line change
@@ -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 += `<meta name="${key}" content="${data[key]}">`
}

return html.replace('<!-- META -->', 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)
}

0 comments on commit 8fca065

Please sign in to comment.