refactor: theme config

This commit is contained in:
radishzzz 2025-03-11 12:10:12 +00:00
parent 8f8cda2717
commit 696fcfac07
15 changed files with 224 additions and 293 deletions

View file

@ -6,13 +6,9 @@ interface Props {
}
const { class: className } = Astro.props
const { author } = themeConfig.site
const {
startYear,
linkA: { name: nameA, url: urlA },
linkB: { name: nameB, url: urlB },
linkC: { name: nameC, url: urlC },
} = themeConfig.footer
const { links, startYear } = themeConfig.footer
const currentYear = new Date().getFullYear()
const year = Number(startYear) === currentYear
@ -22,20 +18,25 @@ const year = Number(startYear) === currentYear
<footer
class:list={[
'bottom-22 text-3 lg:text-3.5 leading-4.75 font-navbar',
className,
'bottom-22 text-3 lg:text-3.5 leading-4.75 font-navbar',
className,
]}
>
<p>
<a class="hover:(c-primary transition-colors)" href={urlA}>{nameA}</a> /
<a class="hover:(c-primary transition-colors)" href={urlB}>{nameB}</a> /
<a class="hover:(c-primary transition-colors)" href={urlC}>{nameC}</a>
{links.map((link, index) => (
<>
<a class="hover:(c-primary transition-colors)" href={link.url}>
{link.name}
</a>
{index < links.length - 1 && ' / '}
</>
))}
</p>
<p>
Powered by <a class="hover:(c-primary transition-colors)" href="https://astro.build/">Astro</a> and <a class="hover:(c-primary transition-colors)" href="https://github.com/radishzzz/astro-theme-retypeset">Retypeset</a>
</p>
<p>
© {year} {author}
</p>

View file

@ -1,6 +1,6 @@
---
import themeConfig from '@/config'
import { getPagePath } from '@/utils/i18n/path'
import { getPagePath } from '@/utils/path'
const { title, subtitle } = themeConfig.site
const { titleSpace } = themeConfig.global

View file

@ -1,6 +1,6 @@
---
import themeConfig from '@/config'
import { getPagePath } from '@/utils/i18n/path'
import { getPagePath } from '@/utils/path'
const { title, subtitle } = themeConfig.site
const { titleSpace } = themeConfig.global

View file

@ -1,6 +1,6 @@
---
import { getPagePath } from '@/utils/i18n/path'
import { ui } from '@/utils/i18n/ui'
import { getPagePath } from '@/utils/path'
const currentPath = Astro.url.pathname
const { currentLang, isHome, isPost, isTag, isAbout, getLocalizedPath }

View file

@ -1,6 +1,6 @@
---
import themeConfig from '@/config'
import { getPagePath } from '@/utils/i18n/path'
import { getPagePath } from '@/utils/path'
import { getCollection } from 'astro:content'
// 获取当前页面路径信息

View file

