diff --git a/worker/src/index.ts b/worker/src/index.ts index 6656fc1..d0edbf0 100644 --- a/worker/src/index.ts +++ b/worker/src/index.ts @@ -1,5 +1,6 @@ import { getAllChannels, getAllOverrides } from './db' import { renderBrowsePage } from './pages/browse' +import { renderDetailPage } from './pages/detail' import { buildPublicIndex } from './publicIndex' import type { Env } from './env' import type { BaseIndex } from './publicIndex' @@ -42,6 +43,27 @@ export default { }) } + const detailMatch = url.pathname.match(/^\/plugins\/([\w.-]+)$/) + if (detailMatch) { + const id = detailMatch[1] + const baseRes = await env.ASSETS.fetch( + new URL('/index.json', request.url), + ) + const base = await baseRes.json() + const [overrides, channels] = await Promise.all([ + getAllOverrides(env), + getAllChannels(env), + ]) + const merged = buildPublicIndex(base, overrides, channels) + + const plugin = merged.plugins[id] + if (!plugin) return new Response('Not found', { status: 404 }) + + return new Response(renderDetailPage(plugin, overrides[id] ?? null), { + headers: { 'content-type': 'text/html; charset=utf-8' }, + }) + } + return env.ASSETS.fetch(request) }, } diff --git a/worker/src/pages/detail.ts b/worker/src/pages/detail.ts new file mode 100644 index 0000000..89f6f9b --- /dev/null +++ b/worker/src/pages/detail.ts @@ -0,0 +1,41 @@ +import { escapeHtml, htmlShell } from '../theme' +import type { Override } from '../db' +import type { IndexPlugin } from '../publicIndex' + +export function renderDetailPage( + plugin: IndexPlugin, + override: Override | null, +): string { + const description = override?.description ?? plugin.description + const tagline = override?.tagline ?? description + const version = plugin.channels.latest ?? Object.keys(plugin.versions)[0] + + const featuresHtml = override?.features?.length + ? `` + : '' + + const body = ` +
+
+ N +
${escapeHtml(plugin.name)}
+
+ +
+
+
${escapeHtml(plugin.name)}
+
${escapeHtml(tagline)}
+

${escapeHtml(description)}

+ ${featuresHtml} +
${escapeHtml(plugin.author)} · v${escapeHtml(version ?? '?')}
+ Add repository in Revenge Next +
` + + return htmlShell({ + title: `${plugin.name} - Revenge Next`, + description: tagline, + ogTitle: plugin.name, + ogDescription: tagline, + body, + }) +}