public/components/CommitStatBox.vue

46 lines
1.3 KiB
Vue
Raw Normal View History

2022-08-08 19:11:31 -04:00
<script setup lang="ts">
2022-08-10 12:03:06 -04:00
import type { GithubPushEvent } from "@/shared/github";
2022-08-09 11:43:20 -04:00
import type { Ref } from "vue";
2022-08-08 19:11:31 -04:00
const FEED_URL = "https://api.github.com/users/potatoeggy/events";
2022-08-10 10:56:49 -04:00
const imgUrl = ref("");
const href = ref("");
2022-08-08 19:11:31 -04:00
2022-08-10 10:56:49 -04:00
onMounted(async () => {
const results = (await useFetch(FEED_URL)).data as Ref<GithubPushEvent[]>;
2022-08-10 10:56:49 -04:00
const latestEvent = results.value.find(
(event) => event.type === "PushEvent"
) as GithubPushEvent;
const latestCommit = latestEvent.payload.commits[0];
imgUrl.value = `https://opengraph.githubassets.com/hash/${latestEvent.repo.name}/commit/${latestCommit.sha}`;
href.value = `https://github.com/${latestEvent.repo.name}/commit/${latestCommit.sha}`;
});
2022-08-08 19:11:31 -04:00
</script>
<template>
2022-08-08 19:11:31 -04:00
<div class="prose dark:prose-invert">
<HomeStatBox
2024-10-16 13:30:57 -04:00
:href
id="github-commit-a"
2022-08-08 19:11:31 -04:00
color="lightgray"
2022-08-09 16:25:23 -04:00
darkcolor="slategray"
2022-08-08 19:11:31 -04:00
title="Latest commit"
2022-08-09 11:43:20 -04:00
:clearstyles="true"
2022-08-08 19:11:31 -04:00
>
2023-04-18 15:08:15 -04:00
<img
class="m-0 w-full h-full"
:src="imgUrl"
id="github-commit-img"
alt="Latest GitHub commit"
/>
2022-08-09 15:37:32 -04:00
<!--
<div>
<h2>{{ title }}</h2>
<p v-if="description">{{ description }}</p>
</div>
-->
2022-08-10 10:56:49 -04:00
<noscript> Enable JavaScript to see the latest commit! </noscript>
2022-08-08 19:11:31 -04:00
</HomeStatBox>
</div>
</template>