-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<script lang="ts" setup> | ||
import { withBase, withoutBase } from 'ufo' | ||
import { useFetch } from '#imports' | ||
const props = defineProps<{ | ||
repo: string | ||
to?: string | ||
}>() | ||
const repo = computed(() => { | ||
// support users providing full github url | ||
return withoutBase(props.repo, 'https://github.com/') | ||
}) | ||
const link = computed(() => { | ||
return props.to || withBase(repo.value, 'https://github.com') | ||
}) | ||
// pull the stars from the server | ||
const { data: stars } = await useFetch('/api/get-github-stars', { | ||
query: { | ||
repo, | ||
}, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<NuxtLink :to="link" target="_blank" :aria-label="`Star ${repo} on GitHub`"> | ||
<slot :stars="stars"> | ||
<div>{{ stars }}</div> | ||
</slot> | ||
</NuxtLink> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { getQuery } from 'h3' | ||
import type { GitHubRepo } from '../../../types' | ||
import { cachedGitHubRepo } from '#imports' | ||
|
||
export default defineEventHandler(async (event) => { | ||
const repoWithOwner = getQuery(event).repo | ||
|
||
if (!repoWithOwner) | ||
return sendError(event, new Error('Missing repo name.')) | ||
|
||
// use ungh to fetch the statrs | ||
const repo = await cachedGitHubRepo(repoWithOwner).catch({ stars: 0 }) as GitHubRepo | ||
return repo.stars | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { cachedFunction } from '#imports' | ||
|
||
export const cachedGitHubRepo = cachedFunction(async (repo: string) => { | ||
return (await $fetch(`https://ungh.cc/repos/${repo}`)).repo | ||
}, { | ||
maxAge: 60 * 60, | ||
name: 'github-repo', | ||
getKey: (repo: string) => repo, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export interface GitHubRepo { | ||
id: number | ||
name: string | ||
repo: string | ||
description: string | ||
createdAt: string | ||
updatedAt: string | ||
pushedAt: string | ||
stars: number | ||
watchers: number | ||
forks: number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './twitter' | ||
export * from './metatags' | ||
export * from './github' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<template> | ||
<LegoGithubStar v-slot="{ stars }" repo="zernonia/nuxt-lego" class="group border bg-white hover:bg-gray-100 transition rounded-lg text-xl flex justify-center"> | ||
<div class="flex items-center bg-gray-100 group-hover:bg-gray-200 transition rounded-l px-4 py-3 space-x-1"> | ||
<Icon name="uil:star" class="text-xl group-hover:op75 " /> | ||
<div>Star</div> | ||
</div> | ||
<div class="px-4 py-3"> | ||
{{ stars }} | ||
</div> | ||
</LegoGithubStar> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<template> | ||
<ShowcaseCard slug="github-star"> | ||
<template #image> | ||
<div class="text-blue-300 group-hover:text-[1.25rem] group-hover:text-blue-500 transition-all "> | ||
<LegoGithubStar v-slot="{ stars }" repo="zernonia/nuxt-lego" class="flex items-center space-x-1 px-3 py-2 border bg-white hover:bg-gray-50 transition rounded-lg flex justify-center"> | ||
<Icon name="mdi:star" class="op75 " /> | ||
{{ stars }} | ||
</LegoGithubStar> | ||
</div> | ||
</template> | ||
</ShowcaseCard> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,6 @@ | |
<MarqueeBannerShowcase /> | ||
<PreviewShowcase /> | ||
<TocShowcase /> | ||
<GithubStarShowcase /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
title: GitHub Star | ||
description: Share your GitHub projects with ease. | ||
new: true | ||
--- | ||
|
||
::code-example | ||
#preview | ||
:github-star-demo | ||
#code | ||
codegen{src="website/components/GithubStar/Demo.vue" lang="vue" fileName="/content/ProseImg.vue"} | ||
:: | ||
|
||
## Anatomy | ||
|
||
```vue | ||
<template> | ||
<LegoGithubStar> | ||
<slot /> | ||
</LegoGithubStar> | ||
</template> | ||
``` | ||
|
||
## API Reference | ||
|
||
### Root | ||
|
||
| Prop | Default | Types | Description | | ||
|------| ------- |----------|------------------------------------------------------------------------| | ||
| repo | `` | `string` | The name of the repository to check. For example: `zernonia/nuxt-lego` | | ||
| to | `` | `string` | Set a different button link. | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters