feat: i18n support for header, subtitle and about pages

This commit is contained in:
radishzzz 2025-03-15 02:52:23 +00:00
parent 22dc899a95
commit 96a89ddcd5
13 changed files with 103 additions and 30 deletions

10
.vscode/settings.json vendored
View file

@ -64,6 +64,7 @@
"Artículos", "Artículos",
"astrojs", "astrojs",
"attributify", "attributify",
"belleza",
"Beze", "Beze",
"blurhash", "blurhash",
"bmoji", "bmoji",
@ -96,13 +97,16 @@
"rashomon", "rashomon",
"rehype", "rehype",
"reimagines", "reimagines",
"Retipografía",
"Retypeset", "Retypeset",
"Reviviendo",
"Roundhand", "Roundhand",
"Sentimentalisme", "Sentimentalisme",
"Servetus", "Servetus",
"Sobre", "Sobre",
"srcset", "srcset",
"STIX", "STIX",
"tipográfica",
"titlebar", "titlebar",
"Twikoo", "Twikoo",
"Umami", "Umami",
@ -112,8 +116,12 @@
"waline", "waline",
"walinejs", "walinejs",
"weibo", "weibo",
"Возрождая",
"красоту",
"Переверстка",
"Посты", "Посты",
"себе", "себе",
"Теги" "Теги",
"типографики"
] ]
} }

View file

