-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
b31d4cd
commit 7e199f8
Showing
9 changed files
with
155 additions
and
15 deletions.
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 @@ | ||
NUXT_GITHUB_TOKEN= |
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
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 |
---|---|---|
@@ -1,14 +1,17 @@ | ||
export default defineNuxtConfig({ | ||
alias: { | ||
heroicons: '@heroicons/vue/24/solid' | ||
heroicons: '@heroicons/vue/24/outline', | ||
}, | ||
devtools: { enabled: true }, | ||
css: ['~/assets/css/main.css'], | ||
modules: ['@nuxt/eslint'], | ||
postcss: { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {} | ||
} | ||
} | ||
autoprefixer: {}, | ||
}, | ||
}, | ||
runtimeConfig: { | ||
githubToken: '', | ||
}, | ||
}); |
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,5 +1,65 @@ | ||
<script setup lang="ts"> | ||
import { StarIcon } from 'heroicons'; | ||
const { data: repositories } = await useFetch('/api/repositories'); | ||
const durationFormatter = new Intl.RelativeTimeFormat('en', { style: 'long' }); | ||
function formatDuration(age: number) { | ||
const years = Math.floor(age / 12 / 30 / 24 / 60 / 60 / 1000); | ||
const formatted = durationFormatter.format(years, 'year'); | ||
return `${formatted.replace('in ', '')} old`; | ||
} | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<h1 class="text-slate-500">Welcome to the homepage</h1> | ||
</div> | ||
<section class="table"> | ||
<div class="table-header-group"> | ||
<div class="table-row text-slate-400 *:table-cell *:px-4 *:py-6"> | ||
<div>Rank</div> | ||
<div>Name</div> | ||
<div>Stars</div> | ||
<div>Description</div> | ||
<div>Language</div> | ||
<div>Age</div> | ||
</div> | ||
</div> | ||
<div class="table-row-group"> | ||
<NuxtLink | ||
v-for="(repo, index) in repositories" | ||
:key="repo.name" | ||
:to="repo.url" | ||
target="_blank" | ||
class="after:content-[' '] relative table-row *:table-cell *:px-4 *:py-6 *:align-top after:absolute after:inset-0 after:h-[1px] after:bg-slate-300" | ||
> | ||
<div> | ||
<div | ||
class="flex h-8 w-8 -translate-y-1 items-center justify-center rounded-full border border-solid border-slate-300" | ||
> | ||
{{ index + 1 }} | ||
</div> | ||
</div> | ||
<div> | ||
<div class="flex items-center gap-2 text-nowrap"> | ||
<img :src="repo.image" :alt="`GitHub ${repo.ownerName} avatar`" class="h-6 rounded" /> | ||
<h3 class="font-semibold">{{ repo.name }}</h3> | ||
</div> | ||
</div> | ||
<div> | ||
<div class="flex items-center gap-1"> | ||
<StarIcon class="h-4" /> | ||
<span>{{ repo.starsNumber.toLocaleString() }}</span> | ||
</div> | ||
</div> | ||
<div class="text-slate-400">{{ repo.description }}</div> | ||
<div> | ||
<div v-if="repo.language" class="flex items-center gap-1"> | ||
<div class="h-2 w-2 rounded-full" :style="{ backgroundColor: repo.language.color }" /> | ||
{{ repo.language?.name }} | ||
</div> | ||
</div> | ||
<div class="text-nowrap">{{ formatDuration(repo.age) }}</div> | ||
</NuxtLink> | ||
</div> | ||
</section> | ||
</template> |
Binary file not shown.
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,68 @@ | ||
type Repository = { | ||
name: string; | ||
ownerName: string; | ||
image: string; | ||
description: string; | ||
starsNumber: number; | ||
url: string; | ||
age: number; | ||
language?: { name: string; color: string }; | ||
}; | ||
|
||
export default defineEventHandler(async (event) => { | ||
const { githubToken } = useRuntimeConfig(event); | ||
|
||
const response = await fetch('https://api.github.com/graphql', { | ||
method: 'POST', | ||
headers: { | ||
Accept: 'application/vnd.github.v4.idl', | ||
Authorization: `Bearer ${githubToken}`, | ||
}, | ||
body: JSON.stringify({ | ||
query: ` | ||
query { | ||
search(query: "stars:>10000 sort:stars", type: REPOSITORY, first: 100) { | ||
edges { | ||
node { | ||
... on Repository { | ||
name | ||
description | ||
createdAt | ||
url | ||
stargazers { | ||
totalCount | ||
} | ||
owner { | ||
login | ||
avatarUrl | ||
} | ||
languages(first: 1) { | ||
nodes { | ||
name | ||
color | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
}), | ||
}); | ||
const { data } = await response.json(); | ||
|
||
const today = new Date(); | ||
|
||
const result: Repository[] = data.search.edges.map(({ node }: any) => ({ | ||
name: node.name, | ||
ownerName: node.owner.login, | ||
image: node.owner.avatarUrl, | ||
description: node.description, | ||
starsNumber: node.stargazers.totalCount, | ||
url: node.url, | ||
age: today.getTime() - new Date(node.createdAt).getTime(), | ||
language: node.languages.nodes[0], | ||
})); | ||
return result; | ||
}); |
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