@jet-w/astro-blog 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-HVQKQN6B.js → chunk-6D3XRDNY.js} +1 -1
- package/dist/{chunk-ATRISB7B.js → chunk-A2E2VSAQ.js} +43 -3
- package/dist/{chunk-AZHCNNAC.js → chunk-TJTPX2WP.js} +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +2 -2
- package/dist/{i18n-5H4W145i.d.ts → i18n-PgMCFBw0.d.ts} +20 -0
- package/dist/index.d.ts +21 -3
- package/dist/index.js +20 -3
- package/dist/integration.d.ts +1 -1
- package/dist/integration.js +2 -2
- package/package.json +1 -1
- package/src/components/blog/FloatingToc.vue +11 -3
- package/src/components/blog/Hero.astro +17 -2
- package/src/components/blog/NavigationTabs.vue +46 -15
- package/src/components/blog/PostCard.astro +28 -10
- package/src/components/blog/RelatedPosts.astro +23 -7
- package/src/components/blog/TableOfContents.astro +10 -4
- package/src/components/blog/TagCloud.astro +4 -3
- package/src/components/home/FeaturedPostsSection.astro +22 -6
- package/src/components/home/QuickNavSection.astro +33 -4
- package/src/components/home/RecentPostsSection.astro +22 -6
- package/src/components/home/StatsSection.astro +24 -6
- package/src/components/layout/Header.astro +9 -5
- package/src/components/layout/Sidebar.astro +14 -11
- package/src/components/ui/SearchBox.vue +13 -5
- package/src/components/ui/SearchInterface.vue +49 -25
- package/src/pages/archives/[year]/[month].astro +36 -17
- package/src/pages/archives/index.astro +36 -20
- package/src/pages/categories/[category].astro +33 -16
- package/src/pages/categories/index.astro +37 -14
- package/src/pages/posts/[...slug].astro +125 -18
- package/src/pages/posts/index.astro +59 -37
- package/src/pages/posts/page/[page].astro +65 -27
- package/src/pages/search.astro +50 -14
- package/src/pages/slides/index.astro +25 -6
- package/src/pages/tags/[tag].astro +32 -15
- package/src/pages/tags/index.astro +39 -16
- package/src/plugins/remark-containers.mjs +351 -322
- package/src/plugins/remark-protect-code.mjs +69 -0
- package/src/styles/global.css +35 -1
- package/templates/default/.claude/ralph-loop.local.md +48 -0
- package/templates/default/astro.config.mjs +13 -4
- package/templates/default/content/posts/blog_docs_en/{get-started → 01.get-started}/01-intro.md +1 -1
- package/templates/default/content/posts/blog_docs_en/{get-started → 01.get-started}/02-install.md +1 -1
- package/templates/default/content/posts/blog_docs_en/{get-started → 01.get-started}/03-create-post.md +1 -1
- package/templates/default/content/posts/blog_docs_en/{get-started → 01.get-started}/04-structure.md +1 -1
- package/templates/default/content/posts/blog_docs_en/01.get-started/05-deploy.md +208 -0
- package/templates/default/content/posts/blog_docs_en/{get-started → 01.get-started}/README.md +1 -1
- package/templates/default/content/posts/blog_docs_en/02.guide/02-containers.md +245 -0
- package/templates/default/content/posts/blog_docs_en/{guide/markdown → 02.guide}/03-code-blocks.md +2 -1
- package/templates/default/content/posts/blog_docs_en/{guide/features/01-mermaid.md → 02.guide/03-mermaid.md} +1 -1
- package/templates/default/content/posts/blog_docs_en/{guide/features → 02.guide}/04-icons.md +4 -2
- package/templates/default/content/posts/blog_docs_en/{guide/features/02-latex.md → 02.guide/06-latex.md} +1 -1
- package/templates/default/content/posts/blog_docs_en/{guide/features/03-video.md → 02.guide/07-video.md} +1 -1
- package/templates/default/content/posts/blog_docs_en/02.guide/08-slides.md +359 -0
- package/templates/default/content/posts/blog_docs_en/{guide/markdown → 02.guide}/README.md +22 -3
- package/templates/default/content/posts/blog_docs_en/{config → 03.config}/01-site.md +1 -1
- package/templates/default/content/posts/blog_docs_en/{config → 03.config}/02-sidebar.md +1 -1
- package/templates/default/content/posts/blog_docs_en/{config → 03.config}/03-i18n.md +88 -24
- package/templates/default/content/posts/blog_docs_en/{config → 03.config}/README.md +1 -1
- package/templates/default/content/posts/blog_docs_en/README.md +2 -1
- package/templates/default/content/posts/blog_docs_zh/01.get-started/01-intro.md +81 -0
- package/templates/default/content/posts/blog_docs_zh/01.get-started/02-install.md +137 -0
- package/templates/default/content/posts/blog_docs_zh/01.get-started/03-create-post.md +176 -0
- package/templates/default/content/posts/blog_docs_zh/01.get-started/04-structure.md +173 -0
- package/templates/default/content/posts/blog_docs_zh/01.get-started/05-deploy.md +208 -0
- package/templates/default/content/posts/blog_docs_zh/01.get-started/README.md +52 -0
- package/templates/default/content/posts/blog_docs_zh/02.guide/02-containers.md +245 -0
- package/templates/default/content/posts/blog_docs_zh/02.guide/03-code-blocks.md +206 -0
- package/templates/default/content/posts/blog_docs_zh/02.guide/03-mermaid.md +194 -0
- package/templates/default/content/posts/blog_docs_zh/02.guide/04-icons.md +229 -0
- package/templates/default/content/posts/blog_docs_zh/02.guide/06-latex.md +233 -0
- package/templates/default/content/posts/blog_docs_zh/02.guide/07-video.md +184 -0
- package/templates/default/content/posts/blog_docs_zh/02.guide/08-slides.md +359 -0
- package/templates/default/content/posts/blog_docs_zh/02.guide/README.md +213 -0
- package/templates/default/content/posts/blog_docs_zh/03.config/01-site.md +208 -0
- package/templates/default/content/posts/blog_docs_zh/03.config/02-sidebar.md +240 -0
- package/templates/default/content/posts/blog_docs_zh/03.config/03-i18n.md +348 -0
- package/templates/default/content/posts/blog_docs_zh/03.config/README.md +85 -0
- package/templates/default/content/posts/blog_docs_zh/README.md +78 -0
- package/templates/default/src/config/locales/en/index.ts +5 -1
- package/templates/default/src/config/locales/en/menu.ts +3 -1
- package/templates/default/src/config/locales/en/sidebar.ts +18 -2
- package/templates/default/src/config/locales/en/site.ts +1 -1
- package/templates/default/src/config/locales/en/ui.ts +29 -0
- package/templates/default/src/config/locales/zh-CN/index.ts +5 -1
- package/templates/default/src/config/locales/zh-CN/menu.ts +7 -5
- package/templates/default/src/config/locales/zh-CN/sidebar.ts +22 -6
- package/templates/default/src/config/locales/zh-CN/site.ts +2 -2
- package/templates/default/src/config/locales/zh-CN/ui.ts +29 -0
- package/templates/default/src/config/site.ts +2 -2
- package/templates/default/src/content.config.ts +15 -3
- package/templates/default/content/posts/blog_docs/01-quick-start.md +0 -162
- package/templates/default/content/posts/blog_docs/02-frontmatter.md +0 -277
- package/templates/default/content/posts/blog_docs/03-markdown-basic.md +0 -350
- package/templates/default/content/posts/blog_docs/04-containers.md +0 -331
- package/templates/default/content/posts/blog_docs/05-code-blocks.md +0 -388
- package/templates/default/content/posts/blog_docs/06-mermaid.md +0 -431
- package/templates/default/content/posts/blog_docs/07-video.md +0 -243
- package/templates/default/content/posts/blog_docs/08-latex.md +0 -382
- package/templates/default/content/posts/blog_docs/09-icons.md +0 -326
- package/templates/default/content/posts/blog_docs/10-sidebar.md +0 -445
- package/templates/default/content/posts/blog_docs/11-config.md +0 -334
- package/templates/default/content/posts/blog_docs/12-i18n.md +0 -355
- package/templates/default/content/posts/blog_docs/12-slides.mdx +0 -552
- package/templates/default/content/posts/blog_docs/README.md +0 -152
- package/templates/default/content/posts/blog_docs_en/get-started/05-deploy.md +0 -197
- package/templates/default/content/posts/blog_docs_en/guide/README.md +0 -59
- package/templates/default/content/posts/blog_docs_en/guide/features/README.md +0 -51
- package/templates/default/content/posts/blog_docs_en/guide/markdown/02-containers.md +0 -226
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: 站点配置
|
|
3
|
-
description: 配置站点信息、菜单、社交链接和样式
|
|
4
|
-
pubDate: 2025-12-11
|
|
5
|
-
author: Astro Blog
|
|
6
|
-
categories:
|
|
7
|
-
- 博客教程
|
|
8
|
-
tags:
|
|
9
|
-
- 配置
|
|
10
|
-
- 主题
|
|
11
|
-
- 样式
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
# 站点配置
|
|
15
|
-
|
|
16
|
-
本博客采用模块化配置系统,所有配置文件位于 `src/config/` 目录。
|
|
17
|
-
|
|
18
|
-
## 配置文件概览
|
|
19
|
-
|
|
20
|
-
```
|
|
21
|
-
src/config/
|
|
22
|
-
├── site.ts # 站点基本信息
|
|
23
|
-
├── menu.ts # 导航菜单配置
|
|
24
|
-
├── sidebar.ts # 侧边栏配置
|
|
25
|
-
├── social.ts # 社交链接配置
|
|
26
|
-
└── footer.ts # 页脚配置
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## 站点信息 (site.ts)
|
|
30
|
-
|
|
31
|
-
配置博客的基本信息:
|
|
32
|
-
|
|
33
|
-
```typescript
|
|
34
|
-
// src/config/site.ts
|
|
35
|
-
export const siteConfig: SiteConfig = {
|
|
36
|
-
title: 'Astro Tech Blog',
|
|
37
|
-
description: '基于Astro构建的现代化技术博客',
|
|
38
|
-
author: 'Your Name',
|
|
39
|
-
email: 'your@email.com',
|
|
40
|
-
avatar: '/images/avatar.jpg',
|
|
41
|
-
social: {
|
|
42
|
-
github: 'https://github.com/username',
|
|
43
|
-
twitter: 'https://twitter.com/username',
|
|
44
|
-
linkedin: 'https://linkedin.com/in/username',
|
|
45
|
-
email: 'mailto:your@email.com'
|
|
46
|
-
},
|
|
47
|
-
menu // 从 menu.ts 导入
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// SEO 默认配置
|
|
51
|
-
export const defaultSEO = {
|
|
52
|
-
title: siteConfig.title,
|
|
53
|
-
description: siteConfig.description,
|
|
54
|
-
image: '/images/og-image.jpg',
|
|
55
|
-
type: 'website' as const
|
|
56
|
-
};
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## 导航菜单 (menu.ts)
|
|
60
|
-
|
|
61
|
-
配置顶部导航菜单项:
|
|
62
|
-
|
|
63
|
-
```typescript
|
|
64
|
-
// src/config/menu.ts
|
|
65
|
-
export const menu: NavigationItem[] = [
|
|
66
|
-
{
|
|
67
|
-
name: '首页',
|
|
68
|
-
href: '/',
|
|
69
|
-
icon: 'home'
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
name: '博客',
|
|
73
|
-
href: '/posts',
|
|
74
|
-
icon: 'posts'
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
name: '分类',
|
|
78
|
-
href: '/categories',
|
|
79
|
-
icon: 'categories'
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
name: '标签',
|
|
83
|
-
href: '/tags',
|
|
84
|
-
icon: 'tags'
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
name: '归档',
|
|
88
|
-
href: '/archives',
|
|
89
|
-
icon: 'archives'
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
name: '关于',
|
|
93
|
-
href: '/about',
|
|
94
|
-
icon: 'about'
|
|
95
|
-
}
|
|
96
|
-
];
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
### 图标选项
|
|
100
|
-
|
|
101
|
-
| icon 值 | 说明 |
|
|
102
|
-
|:---|:---|
|
|
103
|
-
| `home` | 首页图标 |
|
|
104
|
-
| `posts` | 文章图标 |
|
|
105
|
-
| `categories` | 分类图标 |
|
|
106
|
-
| `tags` | 标签图标 |
|
|
107
|
-
| `archives` | 归档图标 |
|
|
108
|
-
| `about` | 关于图标 |
|
|
109
|
-
|
|
110
|
-
## 社交链接 (social.ts)
|
|
111
|
-
|
|
112
|
-
配置社交媒体链接,显示在页脚和其他位置:
|
|
113
|
-
|
|
114
|
-
```typescript
|
|
115
|
-
// src/config/social.ts
|
|
116
|
-
export const socialLinks: SocialLink[] = [
|
|
117
|
-
{ type: 'github', url: 'https://github.com/username', label: 'GitHub' },
|
|
118
|
-
{ type: 'twitter', url: 'https://twitter.com/username', label: 'Twitter' },
|
|
119
|
-
{ type: 'linkedin', url: 'https://linkedin.com/in/username', label: 'LinkedIn' },
|
|
120
|
-
{ type: 'email', url: 'mailto:your@email.com', label: 'Email' }
|
|
121
|
-
];
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### 支持的社交平台
|
|
125
|
-
|
|
126
|
-
| type 值 | 平台 |
|
|
127
|
-
|:---|:---|
|
|
128
|
-
| `github` | GitHub |
|
|
129
|
-
| `twitter` | Twitter/X |
|
|
130
|
-
| `linkedin` | LinkedIn |
|
|
131
|
-
| `email` | 邮箱 |
|
|
132
|
-
| `youtube` | YouTube |
|
|
133
|
-
| `discord` | Discord |
|
|
134
|
-
| `weibo` | 微博 |
|
|
135
|
-
| `zhihu` | 知乎 |
|
|
136
|
-
|
|
137
|
-
每个平台都有内置的 SVG 图标,也可以通过 `icon` 字段自定义。
|
|
138
|
-
|
|
139
|
-
## 页脚配置 (footer.ts)
|
|
140
|
-
|
|
141
|
-
配置页脚内容:
|
|
142
|
-
|
|
143
|
-
```typescript
|
|
144
|
-
// src/config/footer.ts
|
|
145
|
-
export const footerConfig: FooterConfig = {
|
|
146
|
-
// 快速链接
|
|
147
|
-
quickLinksTitle: '快速链接',
|
|
148
|
-
quickLinks: [
|
|
149
|
-
{ name: '首页', href: '/' },
|
|
150
|
-
{ name: '文章', href: '/posts' },
|
|
151
|
-
{ name: '标签', href: '/tags' },
|
|
152
|
-
{ name: '分类', href: '/categories' },
|
|
153
|
-
{ name: '归档', href: '/archives' },
|
|
154
|
-
{ name: '关于', href: '/about' }
|
|
155
|
-
],
|
|
156
|
-
|
|
157
|
-
// 联系方式
|
|
158
|
-
contactTitle: '联系方式',
|
|
159
|
-
socialLinks: socialLinks, // 从 social.ts 导入
|
|
160
|
-
|
|
161
|
-
// RSS
|
|
162
|
-
showRss: true,
|
|
163
|
-
rssUrl: '/rss.xml',
|
|
164
|
-
|
|
165
|
-
// 版权信息(支持 {year} 和 {author} 占位符)
|
|
166
|
-
copyright: '© {year} {author}. All rights reserved.',
|
|
167
|
-
|
|
168
|
-
// Powered by
|
|
169
|
-
poweredBy: {
|
|
170
|
-
text: 'Astro',
|
|
171
|
-
url: 'https://astro.build'
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
## 深色模式
|
|
177
|
-
|
|
178
|
-
博客默认使用深色模式,并内置主题切换功能:
|
|
179
|
-
|
|
180
|
-
1. **自动检测**:首次访问时检测系统主题偏好
|
|
181
|
-
2. **用户选择**:记住用户的主题选择到 localStorage
|
|
182
|
-
3. **无闪烁**:使用内联脚本避免主题切换时的闪烁
|
|
183
|
-
|
|
184
|
-
### 切换方式
|
|
185
|
-
|
|
186
|
-
点击页面右上角的主题切换按钮(太阳/月亮图标)即可切换。
|
|
187
|
-
|
|
188
|
-
### 技术实现
|
|
189
|
-
|
|
190
|
-
```html
|
|
191
|
-
<!-- 浅色模式 -->
|
|
192
|
-
<html lang="zh-CN">
|
|
193
|
-
|
|
194
|
-
<!-- 深色模式 -->
|
|
195
|
-
<html lang="zh-CN" class="dark">
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
## 样式系统
|
|
199
|
-
|
|
200
|
-
### 全局样式
|
|
201
|
-
|
|
202
|
-
位置:`src/styles/global.css`
|
|
203
|
-
|
|
204
|
-
包含:
|
|
205
|
-
- Tailwind CSS 基础样式
|
|
206
|
-
- 自定义容器样式(tip/warning/danger 等)
|
|
207
|
-
- 代码块样式
|
|
208
|
-
- 表格样式
|
|
209
|
-
- 视频嵌入样式
|
|
210
|
-
- 深色模式适配
|
|
211
|
-
|
|
212
|
-
### 颜色系统
|
|
213
|
-
|
|
214
|
-
博客使用 Tailwind CSS 的颜色系统:
|
|
215
|
-
|
|
216
|
-
| 用途 | 颜色 |
|
|
217
|
-
|:---|:---|
|
|
218
|
-
| 主色调 | `primary-*` (蓝色系) |
|
|
219
|
-
| 中性色 | `slate-*` |
|
|
220
|
-
| 成功 | `green-*` |
|
|
221
|
-
| 警告 | `yellow-*` |
|
|
222
|
-
| 错误 | `red-*` |
|
|
223
|
-
| 信息 | `blue-*` |
|
|
224
|
-
|
|
225
|
-
### 修改主色调
|
|
226
|
-
|
|
227
|
-
在 `tailwind.config.cjs` 中覆盖 primary 颜色:
|
|
228
|
-
|
|
229
|
-
```javascript
|
|
230
|
-
module.exports = {
|
|
231
|
-
theme: {
|
|
232
|
-
extend: {
|
|
233
|
-
colors: {
|
|
234
|
-
primary: {
|
|
235
|
-
50: '#fdf4ff',
|
|
236
|
-
100: '#fae8ff',
|
|
237
|
-
// ...
|
|
238
|
-
500: '#d946ef', // 主色
|
|
239
|
-
600: '#c026d3',
|
|
240
|
-
// ...
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
## 响应式设计
|
|
249
|
-
|
|
250
|
-
使用 Tailwind 默认断点:
|
|
251
|
-
|
|
252
|
-
| 前缀 | 最小宽度 | 适用设备 |
|
|
253
|
-
|:---|:---|:---|
|
|
254
|
-
| `sm:` | 640px | 手机横屏 |
|
|
255
|
-
| `md:` | 768px | 平板 |
|
|
256
|
-
| `lg:` | 1024px | 笔记本 |
|
|
257
|
-
| `xl:` | 1280px | 桌面 |
|
|
258
|
-
| `2xl:` | 1536px | 大屏 |
|
|
259
|
-
|
|
260
|
-
## 代码高亮主题
|
|
261
|
-
|
|
262
|
-
代码块使用 Shiki 进行语法高亮。修改主题在 `astro.config.mjs`:
|
|
263
|
-
|
|
264
|
-
```javascript
|
|
265
|
-
export default defineConfig({
|
|
266
|
-
markdown: {
|
|
267
|
-
shikiConfig: {
|
|
268
|
-
theme: 'github-dark', // 可选: 'nord', 'dracula', 'one-dark-pro' 等
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
## 常见配置场景
|
|
275
|
-
|
|
276
|
-
### 修改站点标题和描述
|
|
277
|
-
|
|
278
|
-
编辑 `src/config/site.ts`:
|
|
279
|
-
|
|
280
|
-
```typescript
|
|
281
|
-
export const siteConfig: SiteConfig = {
|
|
282
|
-
title: '我的技术博客',
|
|
283
|
-
description: '分享技术,记录成长',
|
|
284
|
-
// ...
|
|
285
|
-
};
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
### 添加新的导航菜单项
|
|
289
|
-
|
|
290
|
-
编辑 `src/config/menu.ts`:
|
|
291
|
-
|
|
292
|
-
```typescript
|
|
293
|
-
export const menu: NavigationItem[] = [
|
|
294
|
-
// 现有菜单项...
|
|
295
|
-
{
|
|
296
|
-
name: '项目',
|
|
297
|
-
href: '/projects',
|
|
298
|
-
icon: 'posts'
|
|
299
|
-
}
|
|
300
|
-
];
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
### 添加社交链接
|
|
304
|
-
|
|
305
|
-
编辑 `src/config/social.ts`:
|
|
306
|
-
|
|
307
|
-
```typescript
|
|
308
|
-
export const socialLinks: SocialLink[] = [
|
|
309
|
-
// 现有链接...
|
|
310
|
-
{ type: 'youtube', url: 'https://youtube.com/@channel', label: 'YouTube' }
|
|
311
|
-
];
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
## 总结
|
|
315
|
-
|
|
316
|
-
恭喜你完成了博客使用指南的学习!现在你已经掌握了:
|
|
317
|
-
|
|
318
|
-
- 创建和组织文章
|
|
319
|
-
- Frontmatter 配置
|
|
320
|
-
- Markdown 增强语法
|
|
321
|
-
- 容器、代码块、图表、公式
|
|
322
|
-
- 视频嵌入
|
|
323
|
-
- 图标系统
|
|
324
|
-
- 侧边栏配置
|
|
325
|
-
- 站点配置和样式自定义
|
|
326
|
-
|
|
327
|
-
开始写作,分享你的知识吧!
|
|
328
|
-
|
|
329
|
-
::: tip 获取帮助
|
|
330
|
-
如有问题,可以:
|
|
331
|
-
1. 查阅本系列文档
|
|
332
|
-
2. 参考示例文章
|
|
333
|
-
3. 查看源代码实现
|
|
334
|
-
:::
|
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: 多语言支持
|
|
3
|
-
description: 配置博客的多语言支持,实现国际化
|
|
4
|
-
pubDate: 2025-12-11
|
|
5
|
-
author: Astro Blog
|
|
6
|
-
categories:
|
|
7
|
-
- 博客教程
|
|
8
|
-
tags:
|
|
9
|
-
- i18n
|
|
10
|
-
- 多语言
|
|
11
|
-
- 配置
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
# 多语言支持 (i18n)
|
|
15
|
-
|
|
16
|
-
本博客内置多语言支持,可以配置任意数量的语言,实现站点的国际化。
|
|
17
|
-
|
|
18
|
-
## 功能特点
|
|
19
|
-
|
|
20
|
-
::: info 核心特性
|
|
21
|
-
- **灵活配置**:支持任意数量的语言
|
|
22
|
-
- **自动路由**:自动生成带语言前缀的路由(如 `/en/posts`)
|
|
23
|
-
- **独立配置**:每种语言可以有独立的菜单、站点信息、页脚配置
|
|
24
|
-
- **内置翻译**:自带中文和英文的 UI 翻译
|
|
25
|
-
- **SEO 优化**:自动生成 `hreflang` 标签
|
|
26
|
-
- **语言切换器**:内置语言切换组件
|
|
27
|
-
:::
|
|
28
|
-
|
|
29
|
-
## 基本配置
|
|
30
|
-
|
|
31
|
-
在 `astro.config.mjs` 中配置多语言:
|
|
32
|
-
|
|
33
|
-
```javascript
|
|
34
|
-
import { defineConfig } from 'astro/config';
|
|
35
|
-
import { astroBlog, defineI18nConfig } from '@jet-w/astro-blog';
|
|
36
|
-
|
|
37
|
-
// i18n 配置
|
|
38
|
-
const i18nConfig = defineI18nConfig({
|
|
39
|
-
defaultLocale: 'zh-CN',
|
|
40
|
-
locales: [
|
|
41
|
-
{ code: 'zh-CN', name: '中文', htmlLang: 'zh-CN', dateLocale: 'zh-CN' },
|
|
42
|
-
{ code: 'en', name: 'English', htmlLang: 'en', dateLocale: 'en-US' },
|
|
43
|
-
],
|
|
44
|
-
routing: {
|
|
45
|
-
prefixDefaultLocale: false, // 默认语言不加前缀
|
|
46
|
-
},
|
|
47
|
-
localeConfigs: {
|
|
48
|
-
'zh-CN': {
|
|
49
|
-
// 中文配置
|
|
50
|
-
},
|
|
51
|
-
'en': {
|
|
52
|
-
// 英文配置
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
export default defineConfig({
|
|
58
|
-
integrations: [
|
|
59
|
-
astroBlog({ i18n: i18nConfig }),
|
|
60
|
-
// ... 其他集成
|
|
61
|
-
],
|
|
62
|
-
});
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## 配置详解
|
|
66
|
-
|
|
67
|
-
### 语言定义 (locales)
|
|
68
|
-
|
|
69
|
-
每种语言需要定义以下属性:
|
|
70
|
-
|
|
71
|
-
```typescript
|
|
72
|
-
interface Locale {
|
|
73
|
-
code: string; // 语言代码,如 'en', 'zh-CN', 'ja'
|
|
74
|
-
name: string; // 显示名称,如 'English', '中文'
|
|
75
|
-
htmlLang: string; // HTML lang 属性值
|
|
76
|
-
dateLocale: string; // 日期格式化使用的语言
|
|
77
|
-
direction?: 'ltr' | 'rtl'; // 文字方向(可选)
|
|
78
|
-
}
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
示例:
|
|
82
|
-
|
|
83
|
-
```javascript
|
|
84
|
-
locales: [
|
|
85
|
-
{ code: 'zh-CN', name: '中文', htmlLang: 'zh-CN', dateLocale: 'zh-CN' },
|
|
86
|
-
{ code: 'en', name: 'English', htmlLang: 'en', dateLocale: 'en-US' },
|
|
87
|
-
{ code: 'ja', name: '日本語', htmlLang: 'ja', dateLocale: 'ja-JP' },
|
|
88
|
-
{ code: 'ko', name: '한국어', htmlLang: 'ko', dateLocale: 'ko-KR' },
|
|
89
|
-
]
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
### 路由配置 (routing)
|
|
93
|
-
|
|
94
|
-
```javascript
|
|
95
|
-
routing: {
|
|
96
|
-
prefixDefaultLocale: false, // 是否为默认语言添加 URL 前缀
|
|
97
|
-
}
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
| 设置 | 默认语言路径 | 其他语言路径 |
|
|
101
|
-
|:---|:---|:---|
|
|
102
|
-
| `prefixDefaultLocale: false` | `/posts` | `/en/posts` |
|
|
103
|
-
| `prefixDefaultLocale: true` | `/zh-CN/posts` | `/en/posts` |
|
|
104
|
-
|
|
105
|
-
### 语言配置 (localeConfigs)
|
|
106
|
-
|
|
107
|
-
为每种语言配置独立的站点信息、菜单和页脚:
|
|
108
|
-
|
|
109
|
-
```javascript
|
|
110
|
-
localeConfigs: {
|
|
111
|
-
'zh-CN': {
|
|
112
|
-
site: {
|
|
113
|
-
title: '我的博客',
|
|
114
|
-
description: '基于 Astro 构建的个人博客',
|
|
115
|
-
},
|
|
116
|
-
menu: [
|
|
117
|
-
{ name: '首页', href: '/', icon: 'home' },
|
|
118
|
-
{ name: '博客', href: '/posts', icon: 'posts' },
|
|
119
|
-
{ name: '关于', href: '/about', icon: 'about' },
|
|
120
|
-
],
|
|
121
|
-
footer: {
|
|
122
|
-
quickLinksTitle: '快速链接',
|
|
123
|
-
contactTitle: '联系方式',
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
'en': {
|
|
127
|
-
site: {
|
|
128
|
-
title: 'My Blog',
|
|
129
|
-
description: 'A personal blog built with Astro',
|
|
130
|
-
},
|
|
131
|
-
menu: [
|
|
132
|
-
{ name: 'Home', href: '/en/', icon: 'home' },
|
|
133
|
-
{ name: 'Blog', href: '/en/posts', icon: 'posts' },
|
|
134
|
-
{ name: 'About', href: '/en/about', icon: 'about' },
|
|
135
|
-
],
|
|
136
|
-
footer: {
|
|
137
|
-
quickLinksTitle: 'Quick Links',
|
|
138
|
-
contactTitle: 'Contact',
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
}
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
::: warning 路径注意
|
|
145
|
-
非默认语言的菜单链接需要包含语言前缀(如 `/en/posts`)。
|
|
146
|
-
:::
|
|
147
|
-
|
|
148
|
-
## UI 翻译
|
|
149
|
-
|
|
150
|
-
### 内置翻译
|
|
151
|
-
|
|
152
|
-
博客内置了中文和英文的 UI 翻译,包括:
|
|
153
|
-
|
|
154
|
-
| 分类 | 翻译项 |
|
|
155
|
-
|:---|:---|
|
|
156
|
-
| 导航 | 首页、博客、关于、搜索 |
|
|
157
|
-
| 文章 | 文章列表、阅读更多、阅读时间 |
|
|
158
|
-
| 标签分类 | 标签、分类、全部标签、全部分类 |
|
|
159
|
-
| 归档 | 归档、篇文章 |
|
|
160
|
-
| 侧边栏 | 最新文章、热门标签、文档目录 |
|
|
161
|
-
| 页脚 | 快速链接、联系方式 |
|
|
162
|
-
| 搜索 | 搜索文章、搜索结果、无结果 |
|
|
163
|
-
| 分页 | 上一页、下一页、第 X 页 |
|
|
164
|
-
| 文章详情 | 发布于、更新于、目录、相关文章 |
|
|
165
|
-
| 其他 | 回到顶部、复制、已复制、展开、收起 |
|
|
166
|
-
|
|
167
|
-
### 自定义翻译
|
|
168
|
-
|
|
169
|
-
可以在 `localeConfigs` 中覆盖默认翻译:
|
|
170
|
-
|
|
171
|
-
```javascript
|
|
172
|
-
localeConfigs: {
|
|
173
|
-
'zh-CN': {
|
|
174
|
-
ui: {
|
|
175
|
-
readMore: '继续阅读',
|
|
176
|
-
noPostsFound: '还没有文章哦~',
|
|
177
|
-
searchPlaceholder: '输入关键词搜索...',
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
'en': {
|
|
181
|
-
ui: {
|
|
182
|
-
readMore: 'Continue Reading',
|
|
183
|
-
noPostsFound: 'No articles yet~',
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
}
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
### 添加新语言翻译
|
|
190
|
-
|
|
191
|
-
对于不内置支持的语言,需要提供完整的 UI 翻译:
|
|
192
|
-
|
|
193
|
-
```javascript
|
|
194
|
-
localeConfigs: {
|
|
195
|
-
'ja': {
|
|
196
|
-
site: { title: '私のブログ' },
|
|
197
|
-
menu: [...],
|
|
198
|
-
ui: {
|
|
199
|
-
home: 'ホーム',
|
|
200
|
-
blog: 'ブログ',
|
|
201
|
-
posts: '記事',
|
|
202
|
-
tags: 'タグ',
|
|
203
|
-
categories: 'カテゴリー',
|
|
204
|
-
search: '検索',
|
|
205
|
-
readMore: '続きを読む',
|
|
206
|
-
// ... 其他翻译
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
}
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
## 内容管理
|
|
213
|
-
|
|
214
|
-
### 文件组织方式
|
|
215
|
-
|
|
216
|
-
多语言内容可以通过文件夹组织:
|
|
217
|
-
|
|
218
|
-
```
|
|
219
|
-
content/posts/
|
|
220
|
-
├── blog_docs/ # 中文文档(默认语言)
|
|
221
|
-
│ ├── README.md
|
|
222
|
-
│ └── 01-quick-start.md
|
|
223
|
-
├── blog_docs_en/ # 英文文档
|
|
224
|
-
│ ├── README.md
|
|
225
|
-
│ └── 01-quick-start.md
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
::: info 内容自由管理
|
|
229
|
-
框架不强制内容的多语言对应关系,创作者可以自由决定哪些内容需要翻译。
|
|
230
|
-
:::
|
|
231
|
-
|
|
232
|
-
### 路径映射
|
|
233
|
-
|
|
234
|
-
| 文件路径 | 默认语言 URL | 其他语言 URL |
|
|
235
|
-
|:---|:---|:---|
|
|
236
|
-
| `blog_docs/README.md` | `/posts/blog_docs` | - |
|
|
237
|
-
| `blog_docs_en/README.md` | - | `/en/posts/blog_docs_en` |
|
|
238
|
-
|
|
239
|
-
## 语言切换器
|
|
240
|
-
|
|
241
|
-
博客内置语言切换器组件,显示在页面头部。
|
|
242
|
-
|
|
243
|
-
### 工作原理
|
|
244
|
-
|
|
245
|
-
1. 显示所有可用语言
|
|
246
|
-
2. 点击切换到对应语言版本
|
|
247
|
-
3. 自动构建正确的目标 URL
|
|
248
|
-
|
|
249
|
-
### 在 Vue 组件中使用 i18n
|
|
250
|
-
|
|
251
|
-
```vue
|
|
252
|
-
<script setup>
|
|
253
|
-
import { useI18n } from '@jet-w/astro-blog/utils/useI18n';
|
|
254
|
-
|
|
255
|
-
const { t, formatDate, locale } = useI18n();
|
|
256
|
-
</script>
|
|
257
|
-
|
|
258
|
-
<template>
|
|
259
|
-
<h1>{{ t('postList') }}</h1>
|
|
260
|
-
<span>{{ formatDate(post.pubDate) }}</span>
|
|
261
|
-
</template>
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
## 完整配置示例
|
|
265
|
-
|
|
266
|
-
```javascript
|
|
267
|
-
// astro.config.mjs
|
|
268
|
-
import { defineConfig } from 'astro/config';
|
|
269
|
-
import { astroBlog, defineI18nConfig } from '@jet-w/astro-blog';
|
|
270
|
-
|
|
271
|
-
const i18nConfig = defineI18nConfig({
|
|
272
|
-
defaultLocale: 'zh-CN',
|
|
273
|
-
locales: [
|
|
274
|
-
{ code: 'zh-CN', name: '中文', htmlLang: 'zh-CN', dateLocale: 'zh-CN' },
|
|
275
|
-
{ code: 'en', name: 'English', htmlLang: 'en', dateLocale: 'en-US' },
|
|
276
|
-
],
|
|
277
|
-
routing: {
|
|
278
|
-
prefixDefaultLocale: false,
|
|
279
|
-
},
|
|
280
|
-
localeConfigs: {
|
|
281
|
-
'zh-CN': {
|
|
282
|
-
site: {
|
|
283
|
-
title: 'My Astro Blog',
|
|
284
|
-
description: '基于 Astro + Vue + Tailwind 构建的个人技术博客',
|
|
285
|
-
},
|
|
286
|
-
menu: [
|
|
287
|
-
{ name: '首页', href: '/', icon: 'home' },
|
|
288
|
-
{ name: '博客教学', href: '/posts/blog_docs', icon: 'posts' },
|
|
289
|
-
{ name: '演示', href: '/slides', icon: 'slides' },
|
|
290
|
-
{ name: '关于', href: '/about', icon: 'about' },
|
|
291
|
-
],
|
|
292
|
-
footer: {
|
|
293
|
-
quickLinksTitle: '快速链接',
|
|
294
|
-
contactTitle: '联系方式',
|
|
295
|
-
},
|
|
296
|
-
},
|
|
297
|
-
'en': {
|
|
298
|
-
site: {
|
|
299
|
-
title: 'My Astro Blog',
|
|
300
|
-
description: 'A personal tech blog built with Astro + Vue + Tailwind',
|
|
301
|
-
},
|
|
302
|
-
menu: [
|
|
303
|
-
{ name: 'Home', href: '/en/', icon: 'home' },
|
|
304
|
-
{ name: 'Blog Docs', href: '/en/posts/blog_docs', icon: 'posts' },
|
|
305
|
-
{ name: 'Slides', href: '/en/slides', icon: 'slides' },
|
|
306
|
-
{ name: 'About', href: '/en/about', icon: 'about' },
|
|
307
|
-
],
|
|
308
|
-
footer: {
|
|
309
|
-
quickLinksTitle: 'Quick Links',
|
|
310
|
-
contactTitle: 'Contact',
|
|
311
|
-
},
|
|
312
|
-
},
|
|
313
|
-
},
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
export default defineConfig({
|
|
317
|
-
integrations: [
|
|
318
|
-
astroBlog({ i18n: i18nConfig }),
|
|
319
|
-
// ... 其他集成
|
|
320
|
-
],
|
|
321
|
-
});
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
## SEO 优化
|
|
325
|
-
|
|
326
|
-
### hreflang 标签
|
|
327
|
-
|
|
328
|
-
框架自动为多语言页面生成 `hreflang` 标签:
|
|
329
|
-
|
|
330
|
-
```html
|
|
331
|
-
<link rel="alternate" hreflang="zh-CN" href="https://example.com/posts/hello" />
|
|
332
|
-
<link rel="alternate" hreflang="en" href="https://example.com/en/posts/hello" />
|
|
333
|
-
<link rel="alternate" hreflang="x-default" href="https://example.com/posts/hello" />
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
这有助于搜索引擎理解页面的语言版本关系。
|
|
337
|
-
|
|
338
|
-
## 注意事项
|
|
339
|
-
|
|
340
|
-
::: tip 向后兼容
|
|
341
|
-
不配置 i18n 时,博客默认使用中文单语言模式,与之前的行为完全一致。
|
|
342
|
-
:::
|
|
343
|
-
|
|
344
|
-
::: warning 路径一致性
|
|
345
|
-
确保菜单链接、内部链接使用正确的语言前缀,避免出现 404 错误。
|
|
346
|
-
:::
|
|
347
|
-
|
|
348
|
-
::: info 渐进式采用
|
|
349
|
-
可以先配置好 i18n,然后逐步添加多语言内容,不需要一次性完成所有翻译。
|
|
350
|
-
:::
|
|
351
|
-
|
|
352
|
-
## 下一步
|
|
353
|
-
|
|
354
|
-
- [站点配置](./11-config) - 了解更多配置选项
|
|
355
|
-
- [快速开始](./01-quick-start) - 返回入门指南
|