-
Notifications
You must be signed in to change notification settings - Fork 239
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
5 changed files
with
72 additions
and
19 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
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 |
---|---|---|
|
@@ -57,6 +57,7 @@ | |
:root { | ||
/* bg-gray-900 */ | ||
--bg-color: rgb(17 24 39); | ||
color-scheme: dark; | ||
} | ||
|
||
html { | ||
|
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,7 +1,3 @@ | ||
:root { | ||
color-scheme: dark; | ||
} | ||
|
||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
|
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,65 @@ | ||
<script> | ||
import { onMount } from "svelte"; | ||
import createLocaleStorage from "../lib/createLocaleStorage"; | ||
import GithubIcon from "./GithubIcon.svelte"; | ||
const REPOSITORY_PATH = "matschik/component-party.dev"; | ||
const starCountStorage = createLocaleStorage("github-star-count"); | ||
let starCount = null; | ||
async function getRepoStarCount() { | ||
const starCountStorageData = starCountStorage.getJSON(); | ||
if ( | ||
starCountStorageData && | ||
starCountStorageData.fetchedAt > Date.now() - 1000 * 60 * 5 | ||
) { | ||
starCount = starCountStorageData.value; | ||
return; | ||
} | ||
const data = await fetch( | ||
`https://api.github.com/repos/${REPOSITORY_PATH}`, | ||
{ | ||
headers: { | ||
Accept: "application/vnd.github.v3.star+json", | ||
Authorization: "", | ||
}, | ||
} | ||
).then((r) => r.json()); | ||
starCount = data.stargazers_count; | ||
starCountStorage.setJSON({ | ||
value: starCount, | ||
fetchedAt: Date.now(), | ||
}); | ||
} | ||
onMount(() => { | ||
getRepoStarCount(); | ||
}); | ||
function onButtonClick() { | ||
starCountStorage.remove(); | ||
} | ||
</script> | ||
|
||
<a | ||
class="bg-[#21262d] text-[#c9d1d9] border border-[#373b43] py-1 rounded flex items-center text-sm shadow-inner hover:opacity-90" | ||
href={`https://github.com/${REPOSITORY_PATH}`} | ||
target="_blank" | ||
aria-label={`Star ${REPOSITORY_PATH} on GitHub`} | ||
on:click={onButtonClick} | ||
> | ||
<span | ||
class="space-x-2 flex items-center border-r border-[#373b43] font-medium px-2" | ||
> | ||
<GithubIcon class="w-[1.1rem] h-[1.1rem]" /> | ||
<span class="mt-px">Star</span> | ||
</span> | ||
{#if starCount !== null} | ||
<div class="h-full flex justify-center items-center pl-3 pr-3 font-medium"> | ||
<span class="mt-px">{starCount}</span> | ||
</div> | ||
{/if} | ||
</a> |
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