From cac96eca8c9c5c778a84a97a6934c1bdee411001 Mon Sep 17 00:00:00 2001 From: radishzzz Date: Tue, 18 Mar 2025 05:37:33 +0000 Subject: [PATCH] feat: add desktop back home button on posts page --- package.json | 2 +- src/components/Navbar.astro | 3 +-- src/components/PostList.astro | 2 +- src/components/Widgets/BackHome.astro | 15 +++++++++++++++ src/layouts/Layout.astro | 20 +++++++++++++++++++- src/pages/[...posts_slug].astro | 26 ++++++++++++++++---------- src/styles/heti.css | 2 +- 7 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 src/components/Widgets/BackHome.astro diff --git a/package.json b/package.json index 21183e8..2e6d930 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "astro-theme-retypeset", "type": "module", "version": "0.0.1", - "packageManager": "pnpm@10.6.3", + "packageManager": "pnpm@10.6.4", "scripts": { "dev": "astro dev", "build": "astro build", diff --git a/src/components/Navbar.astro b/src/components/Navbar.astro index fd9da40..a0dcaa0 100644 --- a/src/components/Navbar.astro +++ b/src/components/Navbar.astro @@ -2,8 +2,7 @@ import { ui } from '@/i18n/ui' import { getPageInfo } from '@/utils/page' -const { currentLang, isHome, isPost, isTag, isAbout, getLocalizedPath } - = getPageInfo(Astro.url.pathname) +const { currentLang, isHome, isPost, isTag, isAbout, getLocalizedPath } = getPageInfo(Astro.url.pathname) const currentUI = ui[currentLang as keyof typeof ui] const isPostActive = isHome || isPost diff --git a/src/components/PostList.astro b/src/components/PostList.astro index def8abf..c0350e6 100644 --- a/src/components/PostList.astro +++ b/src/components/PostList.astro @@ -46,7 +46,7 @@ function getPostPath(post: Post) { {/* mobile post time */}
diff --git a/src/components/Widgets/BackHome.astro b/src/components/Widgets/BackHome.astro new file mode 100644 index 0000000..7ca5bce --- /dev/null +++ b/src/components/Widgets/BackHome.astro @@ -0,0 +1,15 @@ + diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 75d265b..95b2f19 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -24,7 +24,8 @@ interface Props { } const { postTitle, postDescription, postSlug, supportedLangs = [] } = Astro.props -const { isHome, isPost } = getPageInfo(Astro.url.pathname) +const { isHome, isPost, getLocalizedPath } = getPageInfo(Astro.url.pathname) +const localizedHome = getLocalizedPath('/') const { light: { background: lightMode }, dark: { background: darkMode } } = themeConfig.color const fontStyle = themeConfig.global.fontStyle === 'serif' ? 'font-serif' : 'font-sans' const mobileFooterMargin = isPost && themeConfig.comment?.waline?.serverURL @@ -149,5 +150,22 @@ const mobileFooterMargin = isPost && themeConfig.comment?.waline?.serverURL document.addEventListener('astro:after-swap', setupThemeToggle) + + + diff --git a/src/pages/[...posts_slug].astro b/src/pages/[...posts_slug].astro index fdc7ef8..97bcb6b 100644 --- a/src/pages/[...posts_slug].astro +++ b/src/pages/[...posts_slug].astro @@ -2,6 +2,7 @@ import type { CollectionEntry } from 'astro:content' import Comments from '@/components/Comments/index.astro' import PostDate from '@/components/PostDate.astro' +import BackHome from '@/components/Widgets/BackHome.astro' import { allLocales, defaultLocale, moreLocales } from '@/config' import { getTagPath } from '@/i18n/path' import Layout from '@/layouts/Layout.astro' @@ -18,6 +19,7 @@ export async function getStaticPaths() { throw new Error(`Duplicate post slugs:\n${duplicates.join('\n')}`) } + // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> // Use a Map to store the relationship between post slugs and their supported languages // Set is used to store the supported languages for each post const slugToLangsMap = posts.reduce((map, post) => { @@ -43,7 +45,7 @@ export async function getStaticPaths() { ]), ) - // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> type PathItem = { params: { posts_slug: string } props: { post: any, lang: string, supportedLangs: string[] } @@ -104,15 +106,19 @@ const { Content, remarkPluginFrontmatter } = await post.render() supportedLangs={supportedLangs} >
- -

- - {post.data.title} - -

+
+ + + +

+ + {post.data.title} + +

+