mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-16 11:41:17 +02:00
refactor: refactor article list component and routing logic, optimize multilingual article display
This commit is contained in:
parent
e5165dd740
commit
ff1673da9c
19 changed files with 609 additions and 690 deletions
70
src/components/PostList.astro
Normal file
70
src/components/PostList.astro
Normal file
|
@ -0,0 +1,70 @@
|
|||
---
|
||||
// Define props received by the component
|
||||
interface Post {
|
||||
data: {
|
||||
title: string
|
||||
abbrlink?: string
|
||||
published: Date
|
||||
lang?: string
|
||||
}
|
||||
slug?: string
|
||||
remarkPluginFrontmatter?: {
|
||||
minutes?: number
|
||||
}
|
||||
}
|
||||
|
||||
// Receive posts parameter passed from outside
|
||||
const { posts, lang: pageLang } = Astro.props
|
||||
|
||||
// Declare the type of props
|
||||
export interface Props {
|
||||
posts: Post[]
|
||||
lang?: string
|
||||
}
|
||||
|
||||
// 构建正确的链接路径
|
||||
function getPostUrl(post: Post) {
|
||||
const postPath = post.data.abbrlink || post.slug
|
||||
// 如果是在语言文件夹下的页面,添加语言前缀
|
||||
return pageLang ? `/${pageLang}/posts/${postPath}/` : `/posts/${postPath}/`
|
||||
}
|
||||
---
|
||||
<ul>
|
||||
{posts.map(post => (
|
||||
// Single Post
|
||||
<li class="mt-4.375">
|
||||
|
||||
<a
|
||||
class="hover:c-primary"
|
||||
href={getPostUrl(post)}
|
||||
transition:name={`post-${post.data.abbrlink || post.slug}`}
|
||||
data-disable-transition-on-theme
|
||||
>
|
||||
{post.data.title}
|
||||
</a>
|
||||
|
||||
<div
|
||||
class="uno-mobile-time"
|
||||
transition:name={`time-${post.data.abbrlink || post.slug}`}
|
||||
data-disable-transition-on-theme
|
||||
>
|
||||
<time>
|
||||
{post.data.published.toLocaleDateString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '-')}
|
||||
</time>
|
||||
<span class="ml-1.25">
|
||||
{post.remarkPluginFrontmatter?.minutes} min
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="uno-desktop-time">
|
||||
<time>
|
||||
{post.data.published.toLocaleDateString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '-')}
|
||||
</time>
|
||||
<span class="ml-1.25">
|
||||
{post.remarkPluginFrontmatter?.minutes} min
|
||||
</span>
|
||||
</div>
|
||||
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
Loading…
Add table
Add a link
Reference in a new issue