@ -3,17 +3,25 @@ import type { ThemeConfig } from '@/types'
export const themeConfig: ThemeConfig = {
// SITE INFORMATION >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> START
site: {
title: 'Retypeset', // site title
subtitle: '再现版式之美', // site subtitle (optional)
description: 'This is Retypeset, an elegant and open-source Astro blog theme, help you rediscover the beauty of typography.', // site description for SEO
author: 'radishzz', // author name
url: 'https://retypeset.radishzz.cc', // site url
favicon: '/image/logo.svg', // or https://example.com/logo.svg. Support webp, svg or png
// site title
title: 'Retypeset',
// site subtitle (optional)
subtitle: '再现版式之美',
// 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.',
// author name
author: 'radishzz',
// site url
url: 'https://retypeset.radishzz.cc',
// favicon url
// support only webp, svg or png
favicon: '/image/logo.svg', // https://example.com/logo.svg
},
// SITE INFORMATION >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> END
// COLOR SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> START
color: {
// default theme mode
mode: 'light', // light, dark
light: {
// title color
@ -23,7 +31,7 @@ export const themeConfig: ThemeConfig = {
// background color
background: 'oklch(96% 0.005 298)',
// code block theme
codeTheme: 'github-light',
codeTheme: 'github-light', // available themes: https://shiki.style/themes
},
dark: {
// title color
@ -33,20 +41,21 @@ export const themeConfig: ThemeConfig = {
// background color
background: 'oklch(22% 0.005 298)',
// code block theme
codeTheme: 'github-dark',
codeTheme: 'github-dark', // available themes: https://shiki.style/themes
},
},
// COLOR SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> END
// GLOBAL SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> START
global: {
// Default language
locale: 'zh', // support 'zh', 'zh-tw', 'ja', 'en', 'es', 'ru'
// Not fill in the default locale code again
moreLocale: ['zh-tw', 'ja', 'en', 'es', 'ru'], // ['zh', 'zh-tw', 'ja', 'en', 'es', 'ru']
// Font styles for post content
// default language
locale: 'zh', // zh, zh-tw, ja, en, es, ru
// more languages
// not fill in the locale above again
moreLocale: ['zh-tw', 'ja', 'en', 'es', 'ru'], // zh, zh-tw, ja, en, es, ru
// font styles for text
fontStyle: 'sans', // sans, serif
// Space between title and subtitle
// space between title and subtitle
titleSpace: 3, // 1, 2, 3
},
// GLOBAL SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> END
@ -54,67 +63,106 @@ export const themeConfig: ThemeConfig = {
// COMMENT SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> START
comment: {
waline: {
// Waline server URL
serverURL: 'https://retypeset-comment.radishzz.cc', // https://comment.example.com
// Emoji
// waline server url
serverURL: 'https://retypeset-comment.radishzz.cc',
// emoji url
emoji: [
'https://unpkg.com/@waline/emojis@1.2.0/tw-emoji',
// 'https://unpkg.com/@waline/emojis@1.2.0/bmoji',
// see more at https://waline.js.org/en/guide/features/emoji.html
// more emojis: https://waline.js.org/en/guide/features/emoji.html
],
// Whether to enable GIF search
// gif search
search: false, // true, false
// Whether to enable image uploader
// BUGunable to hide image uploader icon
imageUploader: false, // true, false
// image uploader
imageUploader: false, // true, false (BUGunable to hide image uploader icon)
},
// disqus: TODO
// giscus: TODO
// twikoo: TODO
},
// COMMENT SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> END
// SEO SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> START
seo: {
twitterID: '', // @twitter ID
// @twitter ID
twitterID: '',
// site verification
verification: {
google: '', // Google Search Console: https://search.google.com/search-console
bing: '', // Bing Webmaster Tools: https://www.bing.com/webmasters
yandex: '', // Yandex Webmaster: https://webmaster.yandex.com
baidu: '', // Baidu Search: https://ziyuan.baidu.com
// Google Search Console
google: '', // https://search.google.com/search-console
// Bing Webmaster Tools
bing: '', // https://www.bing.com/webmasters
// Yandex Webmaster
yandex: '', // https://webmaster.yandex.com
// Baidu Search
baidu: '', // https://ziyuan.baidu.com
},
googleAnalyticsID: '', // Google Analytics: https://analytics.google.com
umamiAnalyticsID: '520af332-bfb7-4e7c-9386-5f273ee3d697', // Umami Analytics: https://cloud.umami.is
// Google Analytics
googleAnalyticsID: '', // https://analytics.google.com
// Umami Analytics
umamiAnalyticsID: '520af332-bfb7-4e7c-9386-5f273ee3d697', // https://cloud.umami.is
// follow verification
// https://follow.is/
follow: {
feedID: '', // feed ID
userID: '', // user ID
// feed ID
feedID: '',
// user ID
userID: '',
},
},
// SEO SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> END
// NAVBAR SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> START
// navbar: {
// linkA: {
// // link name
// name: 'RSS',
// // link url
// url: '/rss.xml', // rss.xml or atom.xml
// },
// },
// NAVBAR SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> END
// FOOTER SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> START
footer: {
linkA: {
name: 'RSS', // Link name
url: '/rss.xml', // Link URL
},
linkB: {
name: 'GitHub', // Link name
url: 'https://github.com/radishzzz/astro-theme-retypeset', // Link URL
},
linkC: {
name: 'Telegram', // Link name
url: 'https://t.me/radishzz', // Link URL
},
startYear: '2024', // The year when website was established
// social links
links: [
{
name: 'RSS',
url: '/rss.xml', // rss.xml or atom.xml
},
{
name: 'GitHub',
url: 'https://github.com/radishzzz/astro-theme-retypeset',
},
{
name: 'Views',
url: 'https://views.radishzz.cc/share/uoGMvehDKafqkMC3/retypeset.radishzz.cc',
},
// {
// name: 'Mail',
// url: 'https://example@gmail.com',
// }
],
// year of website start
startYear: 2024,
},
// FOOTER SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> END
// PRELOAD SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> START
preload: {
commentURL: 'https://comment.radishzz.cc', // https://comment.example.com
imageHostURL: 'https://image.radishzz.cc', // https://image.example.com
// If you proxy analytics JavaScript to the custom domain, you can fill in below.
// See more at https://gist.github.com/xiaopc/0602f06ca465d76bd9efd3dda9393738 and https://github.com/umami-software/umami/discussions/1026
// link prefetch strategy
// details: https://docs.astro.build/en/guides/prefetch/#prefetch-strategies
linkPrefetch: 'viewport', // hover, tap, viewport, load
// comment server url
commentURL: 'https://comment.radishzz.cc',
// image hosting domain
imageHostURL: 'https://image.radishzz.cc',
// If you proxy analytics js to the custom domain, you can fill in below.
// See https://gist.github.com/xiaopc/0602f06ca465d76bd9efd3dda9393738
customGoogleAnalyticsJS: '', // https://custom.example.com/whatever.js
customUmamiAnalyticsJS: 'https://js.radishzz.cc/jquery.min.js', // https://custom.example.com/whatever.js
// see https://github.com/umami-software/umami/discussions/1026
customUmamiAnalyticsJS: '', // https://custom.example.com/whatever.js
},
// PRELOAD SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> END
}

View file

@ -10,7 +10,7 @@ import Navigation from '@/components/Navbar.astro'
import ThemeToggle from '@/components/Widgets/ThemeToggle.astro'
import themeConfig from '@/config'
import Head from '@/layouts/Head.astro'
import { getPagePath } from '@/utils/i18n/path'
import { getPagePath } from '@/utils/path'
import '@/styles/font.css'
import '@/styles/global.css'
import '@/styles/heti.css'

View file

@ -0,0 +1,27 @@
import type { APIContext } from 'astro'
import themeConfig from '@/config'
import { generateRSS } from '@/utils/rss'
const { moreLocale } = themeConfig.global
// Type for supported non-default languages
type SupportedLanguage = typeof moreLocale[number]
// Generate static paths for all supported languages
export function getStaticPaths() {
return moreLocale.map((lang: SupportedLanguage) => ({ params: { lang } }))
}
export async function GET({ params }: APIContext) {
const lang = params.lang as SupportedLanguage
// Return 404 if language is not supported
if (!moreLocale.includes(lang)) {
return new Response(null, {
status: 404,
statusText: 'Not found',
})
}
return generateRSS({ lang })
}

5
src/pages/atom.xml.ts Normal file
View file

@ -0,0 +1,5 @@
import { generateRSS } from '@/utils/rss'
export async function GET() {
return generateRSS()
}

15
src/types/index.d.ts vendored
View file

@ -62,22 +62,15 @@ export interface ThemeConfig {
}
footer: {
linkA: {
links: {
name: string
url: string
}
linkB: {
name: string
url: string
}
linkC: {
name: string
url: string
}
startYear: string
}[]
startYear: number
}
preload: {
linkPrefetch: 'hover' | 'tap' | 'viewport' | 'load'
commentURL?: string
imageHostURL?: string
customGoogleAnalyticsJS?: string

View file

@ -8,21 +8,12 @@ export const langMap: Record<string, string[]> = {
'ru': ['ru-RU'],
}
// Waline Language Map
// See more at https://waline.js.org/guide/i18n.html
export const walineLocaleMap: Record<string, string> = {
'zh': 'zh-CN',
'zh-tw': 'zh-TW',
'ja': 'jp-JP', // Waline uses jp-JP not ja-JP
'en': 'en-US',
'es': 'es-ES',
'ru': 'ru-RU',
}
// Standard Language Code
// Standard Language Code (Unused)
export const langCode = Object.values(langMap).flat()
// Abbreviated Language Code
export const langPath = Object.keys(langMap).flat()
// UI Translation
export const ui = {
'zh': {
@ -57,6 +48,17 @@ export const ui = {
},
}
// Waline Language Map
// See more at https://waline.js.org/guide/i18n.html
export const walineLocaleMap: Record<string, string> = {
'zh': 'zh-CN',
'zh-tw': 'zh-TW',
'ja': 'jp-JP', // Waline uses jp-JP not ja-JP
'en': 'en-US',
'es': 'es-ES',
'ru': 'ru-RU',
}
/**
* Get the language code of Waline
* @param currentPath Current page path

View file

@ -3,16 +3,16 @@ import themeConfig from '@/config'
const defaultLocale = themeConfig.global.locale
const moreLocales = themeConfig.global.moreLocale
// Get the language code in the path
// Get the language code from the path
export function getLangFromPath(path: string) {
const lang = path.split('/')[1]
return moreLocales.includes(lang) ? lang : defaultLocale
}
// Get the localized path
export function getLocalizedPath(path: string, currentLang?: string) {
export function getLocalizedPath(path: string) {
const pathWithoutSlashes = path.replace(/^\/+|\/+$/g, '')
const lang = currentLang || getLangFromPath(path)
const lang = getLangFromPath(path)
if (pathWithoutSlashes === '') {
return lang === defaultLocale ? '/' : `/${lang}/`
@ -21,22 +21,20 @@ export function getLocalizedPath(path: string, currentLang?: string) {
return lang === defaultLocale ? `/${pathWithoutSlashes}/` : `/${lang}/${pathWithoutSlashes}/`
}
// Checking the current path to the page
export function isHomePage(path: string) {
return path === '/' || moreLocales.some(lang => path === `/${lang}/`)
}
export function isPostPage(path: string) {
// 简化检查路径是否包含posts
return path.includes('/posts/')
}
export function isTagPage(path: string) {
// 简化检查路径是否包含tags
return path.includes('/tags/')
}
export function isAboutPage(path: string) {
// 简化检查路径是否包含about
return path.includes('/about/')
}
@ -49,30 +47,6 @@ export function getPagePath(path: string) {
isPost: isPostPage(path),
isTag: isTagPage(path),
isAbout: isAboutPage(path),
getLocalizedPath: (targetPath: string) => getLocalizedPath(targetPath, currentLang),
getLocalizedPath: (targetPath: string) => getLocalizedPath(targetPath),
}
}
/**
*
* @param post
* @returns
*/
export function getAvailableLanguages(post?: { data?: { lang?: string } }) {
// 默认支持所有配置的语言
const defaultLangs = ['', ...themeConfig.global.moreLocale]
// 如果没有提供文章对象,返回所有语言
if (!post || !post.data) {
return defaultLangs
}
// 确定文章支持的语言
if (post.data.lang && typeof post.data.lang === 'string' && post.data.lang.trim() !== '') {
// 如果lang是字符串
return ['', post.data.lang]
}
// 如果没有指定或格式不对,返回所有语言
return defaultLangs
}