Files
sori.studio/pages/posts/index.vue

53 lines
1.4 KiB
Vue

<script setup>
const { data: posts } = await useFetch('/api/posts', {
default: () => []
})
const { data: tags } = await useFetch('/api/tags?tagType=all', {
default: () => []
})
/**
* 태그 슬러그로 공개 태그 이름을 찾는다.
* @param {string | undefined} slug - 태그 슬러그
* @returns {string} 태그 이름
*/
const getTagName = (slug) => {
if (!slug) {
return ''
}
return tags.value.find((tag) => tag.slug === slug)?.name || String(slug).toUpperCase()
}
const postCards = computed(() => posts.value.map((post) => ({
title: post.title,
excerpt: createPostSummary(post.excerpt, post.content, {
maxLength: 320,
appendEllipsis: false
}),
featuredImage: post.featuredImage,
featuredImageThumbnail: post.featuredImageThumbnail || '',
tag: getTagName(post.tags?.[0]),
publishedAt: formatPostDate(post.publishedAt),
to: `/post/${post.slug}`
})))
</script>
<template>
<MainColumn>
<section class="posts-index site-section">
<div class="posts-index__header site-section-header">
<p class="posts-index__eyebrow text-xs font-semibold uppercase text-muted">
Posts
</p>
<h1 class="posts-index__title mt-3 text-4xl font-semibold leading-tight">
게시물
</h1>
</div>
</section>
<PostCard v-for="post in postCards" :key="post.to" :post="post" />
</MainColumn>
</template>