Nuxt Content 3 migration #12

Merged
eggy merged 81 commits from js into master 2022-08-10 18:38:39 -04:00
4 changed files with 37 additions and 19 deletions
Showing only changes of commit 9484692dfa - Show all commits

View File

@ -7,6 +7,9 @@ import type { BlogParsedContent } from "@/shared/types";
dayjs.extend(utc); dayjs.extend(utc);
dayjs.extend(tz); dayjs.extend(tz);
// TODO: make queryContent async so it doesn't delay
// execution of the template
const docs = await queryContent<BlogParsedContent>("/blog") const docs = await queryContent<BlogParsedContent>("/blog")
.sort({ date: 1 }) .sort({ date: 1 })
.where({ _draft: false }) .where({ _draft: false })

View File

@ -6,17 +6,19 @@ import type { GithubCommit, GithubPushEvent } from "@/shared/github";
import type { Ref } from "vue"; import type { Ref } from "vue";
const FEED_URL = "https://api.github.com/users/potatoeggy/events"; const FEED_URL = "https://api.github.com/users/potatoeggy/events";
const imgUrl = ref("");
const href = ref("");
const results = (await useFetch(FEED_URL)).data as Ref<GithubPushEvent[]>; onMounted(async () => {
const results = (await useFetch(FEED_URL, { initialCache: false }))
.data as Ref<GithubPushEvent[]>;
const latestEvent = results.value.find( const latestEvent = results.value.find(
(event) => event.type === "PushEvent" (event) => event.type === "PushEvent"
) as GithubPushEvent; ) as GithubPushEvent;
const latestCommit = latestEvent.payload.commits[0]; const latestCommit = latestEvent.payload.commits[0];
const imgUrl = `https://opengraph.githubassets.com/hash/${latestEvent.repo.name}/commit/${latestCommit.sha}`; imgUrl.value = `https://opengraph.githubassets.com/hash/${latestEvent.repo.name}/commit/${latestCommit.sha}`;
const href = `https://github.com/${latestEvent.repo.name}/commit/${latestCommit.sha}`; href.value = `https://github.com/${latestEvent.repo.name}/commit/${latestCommit.sha}`;
});
const [title, description] = latestCommit.message.split("\n\n");
</script> </script>
<template> <template>
@ -35,6 +37,7 @@ const [title, description] = latestCommit.message.split("\n\n");
<p v-if="description">{{ description }}</p> <p v-if="description">{{ description }}</p>
</div> </div>
--> -->
<noscript> Enable JavaScript to see the latest commit! </noscript>
</HomeStatBox> </HomeStatBox>
</div> </div>
</template> </template>

View File

@ -22,12 +22,22 @@ const {
}>(); }>();
const padding = clearstyles ? "0" : "1rem"; const padding = clearstyles ? "0" : "1rem";
const height = forceheight ?? "auto"; const height = forceheight ?? "100%";
// v-bind DOES NOT WORK on initial render
// so unfortunately we have to use the old way
const cssVars = {
"--padding": padding,
"--height": height,
"--color": color,
"--darkcolor": darkcolor,
};
</script> </script>
<template> <template>
<a class="no-underline inline-block flex" :href="href"> <a class="no-underline inline-block flex flex-col items-stretch" :href="href">
<div class="container box"> <div class="container box" :style="cssVars">
<p class="m-0 w-full title">{{ title }}</p> <p class="m-0 w-full title">{{ title }}</p>
<div class="main-content"> <div class="main-content">
<slot /> <slot />
@ -43,8 +53,8 @@ const height = forceheight ?? "auto";
* mobile * mobile
*/ */
width: 28rem; width: 28rem;
height: v-bind(height); height: var(--height);
border: 0.5rem solid v-bind(color); border: 0.5rem solid var(--color);
border-radius: 0.5rem; border-radius: 0.5rem;
transition: transform 0.2s ease; transition: transform 0.2s ease;
box-shadow: 0 0.1rem 0.5rem 0 gray; box-shadow: 0 0.1rem 0.5rem 0 gray;
@ -61,17 +71,17 @@ html.dark .container {
} }
.main-content { .main-content {
padding: v-bind(padding); padding: var(--padding);
padding-top: 0; padding-top: 0;
overflow-wrap: break-word; overflow-wrap: break-word;
} }
.title { .title {
background: v-bind(color); background: var(--color);
} }
html.dark .title { html.dark .title {
background: v-bind(darkcolor); background: var(--dark-color);
} }
@media screen and (max-width: 600px) { @media screen and (max-width: 600px) {

View File

@ -9,7 +9,9 @@ useTitle("Home");
<main class="flex flex-col items-center justify-around gap-8"> <main class="flex flex-col items-center justify-around gap-8">
<h1>Welcome!</h1> <h1>Welcome!</h1>
<p>What are you here to see?</p> <p>What are you here to see?</p>
<div class="flex justify-around items-stretch w-full flex-wrap gap-y-10"> <div
class="flex justify-around items-stretch w-full flex-wrap gap-x-8 gap-y-10"
>
<BlogStatBox /> <BlogStatBox />
<StoryStatBox /> <StoryStatBox />
<CommitStatBox /> <CommitStatBox />