Skip to content

Commit

Permalink
chore: add pinned. #46 (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
hu-qi committed Mar 27, 2024
1 parent b899981 commit dcf8339
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/.vitepress/theme/Home.vue
Expand Up @@ -33,12 +33,13 @@ const postsInPage = computed(() => {
</p>
</div>
<ul class="divide-y divide-gray-200 dark:divide-slate-200/5">
<li class="py-12" v-for="{ title, url, date, excerpt } of postsInPage">
<li class="py-12" v-for="{ title, url, date, excerpt, pinned } of postsInPage">
<article class="space-y-2 xl:grid xl:grid-cols-4 xl:space-y-0 xl:items-baseline">
<Date :date="date" />
<div class="space-y-5 xl:col-span-3">
<div class="space-y-6">
<h2 class="text-2xl leading-8 font-bold tracking-tight">
<span class="text-red-600" v-if="pinned">[置顶]</span>
<a class="text-gray-900 dark:text-white" :href="url">{{ title }}</a>
</h2>
<div
Expand Down
13 changes: 12 additions & 1 deletion src/.vitepress/theme/loaders/posts.ts
Expand Up @@ -11,6 +11,7 @@ export interface Post {
string: string
}
excerpt: string | undefined
pinned?: boolean
}

export interface PostsData {
Expand Down Expand Up @@ -78,8 +79,18 @@ export default function createPostsLoader(getPostsPerPage: () => number) {
url,
excerpt,
date: formatDate(frontmatter.date),
pinned: frontmatter.pinned === true,
}))
.sort((a, b) => b.date.time - a.date.time)
// .sort((a, b) => b.date.time - a.date.time)
.sort((a, b) => {
if (a.pinned && !b.pinned) {
return -1
} else if (!a.pinned && b.pinned) {
return 1
} else {
return b.date.time - a.date.time
}
})
const postsPerPage = getPostsPerPage()
const numPages = Math.ceil(posts.length / postsPerPage)
await createPagesDynamicRoutesWithCache(numPages)
Expand Down
1 change: 1 addition & 0 deletions src/posts/2023-os-report.md
Expand Up @@ -4,6 +4,7 @@ date: 2023-12-02
author:
name: 梦师傅
github: Ligoml
pinned: true
---

什么是开源项目和开源社区?国内活跃度 Top 的开源社区,都有哪些有趣的人和事?开源社区之于开源项目有何重要意义?
Expand Down

0 comments on commit dcf8339

Please sign in to comment.