public/components/CommitStatBox.vue

44 lines
1.3 KiB
Vue
Raw Normal View History

2022-08-08 19:11:31 -04:00
<script setup lang="ts">
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc.js";
import tz from "dayjs/plugin/timezone.js";
2022-08-09 15:37:32 -04:00
import type { GithubCommit, 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, { initialCache: false }))
.data as Ref<GithubPushEvent[]>;
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
2022-08-09 11:43:20 -04:00
:href="href"
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
>
2022-08-09 15:37:32 -04:00
<img class="m-0 w-full h-full" :src="imgUrl" />
<!--
<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>