🚀 refactor: unify page routing files

This commit is contained in:
radishzzz 2025-03-14 23:13:54 +00:00
parent d352b6fb65
commit 54902da6dd
19 changed files with 522 additions and 348 deletions

View file

@ -1,15 +0,0 @@
---
import { getMultiLangRoutes } from '@/i18n/route'
import Layout from '@/layouts/Layout.astro'
export function getStaticPaths() {
return getMultiLangRoutes()
}
---
<Layout>
<div class="uno-decorative-line"></div>
<div class="heti mt-4.375">
<p>Retypeset is a static blog theme based on the <a href="https://astro.build/">Astro</a> framework, inspired by <a href="https://astro-theme-typography.vercel.app/">Typography</a>. Retypeset establishes a new visual standard and reimagines the layout of all pages, offering a reading experience similar to paper books, reviving the beauty of typography. Details in every sight, elegance in every space.</p>
</div>
</Layout>

View file

@ -1,33 +0,0 @@
---
import PostList from '@/components/PostList.astro'
import { getMultiLangRoutes } from '@/i18n/route'
import Layout from '@/layouts/Layout.astro'
import { getPinnedPosts, getPostsByYear } from '@/utils/content'
export function getStaticPaths() {
return getMultiLangRoutes()
}
const { lang } = Astro.params
const pinnedPosts = await getPinnedPosts(lang)
const postsByYear = await getPostsByYear(lang)
---
<Layout>
<main>
<!-- Pinned Posts -->
{pinnedPosts.length > 0 && (
<section class="mb-7.5">
<div class="uno-decorative-line"></div>
<PostList posts={pinnedPosts} lang={lang} />
</section>
)}
<!-- Regular Posts -->
{[...postsByYear.entries()].map(([_year, posts]) => (
<section class="mb-7.5">
<div class="uno-decorative-line"></div>
<PostList posts={posts} lang={lang} />
</section>
))}
</main>
</Layout>

View file

@ -1,74 +0,0 @@
---
import Comments from '@/components/Comments/index.astro'
import PostTime from '@/components/PostTime.astro'
import { getMultiLangPostRoutes } from '@/i18n/route'
import Layout from '@/layouts/Layout.astro'
import { checkSlugDuplication } from '@/utils/content'
import { generateDescription } from '@/utils/description'
import { getCollection } from 'astro:content'
export async function getStaticPaths() {
const posts = await getCollection('posts')
const duplicates = await checkSlugDuplication(posts)
if (duplicates.length > 0) {
throw new Error(`Slug conflicts found:\n${duplicates.join('\n')}`)
}
return getMultiLangPostRoutes(posts)
}
const { lang } = Astro.params
const { post, supportedLangs = [] } = Astro.props
const description = generateDescription(post)
const { Content, remarkPluginFrontmatter } = await post.render()
---
<Layout
postTitle={post.data.title}
postDescription={description}
postSlug={post.slug}
supportedLangs={supportedLangs}
>
<article class="heti mb-12.6">
<h1 class="post-title">
<span
transition:name={`post-${post.data.abbrlink || post.slug}`}
data-disable-transition-on-theme
>
{post.data.title}
</span>
</h1>
<div
class="mb-17 block c-primary font-time"
transition:name={`time-${post.data.abbrlink || post.slug}`}
data-disable-transition-on-theme
>
<!-- published and updated time -->
<PostTime
date={post.data.published}
updatedDate={post.data.updated}
minutes={remarkPluginFrontmatter.minutes}
/>
</div>
<Content />
</article>
<!-- Tags -->
{post.data.tags && post.data.tags.length > 0 && (
<div class="uno-decorative-line"></div>
<div class="uno-tags-wrapper">
{post.data.tags.map(tag => (
<a
href={`/${lang}/tags/${tag}/`}
class="uno-tags-style"
>
{tag}
</a>
))}
</div>
)}
<Comments />
</Layout>

View file

@ -1,38 +0,0 @@
---
import PostList from '@/components/PostList.astro'
import { getMultiLangTagRoutes } from '@/i18n/route'
import Layout from '@/layouts/Layout.astro'
import { getAllTags, getPostsByTag } from '@/utils/content'
export async function getStaticPaths() {
const tags = await getAllTags()
return getMultiLangTagRoutes(tags)
}
const { lang } = Astro.params
const { tag } = Astro.props
const posts = await getPostsByTag(tag, lang)
const allTags = await getAllTags()
---
<Layout>
<div class="uno-decorative-line"></div>
<div class="uno-tags-wrapper">
{allTags.map(tag => (
<a
href={`/${lang}/tags/${tag}/`}
class={`uno-tags-style ${
Astro.props.tag === tag
? 'uno-tag-active'
: ''
}`}
>
{tag}
</a>
))}
</div>
<div class="mt-10.625">
<PostList posts={posts} lang={lang} />
</div>
</Layout>

View file

@ -1,26 +0,0 @@
---
import { getMultiLangRoutes } from '@/i18n/route'
import Layout from '@/layouts/Layout.astro'
import { getAllTags } from '@/utils/content'
export function getStaticPaths() {
return getMultiLangRoutes()
}
const { lang } = Astro.params
const allTags = await getAllTags()
---
<Layout>
<div class="uno-decorative-line"></div>
<div class="uno-tags-wrapper">
{allTags.map(tag => (
<a
href={`/${lang}/tags/${tag}/`}
class="uno-tags-style"
>
{tag}
</a>
))}
</div>
</Layout>