Skip to content

Commit

Permalink
Merge pull request #50 from vab1997/main
Browse files Browse the repository at this point in the history
Add: stars count repository
  • Loading branch information
pheralb committed May 11, 2023
2 parents 7ef31b6 + e9b097f commit 0d15934
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { LayoutServerLoad } from './$types';
import { fetchGitHubStars } from '@/utils/getStarsRepository';

export const load: LayoutServerLoad = async ({ url: { pathname } }) => {
return { pathname };
const stars = await fetchGitHubStars();
return { pathname, stars };
};
14 changes: 10 additions & 4 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import Heart from 'phosphor-svelte/lib/Heart';
import ArrowUpRight from 'phosphor-svelte/lib/ArrowUpRight';
import ArrowLeft from 'phosphor-svelte/lib/ArrowLeft';
import Star from 'phosphor-svelte/lib/Star';
// Toaster:
import { Toaster } from 'svelte-french-toast';
Expand All @@ -27,7 +28,7 @@

<main class="min-h-screen bg-light font-sans text-mini dark:bg-dark dark:text-white">
<nav
class="z-50 w-full overflow-y-auto overflow-x-hidden border-b border-neutral-300 dark:border-neutral-800 md:fixed md:top-0 md:left-0 md:h-full md:w-60 md:border-none md:pb-10"
class="z-50 w-full overflow-y-auto overflow-x-hidden border-b border-neutral-300 dark:border-neutral-800 md:fixed md:left-0 md:top-0 md:h-full md:w-60 md:border-none md:pb-10"
>
<div class="px-6 py-6">
<div class="mb-3 border-b border-neutral-300 pb-3 dark:border-neutral-700/40">
Expand Down Expand Up @@ -82,9 +83,14 @@
target="_blank"
class="flex w-full items-center space-x-2 rounded-md p-2 duration-100 hover:bg-neutral-200 dark:hover:bg-neutral-700/40"
>
<span>Repository</span>
<ArrowUpRight size={16} />
</a>
<span class="flex items-center justify-center">
Repository
{#if data.stars}
- Star <span class="mx-[2px]"><Star size={14} /></span>| {data.stars}
{/if}
<ArrowUpRight size={16} />
</span></a
>
</div>
<a
href="https://twitter.com/pheralb_"
Expand Down
10 changes: 10 additions & 0 deletions src/utils/getStarsRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export async function fetchGitHubStars() {
const res = await fetch('https://api.github.com/repos/pheralb/svgl');
const response = await res.json();
const starsFormated =
response.stargazers_count > 1000
? `${(response.stargazers_count / 1000).toFixed(1)}K`
: response.stargazers_count;

return starsFormated;
}

1 comment on commit 0d15934

@vercel
Copy link

@vercel vercel bot commented on 0d15934 May 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

svgl – ./

svgl.vercel.app
svgl-git-main-pheralb.vercel.app
svgl-pheralb.vercel.app

Please sign in to comment.