From 155fc6332532d225767b83f1197d9a83071b6366 Mon Sep 17 00:00:00 2001 From: AmirSa12 Date: Sat, 10 May 2025 22:55:36 +0330 Subject: [PATCH 01/20] add badge route --- README.md | 3 ++ .../app/app/components/GettingStarted.vue | 23 ++++++++++ packages/app/server/routes/badge.get.ts | 42 +++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 packages/app/server/routes/badge.get.ts diff --git a/README.md b/README.md index c5fb25e8..c394d2ff 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +[![pkg.pr.new](https://pkg.pr.new/badge?owner=stackblitz-labs&repo=pkg.pr.new)](https://pkg.pr.new/view/stackblitz-labs/pkg.pr.new) + +

# pkg.pr.new diff --git a/packages/app/app/components/GettingStarted.vue b/packages/app/app/components/GettingStarted.vue index 61dbbed5..f1c4a060 100644 --- a/packages/app/app/components/GettingStarted.vue +++ b/packages/app/app/components/GettingStarted.vue @@ -51,5 +51,28 @@ PR Screenshot + + +
+ Promote pkg.pr.new by adding a badge to your repository README: +
+ + + +
+ Replace OWNER and REPO with your GitHub username/organization and repository name. +
+ + +
diff --git a/packages/app/server/routes/badge.get.ts b/packages/app/server/routes/badge.get.ts new file mode 100644 index 00000000..f4a16b94 --- /dev/null +++ b/packages/app/server/routes/badge.get.ts @@ -0,0 +1,42 @@ +import { defineEventHandler, setHeader, getQuery, createError } from 'h3' + +const BASE_URL = 'https://pkg.pr.new' + +export default defineEventHandler(async (event) => { + const query = getQuery(event) + const owner = query.owner as string + const repo = query.repo as string + const style = (query.style as string) || 'flat' + const label = (query.label as string) || 'pkg.pr.new' + const color = (query.color as string) || '0ea5e9' + + if (!owner || !repo) { + throw createError({ + statusCode: 400, + statusMessage: 'Owner and repo parameters are required', + }) + } + + const logoBase64 = getPkgPrNewLogoBase64() + const shieldsUrl = `https://img.shields.io/static/v1?label=${encodeURIComponent(label)}&message=${encodeURIComponent(repo)}&color=${color}&style=${style}&logo=data:image/svg+xml;base64,${logoBase64}` + + setHeader(event, 'Content-Type', 'image/svg+xml') + setHeader(event, 'Cache-Control', 'public, max-age=86400') + + const response = await fetch(shieldsUrl) + const svg = await response.text() + + return ` + + ${svg} + + ` +}) + +function getPkgPrNewLogoBase64(): string { + const logo = ` + + ` + + return Buffer.from(logo).toString('base64') +} \ No newline at end of file From f763510e3696bd33d0c195e2d1b118bcbac7c0ca Mon Sep 17 00:00:00 2001 From: AmirSa12 Date: Sat, 10 May 2025 22:55:56 +0330 Subject: [PATCH 02/20] prettier --- README.md | 1 - .../app/app/components/GettingStarted.vue | 11 ++-- packages/app/server/routes/badge.get.ts | 64 +++++++++---------- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index c394d2ff..08ee1591 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ [![pkg.pr.new](https://pkg.pr.new/badge?owner=stackblitz-labs&repo=pkg.pr.new)](https://pkg.pr.new/view/stackblitz-labs/pkg.pr.new) -

# pkg.pr.new diff --git a/packages/app/app/components/GettingStarted.vue b/packages/app/app/components/GettingStarted.vue index f1c4a060..76c02147 100644 --- a/packages/app/app/components/GettingStarted.vue +++ b/packages/app/app/components/GettingStarted.vue @@ -53,14 +53,15 @@ -
- Promote pkg.pr.new by adding a badge to your repository README: -
+
Promote pkg.pr.new by adding a badge to your repository README:
- +
- Replace OWNER and REPO with your GitHub username/organization and repository name. + Replace OWNER and REPO with your GitHub username/organization and + repository name.