|
| 1 | +<template> |
| 2 | + <div class="blog-list"> |
| 3 | + <div class="blog-cards"> |
| 4 | + <article |
| 5 | + v-for="post in sortedPosts" |
| 6 | + :key="post.url" |
| 7 | + class="blog-card" |
| 8 | + @click="navigateToPost(post.url)" |
| 9 | + > |
| 10 | + <div class="blog-card-content"> |
| 11 | + <h3 class="blog-card-title"> |
| 12 | + {{ post.frontmatter.title }} |
| 13 | + </h3> |
| 14 | + |
| 15 | + <p class="blog-card-description"> |
| 16 | + {{ post.frontmatter.description }} |
| 17 | + </p> |
| 18 | + |
| 19 | + <div class="blog-card-footer"> |
| 20 | + <div class="blog-card-meta"> |
| 21 | + <span |
| 22 | + class="blog-card-category-indicator" |
| 23 | + :style="{ |
| 24 | + backgroundColor: getCategoryColor(post.frontmatter.category), |
| 25 | + }" |
| 26 | + ></span> |
| 27 | + <span class="blog-card-category-name">{{ |
| 28 | + post.frontmatter.category |
| 29 | + }}</span> |
| 30 | + </div> |
| 31 | + <time class="blog-card-date"> |
| 32 | + {{ formatDate(post.frontmatter.createdAt) }} |
| 33 | + </time> |
| 34 | + </div> |
| 35 | + </div> |
| 36 | + </article> |
| 37 | + </div> |
| 38 | + </div> |
| 39 | +</template> |
| 40 | + |
| 41 | +<script setup lang="ts"> |
| 42 | +import { computed } from "vue"; |
| 43 | +import { posts } from "../../data/posts"; |
| 44 | +import { getCategoryColor } from "../constants/colors"; |
| 45 | +import "./BlogList.css"; |
| 46 | +
|
| 47 | +interface Props { |
| 48 | + category?: string; |
| 49 | +} |
| 50 | +
|
| 51 | +const props = withDefaults(defineProps<Props>(), { |
| 52 | + category: undefined, |
| 53 | +}); |
| 54 | +
|
| 55 | +const sortedPosts = computed(() => { |
| 56 | + if (props.category) { |
| 57 | + return posts.filter( |
| 58 | + (post) => post.frontmatter.category.toLowerCase() === props.category!.toLowerCase(), |
| 59 | + ); |
| 60 | + } |
| 61 | + return posts; |
| 62 | +}); |
| 63 | +
|
| 64 | +// 날짜 포맷팅 함수 (yyyy-mm-dd 형식) |
| 65 | +function formatDate(dateString: string) { |
| 66 | + const date = new Date(dateString); |
| 67 | + return date |
| 68 | + .toLocaleDateString("ko-KR", { |
| 69 | + year: "numeric", |
| 70 | + month: "2-digit", |
| 71 | + day: "2-digit", |
| 72 | + }) |
| 73 | + .replace(/\. /g, "-") |
| 74 | + .replace(/\.$/, ""); |
| 75 | +} |
| 76 | +
|
| 77 | +function navigateToPost(url: string) { |
| 78 | + window.location.href = url; |
| 79 | +} |
| 80 | +</script> |
0 commit comments