Skip to content

Commit

Permalink
refactor(posts): make PostList a component
Browse files Browse the repository at this point in the history
  • Loading branch information
Octobug committed Nov 25, 2023
1 parent 995078d commit c8f9cd0
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 48 deletions.
53 changes: 5 additions & 48 deletions .vitepress/theme/components/HomeFeed.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
<template>
<div :class="$style.postList">
<div
v-for="post in postList"
:key="post.url"
:class="$style.postItem"
>
<a :href="post.url">
<span :class="$style.title">{{ post.frontmatter.title }}</span>
</a>
<span :class="$style.date">
{{ moment(post.frontmatter.datetime).format('ll') }}
</span>
</div>
</div>
<PostList
date-format="ll"
:post-list="postList"
/>

<div :class="$style.pagination">
<button
Expand Down Expand Up @@ -40,10 +30,10 @@

<script lang="ts" setup>
import type { ContentData } from "vitepress";
import moment from "moment-timezone";
import { useData } from "vitepress";
import { ref } from "vue";
import { data as allPosts } from "../posts.data";
import PostList from "./PostList.vue";
const { theme } = useData();
const allPostsLength = allPosts.length;
Expand All @@ -64,39 +54,6 @@ function turnTo(n: number) {
</script>

<style module scope>
.postList {
margin-bottom: 2rem;
}
.postItem {
margin: var(--ct-post-list-gap);
padding-bottom: 1px;
border-bottom: 1px dashed var(--vp-c-default-3);
}
.title {
display: block;
color: var(--vp-c-neutral);
font-weight: 500;
font-size: 1.05em;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.title:hover {
font-weight: bold;
font-style: italic;
}
.date {
float: right;
position: relative;
bottom: 1.6em;
font-size: 0.85em;
color: var(--vp-c-text-3);
}
.pagination {
padding-top: 2rem;
display: flex;
Expand Down
67 changes: 67 additions & 0 deletions .vitepress/theme/components/PostList.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<template>
<div :class="$style.postList">
<div
v-for="post in postList"
:key="post.url"
:class="$style.postItem"
>
<a :href="post.url">
<span :class="$style.title">{{ post.frontmatter.title }}</span>
</a>
<span :class="$style.date">
{{ moment(post.frontmatter.datetime).format(dateFormat) }}
</span>
</div>
</div>
</template>

<script lang="ts" setup>
import moment from "moment-timezone";
import Post from "../types/post";
defineProps({
postList: {
type: Array<Post>,
default: []
},
dateFormat: {
type: String,
default: "ll"
}
});
</script>

<style module scoped>
.postList {
margin-bottom: 2rem;
}
.postItem {
margin: var(--ct-post-list-gap);
padding-bottom: 1px;
border-bottom: 1px dashed var(--vp-c-default-3);
}
.title {
display: block;
color: var(--vp-c-neutral);
font-weight: 500;
font-size: 1.05em;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.title:hover {
font-weight: bold;
font-style: italic;
}
.date {
float: right;
position: relative;
bottom: 1.6em;
font-size: 0.85em;
color: var(--vp-c-text-3);
}
</style>
6 changes: 6 additions & 0 deletions .vitepress/theme/types/post.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Record from "vitepress";

export default interface Post {
frontmatter: Record<string, any>,
url: string
}

0 comments on commit c8f9cd0

Please sign in to comment.