Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add pinned. #46 #48

Merged
merged 2 commits into from Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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