Skip to content

Commit fdda980

Browse files
committed
some changes
1 parent fc9f31d commit fdda980

5 files changed

Lines changed: 69 additions & 10 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![pkg.pr.new](https://6de7d3b2.stackblitz-cr.pages.dev/badge?owner=stackblitz-labs&repo=pkg.pr.new)](https://pkg.pr.new/view/stackblitz-labs/pkg.pr.new)
1+
[![pkg.pr.new](https://pkg.pr.new/badge/stackblitz-labs/pkg.pr.new)](https://pkg.pr.new/~/stackblitz-labs/pkg.pr.new)
22

33
<p align="center"><img src="https://github.com/user-attachments/assets/314d5112-f67f-4758-82bf-7b0c19c01ba6" /></p>
44

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<script setup lang="ts">
2+
const props = defineProps<{
3+
owner: string;
4+
repo: string;
5+
}>();
6+
7+
const copied = ref(false);
8+
9+
const baseUrl = process.client ? window.location.origin : "https://pkg.pr.new";
10+
const badgeUrl = `${baseUrl}/badge/${props.owner}/${props.repo}`;
11+
const redirectUrl = `${baseUrl}/~/${props.owner}/${props.repo}`;
12+
13+
function copyBadgeCode() {
14+
const badgeCode = `[![${props.repo}](${badgeUrl})](${redirectUrl})`;
15+
navigator.clipboard.writeText(badgeCode);
16+
copied.value = true;
17+
setTimeout(() => {
18+
copied.value = false;
19+
}, 2000);
20+
}
21+
</script>
22+
23+
<template>
24+
<div class="flex flex-col gap-3 p-4 bg-gray-50 dark:bg-gray-800 rounded-lg">
25+
<h3 class="font-semibold">Add a badge to your README</h3>
26+
27+
<div class="flex items-center gap-2">
28+
<img :src="badgeUrl" :alt="`${repo} badge`" height="20" class="h-5" />
29+
<UButton
30+
@click="copyBadgeCode"
31+
size="sm"
32+
color="primary"
33+
:icon="copied ? 'i-ph-check-bold' : 'i-ph-copy'"
34+
>
35+
{{ copied ? "Copied!" : "Copy Markdown" }}
36+
</UButton>
37+
</div>
38+
39+
<div class="text-xs text-gray-500">
40+
Add this badge to your README to help promote pkg.pr.new
41+
</div>
42+
</div>
43+
</template>

packages/app/app/components/GettingStarted.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@
5555
<GettingStartedStep step="4">
5656
<div>Promote pkg.pr.new by adding a badge to your repository README:</div>
5757

58-
<CodeSnippet
59-
code="[![pkg.pr.new](https://pkg.pr.new/badge?owner=OWNER&repo=REPO)](https://pkg.pr.new/view/OWNER/REPO)"
60-
/>
58+
<div class="w-[550px]">
59+
<CodeSnippet
60+
class="text-[10px]"
61+
code="[![pkg.pr.new](https://pkg.pr.new/badge/OWNER/REPO)](https://pkg.pr.new/~/OWNER/REPO)"
62+
/>
63+
</div>
6164

6265
<div class="text-gray-500 text-sm">
6366
Replace OWNER and REPO with your GitHub username/organization and

packages/app/app/pages/~/[owner]/[repo].vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script setup lang="ts">
2+
import { computed } from "vue";
3+
24
definePageMeta({
35
name: "repo:details",
46
});
@@ -78,6 +80,10 @@ useSeoMeta({
7880
</div>
7981
</div>
8082

83+
<div class="max-w-xl mx-auto w-full">
84+
<BadgeGenerator :owner="repository.owner.login" :repo="repository.name" />
85+
</div>
86+
8187
<Commits :owner="repository.owner.login" :repo="repository.name" />
8288
</div>
8389
</template>

packages/app/server/routes/badge.get.ts renamed to packages/app/server/routes/badge/[owner]/[repo].get.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
import { defineEventHandler, setHeader, getQuery, createError } from "h3";
1+
import {
2+
defineEventHandler,
3+
setHeader,
4+
getRouterParams,
5+
createError,
6+
getQuery,
7+
} from "h3";
28

39
const BASE_URL = "https://pkg.pr.new";
410

511
export default defineEventHandler(async (event) => {
12+
const params = getRouterParams(event);
13+
const owner = params.owner as string;
14+
const repo = params.repo as string;
15+
616
const query = getQuery(event);
7-
const owner = query.owner as string;
8-
const repo = query.repo as string;
917
const style = (query.style as string) || "flat";
10-
const label = (query.label as string) || "pkg.pr.new";
1118
const color = (query.color as string) || "0ea5e9";
1219

1320
if (!owner || !repo) {
@@ -18,10 +25,10 @@ export default defineEventHandler(async (event) => {
1825
}
1926

2027
const logoBase64 = getPkgPrNewLogoBase64();
21-
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}`;
28+
const shieldsUrl = `https://img.shields.io/static/v1?label=&message=${encodeURIComponent(repo)}&color=${color}&style=${style}&logo=data:image/svg+xml;base64,${logoBase64}`;
2229

2330
setHeader(event, "Content-Type", "image/svg+xml");
24-
setHeader(event, "Cache-Control", "public, max-age=86400");
31+
setHeader(event, "Cache-Control", "public, max-age=86400"); // Cache for 24 hours
2532

2633
const response = await fetch(shieldsUrl);
2734
const svg = await response.text();

0 commit comments

Comments
 (0)