add TOC add better blog navigation and a new blog post

This commit is contained in:
Zoe
2024-04-23 18:33:05 -05:00
parent df52d24242
commit 2e75732908
27 changed files with 2530 additions and 10686 deletions

View File

@@ -1,46 +1,162 @@
<script setup lang="ts">
import { withoutTrailingSlash } from 'ufo'
import { useBrowserLocation, useClipboard } from '@vueuse/core';
const { copy, copied } = useClipboard();
const location = useBrowserLocation()
let year = new Date().getFullYear();
let route = useRoute();
const { data: doc } = await useAsyncData('blog', () => queryContent(route.path).findOne())
if (!doc.value) {
throw createError({ statusCode: 404, statusMessage: 'Article not found', fatal: true })
}
const { data: surround } = await useAsyncData(`${route.path}-surround`, () => queryContent('/blog')
.where({ _extension: 'md' })
.only(['title', 'description', '_path'])
.sort({ date: 1 })
.where({ _draft: false })
.findSurround(withoutTrailingSlash(route.path))
)
const activeTocId: Ref<string | null> = ref(null)
const nuxtContent = ref(null)
const updateActiveHeading = () => {
const headings = document.querySelectorAll('#main h2[id], #main h3[id]')
const windowHeight = window.innerHeight
const windowMidpoint = windowHeight / 2
headings.forEach((heading) => {
const headingRect = heading.getBoundingClientRect()
const headingBottom = headingRect.bottom
if (headingBottom <= windowMidpoint) {
activeTocId.value = heading.id
}
})
}
onMounted(() => {
window.addEventListener('scroll', updateActiveHeading)
})
onUnmounted(() => {
window.removeEventListener('scroll', updateActiveHeading)
})
useSeoMeta({
title: doc.value?.title,
description: doc.value?.description,
ogTitle: doc.value?.title,
ogDescription: doc.value?.description,
ogImage: doc.value?.image.src,
ogUrl: 'https://juls07.dev',
twitterTitle: doc.value?.title,
twitterDescription: doc.value?.description,
twitterImage: doc.value?.image.src,
twitterCard: 'summary_large_image',
})
useHead({
htmlAttrs: {
lang: 'en'
},
meta: [
{
name: "copyright",
content: "© ${year} juls07"
},
{
name: "robots",
content: "index, follow"
},
{
name: "keywords",
content: doc.value?.tags.join(", ")
},
{
name: "author",
content: "juls07",
}
],
link: [
{
rel: 'icon',
type: 'image/png',
href: '/favicon.png'
}
]
})
</script>
<template>
<div class="min-h-screen">
<Nav />
<div class="grid grid-cols-12 gap-5 justify-center">
<div class="pt-6 mb-4 !col-start-2 md:!col-start-3 lg:!col-start-4 lg:col-span-6 md:col-span-8 col-span-10">
<ContentDoc v-slot="{ doc }">
<img :src="doc.image.src" class="mb-2 rounded-md drop-shadow" />
<h1 class="text-3xl dark:text-gray-100 md:text-4xl font-semibold mb-2">{{ doc.title }}</h1>
<p class="mb-1 dark:text-zinc-400 text-zinc-600">
{{ doc.description }}
</p>
<p class="mb-2 text-zinc-500">
{{ new Date(doc.date).toDateString().split(' ').slice(1).join(' ') }}
</p>
<div class="flex flex-wrap w-full gap-2 justify-start mb-3">
<IconTag v-for="tag in doc.tags" :name="tag" :iconName='tag' isTag="true" />
</div>
<main id="main" class="leading-relaxed">
<ContentRenderer class="dark:text-gray-200 text-gray-800" :value="doc" />
</main>
</ContentDoc>
</div>
</div>
<footer class="grid grid-cols-12 gap-5 justify-center">
<div class="py-2 mb-4 !col-start-3 md:!col-start-4 xl:!col-start-5 xl:col-span-4 md:col-span-6 col-span-8">
<!-- <NewsletterSignup class="mb-2" /> -->
© {{ year }} Juls07 - GPL v3.0 License
</div>
</footer>
</div>
<div class="min-h-screen">
<Nav />
<div class="grid grid-cols-12 gap-x-5 justify-center pt-6 mb-4 relative">
<div class="!col-start-2 md:!col-start-3 lg:!col-start-4 lg:col-span-6 md:col-span-8 col-span-10 order-1">
<NuxtImg :src="doc.image.src" class="mb-2 rounded-md drop-shadow w-full" quality="80" />
<h1 class="text-3xl dark:text-gray-100 md:text-4xl font-semibold mb-2">{{ doc.title }}</h1>
<p class="mb-1 dark:text-zinc-400 text-zinc-600">
{{ doc.description }}
</p>
<p class="mb-2 text-zinc-500">
{{ new Date(doc.date).toDateString().split(' ').slice(1).join(' ') }} |
{{ doc.readTime }} minute read
</p>
<div class="flex flex-wrap w-full gap-2 justify-start mb-3">
<IconTag v-for="tag in doc.tags" :name="tag" :iconName='tag' isTag="true" />
</div>
<hr class="mb-4 border-[#ECE6E7] dark:border-[#232326] border-t" />
</div>
<div class="!col-start-2 md:!col-start-3 lg:!col-start-4 lg:col-span-6 md:col-span-8 col-span-10 order-3">
<main id="main" class="leading-relaxed">
<ContentRenderer ref="nuxtContent" class="dark:text-gray-200 text-gray-800" :value="doc" />
</main>
</div>
<nav
class="lg:ml-2 mb-3 lg:mb-0 col-start-2 md:col-start-3 lg:block lg:col-start-10 lg:col-span-2 md:col-span-8 col-span-10 lg:sticky lg:top-8 h-fit order-2 lg:order-4">
<TableOfContents :doc="doc" :activeTocId="activeTocId" />
</nav>
<div class="!col-start-2 md:!col-start-3 lg:!col-start-4 lg:col-span-6 md:col-span-8 col-span-10 order-5">
<div class="flex justify-between mt-10">
<NuxtLink class="flex items-center text-fuschia hover:underline visited:bg-rose-700" to="/blog">
Back to Blog
</NuxtLink>
<button class="flex items-center px-2 py-1" @click="copy(location.origin + location.pathname)">
<Icon v-if="copied" name="tabler:check" class="mr-1.5" size="20" />
<Icon v-else name="tabler:link" class="mr-1.5" size="20" />
Copy Link
</button>
</div>
<div v-if="surround">
<hr class="my-6 border-[#ECE6E7] dark:border-[#232326] border-t" />
<div class="grid gap-8 grid-cols-1 sm:grid-cols-2">
<MiniBlogCard v-if="surround[0]" :to="surround[0]._path" :title="surround[0].title"
:description="surround[0].description" />
<MiniBlogCard class="col-start-2" v-if="surround[1]" :to="surround[1]._path"
:title="surround[1].title" :right-align="true" :description="surround[1].description" />
</div>
</div>
</div>
</div>
<footer class="grid grid-cols-12 gap-5 justify-center">
<div
class="pt-6 mb-4 !col-start-2 md:!col-start-3 lg:!col-start-4 lg:col-span-6 md:col-span-8 col-span-10 text-center">
© {{ year }} Juls07 - GPL v3.0 License
</div>
</footer>
</div>
</template>
<style>
br {
@apply my-3;
display: block;
@apply my-3;
display: block;
}
#main a {
@apply text-fuschia hover:underline visited:bg-rose-700;
@apply text-fuschia hover:underline visited:bg-rose-700;
}
</style>