@ -1,11 +1,20 @@
--- ---
import themeConfig from '@/config' import themeConfig from '@/config'
import { ui } from '@/i18n/ui'
import { getPageInfo } from '@/utils/page' import { getPageInfo } from '@/utils/page'
const { title, subtitle } = themeConfig.site const { currentLang, getLocalizedPath } = getPageInfo(Astro.url.pathname)
const { titleSpace } = themeConfig.global const currentUI = ui[currentLang as keyof typeof ui]
const { getLocalizedPath } = getPageInfo(Astro.url.pathname)
const { title, subtitle } = themeConfig.site
const headerTitle = title || currentUI.title
const headerSubtitle = !subtitle
? ''
: (subtitle === 'Revive the beauty of typography'
? currentUI.subtitle
: subtitle)
const { titleSpace } = themeConfig.global
const marginBottom = { const marginBottom = {
1: 'mb-0.625', 1: 'mb-0.625',
2: 'mb-1.875', 2: 'mb-1.875',
@ -13,26 +22,23 @@ const marginBottom = {
}[titleSpace] || 'mb-3.125' }[titleSpace] || 'mb-3.125'
--- ---
<header <header class="mb-10.625 lg:fixed">
class="mb-10.625"
lg="fixed"
>
<h1 class={`${marginBottom} text-8 c-primary font-bold font-title lg:text-9`}> <h1 class={`${marginBottom} text-8 c-primary font-bold font-title lg:text-9`}>
<!-- Fix text cropping issues during view transition on ios by adding a div tag --> <!-- Fix text cropping issues during view transition on ios by adding a div tag -->
<div <div
class="box-content inline-block pr-1.25" class="box-content inline-block pr-1.25"
transition:name="site-title" transition:name={`site-title-${currentLang}`}
data-disable-transition-on-theme data-disable-transition-on-theme
> >
<a href={getLocalizedPath('/')}> <a href={getLocalizedPath('/')}>
{title} {headerTitle}
</a> </a>
</div> </div>
</h1> </h1>
{subtitle && ( {headerSubtitle && (
<h2 class="text-3.5 c-secondary font-navbar lg:text-4"> <h2 class="text-3.5 c-secondary font-navbar lg:text-4">
{subtitle} {headerSubtitle}
</h2> </h2>
)} )}
</header> </header>

View file

@ -1,11 +1,20 @@
--- ---
import themeConfig from '@/config' import themeConfig from '@/config'
import { ui } from '@/i18n/ui'
import { getPageInfo } from '@/utils/page' import { getPageInfo } from '@/utils/page'
const { title, subtitle } = themeConfig.site const { currentLang, getLocalizedPath } = getPageInfo(Astro.url.pathname)
const { titleSpace } = themeConfig.global const currentUI = ui[currentLang as keyof typeof ui]
const { getLocalizedPath } = getPageInfo(Astro.url.pathname)
const { title, subtitle } = themeConfig.site
const headerTitle = title || currentUI.title
const headerSubtitle = !subtitle
? ''
: (subtitle === 'Revive the beauty of typography'
? currentUI.subtitle
: subtitle)
const { titleSpace } = themeConfig.global
const marginBottom = { const marginBottom = {
1: 'mb-1.625', 1: 'mb-1.625',
2: 'mb-2.875', 2: 'mb-2.875',
@ -18,21 +27,21 @@ const marginBottom = {
<!-- Fix text cropping issues during view transition on ios by adding a div tag --> <!-- Fix text cropping issues during view transition on ios by adding a div tag -->
<div <div
class="box-content inline-block pr-1.25" class="box-content inline-block pr-1.25"
transition:name="site-title" transition:name={`site-title-${currentLang}`}
data-disable-transition-on-theme data-disable-transition-on-theme
> >
<a href={getLocalizedPath('/')}> <a href={getLocalizedPath('/')}>
{title} {headerTitle}
</a> </a>
</div> </div>
</h3> </h3>
{subtitle && ( {headerSubtitle && (
<div <div
class="text-3.5 opacity-0" class="text-3.5 opacity-0"
aria-hidden="true" aria-hidden="true"
> >
{subtitle} {headerSubtitle}
</div> </div>
)} )}
</header> </header>

View file

@ -4,9 +4,9 @@ export const themeConfig: ThemeConfig = {
// SITE INFORMATION >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> START // SITE INFORMATION >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> START
site: { site: {
// site title // site title
title: 'Retypeset', title: '',
// site subtitle (optional) // site subtitle (optional)
subtitle: '再现版式之美', subtitle: 'Revive the beauty of typography',
// site description for SEO // site description for SEO
description: 'Retypeset is a static blog theme based on the Astro framework, inspired by Typography. 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.', description: 'Retypeset is a static blog theme based on the Astro framework, inspired by Typography. 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.',
// author name // author name
@ -60,7 +60,7 @@ export const themeConfig: ThemeConfig = {
// date format for posts // date format for posts
dateFormat: 'YYYY-MM-DD', // YYYY-MM-DD, MM-DD-YYYY, DD-MM-YYYY, MONTH DAY YYYY, DAY MONTH YYYY dateFormat: 'YYYY-MM-DD', // YYYY-MM-DD, MM-DD-YYYY, DD-MM-YYYY, MONTH DAY YYYY, DAY MONTH YYYY
// space between title and subtitle // space between title and subtitle
titleSpace: 3, // 1, 2, 3 titleSpace: 2, // 1, 2, 3
}, },
// GLOBAL SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> END // GLOBAL SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> END

View file

@ -0,0 +1,5 @@
---
lang: en
---
Retypeset is a static blog theme based on the [Astro](https://astro.build/) framework, inspired by [Typography](https://astro-theme-typography.vercel.app/). 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.

View file

@ -0,0 +1,5 @@
---
lang: es
---
Retypeset es un tema de blog estático basado en el framework [Astro](https://astro.build/), inspirado en [Typography](https://astro-theme-typography.vercel.app/). Retypeset establece un nuevo estándar visual y reimagina la disposición de todas las páginas, ofreciendo una experiencia de lectura similar a la de los libros impresos, reviviendo la belleza de la tipografía. Detalles en cada mirada, elegancia en cada espacio.

View file

@ -0,0 +1,5 @@
---
lang: ja
---
Retypeset は [Astro](https://astro.build/) フレームワークをベースにした静的ブログテーマで、[Typography](https://astro-theme-typography.vercel.app/) からインスピレーションを得ています。新しい視覚的標準を確立し、すべてのページのレイアウトを再考することで、紙の本のような読書体験を提供し、タイポグラフィの美しさを蘇らせます。細部へのこだわりと、洗練された空間デザインが特徴です。

View file

@ -0,0 +1,5 @@
---
lang: ru
---
Retypeset — это статическая тема блога, основанная на фреймворке [Astro](https://astro.build/) и вдохновленная [Typography](https://astro-theme-typography.vercel.app/). Retypeset устанавливает новый визуальный стандарт и переосмысливает компоновку всех страниц, предлагая опыт чтения, подобный бумажным книгам, возрождая красоту типографики. Детали в каждом взгляде, элегантность в каждом пространстве.

View file

@ -0,0 +1,5 @@
---
lang: zh-tw
---
Retypeset 是一款基於 [Astro](https://astro.build/) 框架的靜態博客主題,設計靈感來自 [Typography](https://astro-theme-typography.vercel.app/)。本主題通過建立全新的視覺規範,對所有頁面進行重新編排,打造紙質書頁般的閱讀體驗,再現版式之美。所見皆為細節,方寸盡顯優雅。

View file

@ -0,0 +1,5 @@
---
lang: zh
---
Retypeset 是一款基于 [Astro](https://astro.build/) 框架的静态博客主题,设计灵感来自 [Typography](https://astro-theme-typography.vercel.app/)。本主题通过建立全新的视觉规范,对所有页面进行重新编排,打造纸质书页般的阅读体验,再现版式之美。所见皆为细节,方寸尽显优雅。

View file

@ -1,3 +1,4 @@
import { allLocales } from '@/config'
import { defineCollection, z } from 'astro:content' import { defineCollection, z } from 'astro:content'
const postsCollection = defineCollection({ const postsCollection = defineCollection({
@ -13,7 +14,7 @@ const postsCollection = defineCollection({
draft: z.boolean().optional().default(false), draft: z.boolean().optional().default(false),
pin: z.number().int().min(0).max(99).optional().default(0), pin: z.number().int().min(0).max(99).optional().default(0),
toc: z.boolean().optional().default(false), toc: z.boolean().optional().default(false),
lang: z.string().optional().default(''), lang: z.enum(['', ...allLocales]).optional().default(''),
abbrlink: z.string().optional().default('').refine( abbrlink: z.string().optional().default('').refine(
abbrlink => !abbrlink || /^[a-z0-9\-]*$/.test(abbrlink), abbrlink => !abbrlink || /^[a-z0-9\-]*$/.test(abbrlink),
{ message: 'Abbrlink can only contain lowercase letters, numbers and hyphens' }, { message: 'Abbrlink can only contain lowercase letters, numbers and hyphens' },
@ -21,6 +22,13 @@ const postsCollection = defineCollection({
}), }),
}) })
const aboutCollection = defineCollection({
schema: z.object({
lang: z.enum(['', ...allLocales]).optional().default(''),
}),
})
export const collections = { export const collections = {
posts: postsCollection, posts: postsCollection,
about: aboutCollection,
} }

View file

@ -1,30 +1,42 @@
export const ui = { export const ui = {
'zh': { 'zh': {
title: '重新编排',
subtitle: '再现版式之美',
posts: '文章', posts: '文章',
tags: '标签', tags: '标签',
about: '关于', about: '关于',
}, },
'zh-tw': { 'zh-tw': {
title: '重新編排',
subtitle: '再現版式之美',
posts: '文章', posts: '文章',
tags: '標籤', tags: '標籤',
about: '關於', about: '關於',
}, },
'ja': { 'ja': {
title: '再組版',
subtitle: '印刷の美を甦らせる',
posts: '記事', posts: '記事',
tags: 'タグ', tags: 'タグ',
about: '概要', about: '概要',
}, },
'en': { 'en': {
title: 'Retypeset',
subtitle: 'Revive the beauty of typography',
posts: 'Posts', posts: 'Posts',
tags: 'Tags', tags: 'Tags',
about: 'About', about: 'About',
}, },
'es': { 'es': {
title: 'Retipografía',
subtitle: 'Reviviendo la belleza tipográfica',
posts: 'Artículos', posts: 'Artículos',
tags: 'Etiquetas', tags: 'Etiquetas',
about: 'Sobre', about: 'Sobre',
}, },
'ru': { 'ru': {
title: 'Переверстка',
subtitle: 'Возрождая красоту типографики',
posts: 'Посты', posts: 'Посты',
tags: 'Теги', tags: 'Теги',
about: 'О себе', about: 'О себе',

View file

@ -1,6 +1,7 @@
--- ---
import { allLocales, defaultLocale } from '@/config' import { allLocales, defaultLocale } from '@/config'
import Layout from '@/layouts/Layout.astro' import Layout from '@/layouts/Layout.astro'
import { getCollection } from 'astro:content'
export async function getStaticPaths() { export async function getStaticPaths() {
type PathItem = { type PathItem = {
@ -30,17 +31,16 @@ export async function getStaticPaths() {
} }
const { lang } = Astro.props const { lang } = Astro.props
const allAboutEntries = await getCollection('about')
const aboutEntry = allAboutEntries.find(entry => entry.data.lang === lang)
|| allAboutEntries.find(entry => entry.data.lang === '')
const { Content } = aboutEntry ? await aboutEntry.render() : { Content: null }
--- ---
<Layout> <Layout>
<div class="uno-decorative-line"></div> <div class="uno-decorative-line"></div>
<div class="heti mt-4.375"> <div class="heti mt-4.375">
{lang === 'en' {Content && <Content />}
? (
<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>
)
: (
<p>Retypeset 是一款基于<a href="https://astro.build/">Astro</a>框架的静态博客主题,设计灵感来自<a href="https://astro-theme-typography.vercel.app/">Typography</a>。本主题通过建立全新的视觉规范,对所有页面进行重新编排,打造纸质书页般的阅读体验,再现版式之美。所见皆为细节,方寸尽显优雅。</p>
)}
</div> </div>
</Layout> </Layout>