View File

@@ -1,70 +1,69 @@
<script setup lang="ts">
useHead({
title: 'Juls07',
})
</script>
<template>
<div class="min-h-screen">
<Nav />
<main>
<div id="main" class="gap-4 justify-evenly py-2 grid grid-cols-[repeat(auto-fit,_minmax(50px,_450px))]">
<ContentQuery path="blog" :only="['image', '_path', 'title', 'description', 'date', 'tags', 'excerpt']"
:sort="{
date: -1
}" :where="{
_draft: false
}" v-slot="{ data }">
<div v-for="article in data" :key="article._path" class="mb-5 px-1.5">
<div
class="dark:bg-dark-slate bg-touched-lavender max-h-[563.25px] h-[563.25px] overflow-hidden rounded-lg border border-soft-lilac dark:border-midnight-slate/30 shadow-md">
<NuxtImg v-if="article.image.src" :src="article.image.src"
class="w-full rounded-tl-lg rounded-tr-lg aspect-video" loading="lazy" />
<div
class="p-3 overflow-hidden pt-2 text-fade dark:before:bg-[linear-gradient(180deg,transparent_0,hsla(0,0%,5%,0)_36%,#0C0B0C_95%,#0C0B0C)] before:bg-[linear-gradient(180deg,transparent_0,hsla(0,0%,5%,0)_36%,#F5EDFE_95%,#F5EDFE)] mb-1 pb-1 relative">
<h3>
<nuxt-link tabindex="0" class="text-lg" :to="article._path">
{{ article.title }}
</nuxt-link>
</h3>
<p class="dark:text-zinc-400 text-zinc-600">
{{ article.description }}
</p>
<p class="text-zinc-500">
{{ new Date(article.date).toDateString().split(' ').slice(1).join(' ') }}
</p>
<p class="dark:text-zinc-200 text-zinc-800 max-h-[13.75rem]">
<ContentDoc :head="false" :value="article" :path="article._path" v-slot="{ doc }">
<div class="flex flex-wrap w-full gap-2 justify-start my-1">
<IconTag v-for="tag in doc.tags" :name="tag" :iconName='tag' isTag="true" />
</div>
<div class="max-h-full leading-relaxed">
<ContentRenderer :value="doc">
<ContentRendererMarkdown :value="doc" :excerpt="true" />
</ContentRenderer>
</div>
</ContentDoc>
</p>
</div>
</div>
</div>
</ContentQuery>
</div>
</main>
</div>
<div class="min-h-screen">
<Nav />
<main>
<div id="main" class="gap-4 justify-evenly py-2 grid grid-cols-[repeat(auto-fit,_minmax(50px,_450px))]">
<ContentQuery path="blog"
:only="['image', '_path', 'title', 'description', 'date', 'tags', 'excerpt', 'readTime']" :sort="{
date: 1
}" :where="{
_draft: false
}" v-slot="{ data }">
<div v-for="article in data" :key="article._path" class="mb-5 px-1.5">
<div
class="dark:bg-dark-slate bg-touched-lavender max-h-[563.25px] h-[563.25px] overflow-hidden rounded-lg border border-soft-lilac dark:border-midnight-slate/30 shadow-md">
<NuxtImg v-if="article.image" :src="article.image.src" width="464" densities="1x 2x"
quality="80" class="w-full rounded-tl-lg rounded-tr-lg aspect-video" loading="lazy" />
<div
class="p-3 overflow-hidden pt-2 text-fade dark:before:bg-[linear-gradient(180deg,transparent_0,hsla(0,0%,5%,0)_36%,#0C0B0C_95%,#0C0B0C)] before:bg-[linear-gradient(180deg,transparent_0,hsla(0,0%,5%,0)_36%,#F5EDFE_95%,#F5EDFE)] mb-1 pb-1 relative">
<h3>
<nuxt-link tabindex="0" class="text-lg" :to="article._path">
{{ article.title }}
</nuxt-link>
</h3>
<p class="dark:text-zinc-400 text-zinc-600">
{{ article.description }}
</p>
<p class="text-zinc-500">
{{ new Date(article.date).toDateString().split(' ').slice(1).join(' ') }} |
{{ article.readTime }} minute read
</p>
<p class="dark:text-zinc-200 text-zinc-800 max-h-[13.75rem]">
<div class="flex flex-wrap w-full gap-2 justify-start my-1">
<IconTag v-for="tag in article.tags" :name="tag" :iconName='tag' isTag="true" />
</div>
<div class="max-h-full leading-relaxed">
<ContentRenderer :value="article">
<ContentRendererMarkdown :value="article" :excerpt="true" />
</ContentRenderer>
</div>
</p>
</div>
</div>
</div>
</ContentQuery>
</div>
</main>
</div>
</template>
<style>
.text-fade::before {
content: '';
position: absolute;
width: 100%;
height: 33.333333%;
left: 0px;
bottom: 0px;
content: '';
position: absolute;
width: 100%;
height: 33.333333%;
left: 0px;
bottom: 0px;
}
#main a {
@apply text-fuschia hover:underline visited:bg-rose-700;
@apply text-fuschia hover:underline visited:bg-rose-700;
}
</style>
<script setup lang="ts">
useHead({
title: 'Juls07',
})
</script>