@jet-w/astro-blog 0.2.0 → 0.2.2
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-DAH2XP4W.js +154 -0
- package/dist/{chunk-AZHCNNAC.js → chunk-PG43JO4O.js} +1 -153
- package/dist/chunk-PZICDGJG.js +69 -0
- package/dist/chunk-Z3O3JK56.js +186 -0
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +9 -7
- package/dist/{i18n-5H4W145i.d.ts → i18n-DYYPTq4o.d.ts} +21 -1
- package/dist/index.d.ts +10 -184
- package/dist/index.js +37 -210
- package/dist/integration.d.ts +2 -2
- package/dist/integration.js +2 -2
- package/dist/{sidebar-Da-W_4Lr.d.ts → sidebar-DNdiCKBw.d.ts} +1 -1
- package/dist/utils/i18n.d.ts +133 -0
- package/dist/utils/i18n.js +49 -0
- package/dist/utils/sidebar.d.ts +1 -1
- package/dist/utils/useI18n.d.ts +74 -0
- package/dist/utils/useI18n.js +15 -0
- package/package.json +9 -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/package.dev.json +31 -0
- package/templates/default/package.json +1 -1
- 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
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 多语言支持
|
|
3
|
+
description: 为博客添加多语言支持
|
|
4
|
+
pubDate: 2025-01-01
|
|
5
|
+
author: jet-w
|
|
6
|
+
categories:
|
|
7
|
+
- 文档
|
|
8
|
+
tags:
|
|
9
|
+
- 配置
|
|
10
|
+
- 多语言
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# 多语言支持
|
|
14
|
+
|
|
15
|
+
添加多语言支持以触达全球受众。
|
|
16
|
+
|
|
17
|
+
## 概述
|
|
18
|
+
|
|
19
|
+
多语言系统提供:
|
|
20
|
+
|
|
21
|
+
- **多种语言** - 支持任意数量的语言
|
|
22
|
+
- **URL 前缀** - `/en/posts`、`/zh-CN/posts`
|
|
23
|
+
- **语言独立配置** - 不同的菜单、标题等
|
|
24
|
+
- **语言切换器** - 内置 UI 组件
|
|
25
|
+
- **SEO** - 正确的 hreflang 标签
|
|
26
|
+
|
|
27
|
+
## 基本设置
|
|
28
|
+
|
|
29
|
+
### 1. 配置语言
|
|
30
|
+
|
|
31
|
+
在 `astro.config.mjs` 中:
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
import { astroBlog, defineI18nConfig } from '@jet-w/astro-blog';
|
|
35
|
+
import { enConfig } from './src/config/locales/en';
|
|
36
|
+
import { zhCNConfig } from './src/config/locales/zh-CN';
|
|
37
|
+
|
|
38
|
+
const i18nConfig = defineI18nConfig({
|
|
39
|
+
defaultLocale: 'en',
|
|
40
|
+
locales: [
|
|
41
|
+
{ code: 'en', name: 'English', htmlLang: 'en', dateLocale: 'en-US' },
|
|
42
|
+
{ code: 'zh-CN', name: '中文', htmlLang: 'zh-CN', dateLocale: 'zh-CN' },
|
|
43
|
+
],
|
|
44
|
+
routing: {
|
|
45
|
+
prefixDefaultLocale: false,
|
|
46
|
+
},
|
|
47
|
+
localeConfigs: {
|
|
48
|
+
'en': enConfig,
|
|
49
|
+
'zh-CN': zhCNConfig,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export default defineConfig({
|
|
54
|
+
integrations: [astroBlog({ i18n: i18nConfig })],
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 2. 创建语言配置
|
|
59
|
+
|
|
60
|
+
为每种语言创建文件夹:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
src/config/locales/
|
|
64
|
+
├── en/
|
|
65
|
+
│ ├── index.ts
|
|
66
|
+
│ ├── site.ts
|
|
67
|
+
│ ├── menu.ts
|
|
68
|
+
│ ├── footer.ts
|
|
69
|
+
│ ├── sidebar.ts
|
|
70
|
+
│ └── ui.ts # UI 翻译
|
|
71
|
+
└── zh-CN/
|
|
72
|
+
├── index.ts
|
|
73
|
+
├── site.ts
|
|
74
|
+
├── menu.ts
|
|
75
|
+
├── footer.ts
|
|
76
|
+
├── sidebar.ts
|
|
77
|
+
└── ui.ts # UI 翻译
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 3. 配置每种语言
|
|
81
|
+
|
|
82
|
+
**英文 (`en/index.ts`):**
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { site } from './site';
|
|
86
|
+
import { menu } from './menu';
|
|
87
|
+
import { footer } from './footer';
|
|
88
|
+
import { sidebar } from './sidebar';
|
|
89
|
+
import { ui } from './ui';
|
|
90
|
+
|
|
91
|
+
export const enConfig = {
|
|
92
|
+
site,
|
|
93
|
+
menu,
|
|
94
|
+
footer,
|
|
95
|
+
sidebar,
|
|
96
|
+
ui,
|
|
97
|
+
};
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**英文站点 (`en/site.ts`):**
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
export const site = {
|
|
104
|
+
title: 'My Blog',
|
|
105
|
+
description: 'A blog about technology',
|
|
106
|
+
};
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**英文菜单 (`en/menu.ts`):**
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
export const menu = [
|
|
113
|
+
{ name: 'Home', href: '/', icon: 'home' },
|
|
114
|
+
{ name: 'Posts', href: '/posts', icon: 'posts' },
|
|
115
|
+
{ name: 'About', href: '/about', icon: 'about' },
|
|
116
|
+
];
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## URL 结构
|
|
120
|
+
|
|
121
|
+
当 `prefixDefaultLocale: false` 时:
|
|
122
|
+
|
|
123
|
+
| 语言 | URL |
|
|
124
|
+
|------|-----|
|
|
125
|
+
| 英文(默认) | `/posts` |
|
|
126
|
+
| 中文 | `/zh-CN/posts` |
|
|
127
|
+
|
|
128
|
+
当 `prefixDefaultLocale: true` 时:
|
|
129
|
+
|
|
130
|
+
| 语言 | URL |
|
|
131
|
+
|------|-----|
|
|
132
|
+
| 英文 | `/en/posts` |
|
|
133
|
+
| 中文 | `/zh-CN/posts` |
|
|
134
|
+
|
|
135
|
+
## 内容组织
|
|
136
|
+
|
|
137
|
+
### 方式 1:分开文件夹
|
|
138
|
+
|
|
139
|
+
为每种语言创建单独的内容文件夹:
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
content/posts/
|
|
143
|
+
├── blog_docs_en/ # 英文文档
|
|
144
|
+
│ └── ...
|
|
145
|
+
└── blog_docs_zh/ # 中文文档
|
|
146
|
+
└── ...
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### 方式 2:相同内容
|
|
150
|
+
|
|
151
|
+
使用语言感知的 frontmatter:
|
|
152
|
+
|
|
153
|
+
```yaml
|
|
154
|
+
---
|
|
155
|
+
title: Hello World
|
|
156
|
+
lang: en
|
|
157
|
+
---
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## 语言切换器
|
|
161
|
+
|
|
162
|
+
当配置多种语言时,语言切换器会自动出现在头部。
|
|
163
|
+
|
|
164
|
+
它显示:
|
|
165
|
+
- 当前语言标志/名称
|
|
166
|
+
- 包含所有语言的下拉菜单
|
|
167
|
+
- 链接到其他语言的相同页面
|
|
168
|
+
|
|
169
|
+
## 语言配置选项
|
|
170
|
+
|
|
171
|
+
### 语言定义
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
{
|
|
175
|
+
code: 'en', // URL 前缀
|
|
176
|
+
name: 'English', // 显示名称
|
|
177
|
+
htmlLang: 'en', // HTML lang 属性
|
|
178
|
+
dateLocale: 'en-US', // 日期格式化
|
|
179
|
+
direction: 'ltr', // 文本方向(ltr/rtl)
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### 语言独立配置
|
|
184
|
+
|
|
185
|
+
每种语言可以覆盖:
|
|
186
|
+
|
|
187
|
+
| 配置 | 用途 |
|
|
188
|
+
|------|------|
|
|
189
|
+
| `site` | 标题、描述、作者 |
|
|
190
|
+
| `menu` | 导航链接 |
|
|
191
|
+
| `footer` | 页脚链接和文本 |
|
|
192
|
+
| `sidebar` | 文档树分组 |
|
|
193
|
+
| `ui` | UI 翻译字符串 |
|
|
194
|
+
|
|
195
|
+
## UI 翻译
|
|
196
|
+
|
|
197
|
+
博客为英文和中文内置了 50+ 个 UI 字符串的翻译。你可以在语言的 `ui.ts` 文件中覆盖任何字符串。
|
|
198
|
+
|
|
199
|
+
### 创建 UI 翻译
|
|
200
|
+
|
|
201
|
+
**英文 (`en/ui.ts`):**
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
import type { UITranslations } from '@jet-w/astro-blog';
|
|
205
|
+
|
|
206
|
+
export const ui: Partial<UITranslations> = {
|
|
207
|
+
// 在这里覆盖任何 UI 字符串
|
|
208
|
+
browsePosts: 'Browse Posts',
|
|
209
|
+
aboutMe: 'About Me',
|
|
210
|
+
searchPlaceholder: 'Search articles...',
|
|
211
|
+
readMore: 'Continue reading',
|
|
212
|
+
};
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### 可用 UI 键
|
|
216
|
+
|
|
217
|
+
| 分类 | 键 |
|
|
218
|
+
|------|-----|
|
|
219
|
+
| 导航 | `home`, `blog`, `about`, `search` |
|
|
220
|
+
| 文章 | `posts`, `postList`, `noPostsFound`, `readMore`, `readingTime`, `minuteRead` |
|
|
221
|
+
| 标签与分类 | `tags`, `categories`, `allTags`, `allCategories`, `taggedWith`, `inCategory` |
|
|
222
|
+
| 归档 | `archives`, `postsInArchive` |
|
|
223
|
+
| 侧边栏 | `recentPosts`, `popularTags`, `friendLinks`, `documentTree` |
|
|
224
|
+
| 页脚 | `quickLinks`, `contact` |
|
|
225
|
+
| 搜索 | `searchPlaceholder`, `searchResults`, `noResults`, `searching`, `searchArticles`, `searchTips` 等 |
|
|
226
|
+
| Hero | `browsePosts`, `aboutMe` |
|
|
227
|
+
| 分页 | `previousPage`, `nextPage`, `page`, `of` |
|
|
228
|
+
| 文章 | `publishedOn`, `updatedOn`, `author`, `tableOfContents`, `relatedPosts`, `sharePost` |
|
|
229
|
+
| 其他 | `backToTop`, `copyCode`, `copied`, `expand`, `collapse`, `viewMode`, `sortBy`, `draft` |
|
|
230
|
+
| 幻灯片 | `slides`, `slidesList` |
|
|
231
|
+
| RSS | `rssFeed` |
|
|
232
|
+
|
|
233
|
+
::: tip 提示
|
|
234
|
+
你只需要覆盖想要自定义的字符串。库为所有字符串提供了合理的默认值。
|
|
235
|
+
:::
|
|
236
|
+
|
|
237
|
+
## 添加新语言
|
|
238
|
+
|
|
239
|
+
1. 添加到 `locales` 数组:
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
locales: [
|
|
243
|
+
{ code: 'en', name: 'English', htmlLang: 'en', dateLocale: 'en-US' },
|
|
244
|
+
{ code: 'zh-CN', name: '中文', htmlLang: 'zh-CN', dateLocale: 'zh-CN' },
|
|
245
|
+
{ code: 'ja', name: '日本語', htmlLang: 'ja', dateLocale: 'ja-JP' }, // 新增
|
|
246
|
+
],
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
2. 创建配置文件夹:
|
|
250
|
+
|
|
251
|
+
```
|
|
252
|
+
src/config/locales/ja/
|
|
253
|
+
├── index.ts
|
|
254
|
+
├── site.ts
|
|
255
|
+
├── menu.ts
|
|
256
|
+
├── footer.ts
|
|
257
|
+
├── sidebar.ts
|
|
258
|
+
└── ui.ts # UI 翻译
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
3. 创建带翻译的 `ui.ts`:
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
import type { UITranslations } from '@jet-w/astro-blog';
|
|
265
|
+
|
|
266
|
+
export const ui: Partial<UITranslations> = {
|
|
267
|
+
// 导航
|
|
268
|
+
home: 'ホーム',
|
|
269
|
+
posts: '記事',
|
|
270
|
+
tags: 'タグ',
|
|
271
|
+
categories: 'カテゴリー',
|
|
272
|
+
search: '検索',
|
|
273
|
+
|
|
274
|
+
// Hero 区域
|
|
275
|
+
browsePosts: '記事を見る',
|
|
276
|
+
aboutMe: '私について',
|
|
277
|
+
|
|
278
|
+
// 搜索
|
|
279
|
+
searchPlaceholder: '記事を検索...',
|
|
280
|
+
noResults: '結果が見つかりません',
|
|
281
|
+
|
|
282
|
+
// 根据需要添加更多翻译...
|
|
283
|
+
};
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
4. 创建 `index.ts`:
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
import { site } from './site';
|
|
290
|
+
import { menu } from './menu';
|
|
291
|
+
import { footer } from './footer';
|
|
292
|
+
import { sidebar } from './sidebar';
|
|
293
|
+
import { ui } from './ui';
|
|
294
|
+
|
|
295
|
+
export const jaConfig = {
|
|
296
|
+
site,
|
|
297
|
+
menu,
|
|
298
|
+
footer,
|
|
299
|
+
sidebar,
|
|
300
|
+
ui,
|
|
301
|
+
contentPathPrefix: 'blog_docs_ja',
|
|
302
|
+
};
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
5. 添加到 `astro.config.mjs` 的 `localeConfigs`:
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
import { jaConfig } from './src/config/locales/ja';
|
|
309
|
+
|
|
310
|
+
localeConfigs: {
|
|
311
|
+
'en': enConfig,
|
|
312
|
+
'zh-CN': zhCNConfig,
|
|
313
|
+
'ja': jaConfig, // 新增
|
|
314
|
+
},
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
## RTL 语言
|
|
318
|
+
|
|
319
|
+
对于从右到左的语言(阿拉伯语、希伯来语):
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
{
|
|
323
|
+
code: 'ar',
|
|
324
|
+
name: 'العربية',
|
|
325
|
+
htmlLang: 'ar',
|
|
326
|
+
dateLocale: 'ar-SA',
|
|
327
|
+
direction: 'rtl', // 启用 RTL
|
|
328
|
+
}
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
## 最佳实践
|
|
332
|
+
|
|
333
|
+
::: tip 多语言技巧
|
|
334
|
+
1. **从两种语言开始** - 不需要时不要添加更多
|
|
335
|
+
2. **保持内容同步** - 一起更新所有翻译
|
|
336
|
+
3. **使用一致的 URL** - 跨语言匹配 URL 结构
|
|
337
|
+
4. **彻底测试** - 检查所有语言的所有页面
|
|
338
|
+
:::
|
|
339
|
+
|
|
340
|
+
::: warning 路径一致性
|
|
341
|
+
更改 `defaultLocale` 时,更新所有菜单和页脚链接以匹配新的 URL 结构。
|
|
342
|
+
:::
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
恭喜!你已完成配置指南。
|
|
347
|
+
|
|
348
|
+
返回 [文档首页](../) 了解更多主题。
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 配置
|
|
3
|
+
description: 使用站点设置、侧边栏和多语言自定义你的博客
|
|
4
|
+
pubDate: 2025-01-01
|
|
5
|
+
author: jet-w
|
|
6
|
+
categories:
|
|
7
|
+
- 文档
|
|
8
|
+
tags:
|
|
9
|
+
- 配置
|
|
10
|
+
- 设置
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# 配置
|
|
14
|
+
|
|
15
|
+
通过配置文件自定义博客的各个方面。
|
|
16
|
+
|
|
17
|
+
## 配置文件
|
|
18
|
+
|
|
19
|
+
所有配置都在 `src/config/` 目录:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
src/config/
|
|
23
|
+
├── locales/ # 语言特定配置
|
|
24
|
+
│ ├── en/ # 英文
|
|
25
|
+
│ └── zh-CN/ # 中文
|
|
26
|
+
├── site.ts # 站点元数据
|
|
27
|
+
├── menu.ts # 导航菜单
|
|
28
|
+
├── sidebar.ts # 侧边栏设置
|
|
29
|
+
├── footer.ts # 页脚内容
|
|
30
|
+
└── social.ts # 社交链接
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 配置指南
|
|
34
|
+
|
|
35
|
+
| 指南 | 描述 |
|
|
36
|
+
|------|------|
|
|
37
|
+
| [站点设置](./01-site) | 标题、描述、作者信息 |
|
|
38
|
+
| [侧边栏](./02-sidebar) | 导航和文档树 |
|
|
39
|
+
| [多语言](./03-i18n) | 添加多语言支持 |
|
|
40
|
+
|
|
41
|
+
## 快速概览
|
|
42
|
+
|
|
43
|
+
### 站点配置
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
// src/config/site.ts
|
|
47
|
+
export const siteConfig = {
|
|
48
|
+
title: '我的博客',
|
|
49
|
+
description: '一个技术博客',
|
|
50
|
+
author: '你的名字',
|
|
51
|
+
avatar: '/images/avatar.jpg',
|
|
52
|
+
};
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 导航菜单
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
// src/config/locales/zh-CN/menu.ts
|
|
59
|
+
export const menu = [
|
|
60
|
+
{ name: '首页', href: '/', icon: 'home' },
|
|
61
|
+
{ name: '文章', href: '/posts', icon: 'posts' },
|
|
62
|
+
{ name: '关于', href: '/about', icon: 'about' },
|
|
63
|
+
];
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 多语言
|
|
67
|
+
|
|
68
|
+
```javascript
|
|
69
|
+
// astro.config.mjs
|
|
70
|
+
const i18nConfig = defineI18nConfig({
|
|
71
|
+
defaultLocale: 'en',
|
|
72
|
+
locales: [
|
|
73
|
+
{ code: 'en', name: 'English' },
|
|
74
|
+
{ code: 'zh-CN', name: '中文' },
|
|
75
|
+
],
|
|
76
|
+
localeConfigs: {
|
|
77
|
+
'en': enConfig,
|
|
78
|
+
'zh-CN': zhCNConfig,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
从 [站点设置](./01-site) 开始!
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Astro 博客文档
|
|
3
|
+
description: 一个基于 Astro、Vue 和 Tailwind CSS 构建的现代博客系统
|
|
4
|
+
pubDate: 2025-01-01
|
|
5
|
+
author: jet-w
|
|
6
|
+
categories:
|
|
7
|
+
- 文档
|
|
8
|
+
tags:
|
|
9
|
+
- Astro
|
|
10
|
+
- 指南
|
|
11
|
+
star: true
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
# Astro 博客
|
|
15
|
+
|
|
16
|
+
一个基于 **Astro**、**Vue 3** 和 **Tailwind CSS** 构建的现代化、功能丰富的博客系统。
|
|
17
|
+
|
|
18
|
+
::: tip 为什么选择这个博客?
|
|
19
|
+
- **快速** - 静态站点生成,页面加载近乎即时
|
|
20
|
+
- **现代** - 采用最新的 Web 技术构建
|
|
21
|
+
- **灵活** - 支持 Markdown、MDX 和丰富的组件
|
|
22
|
+
- **美观** - 简洁设计,支持深色模式
|
|
23
|
+
:::
|
|
24
|
+
|
|
25
|
+
## 快速入门
|
|
26
|
+
|
|
27
|
+
第一次使用 Astro 博客?从这里开始:
|
|
28
|
+
|
|
29
|
+
| 章节 | 描述 |
|
|
30
|
+
|------|------|
|
|
31
|
+
| [介绍](./01.get-started/) | 什么是 Astro 博客以及为什么要使用它 |
|
|
32
|
+
| [安装](./01.get-started/02-install) | 设置你的开发环境 |
|
|
33
|
+
| [第一篇文章](./01.get-started/03-create-post) | 创建并发布你的第一篇文章 |
|
|
34
|
+
| [项目结构](./01.get-started/04-structure) | 了解文件组织方式 |
|
|
35
|
+
| [部署](./01.get-started/05-deploy) | 构建并部署你的博客 |
|
|
36
|
+
|
|
37
|
+
## 写作指南
|
|
38
|
+
|
|
39
|
+
学习如何创作精美的内容:
|
|
40
|
+
|
|
41
|
+
| 指南 | 描述 |
|
|
42
|
+
|------|------|
|
|
43
|
+
| [Markdown 基础](./02.guide/) | 基本 Markdown 语法 |
|
|
44
|
+
| [容器](./02.guide/02-containers) | 提示框、警告框和标注 |
|
|
45
|
+
| [代码块](./02.guide/03-code-blocks) | 语法高亮及更多功能 |
|
|
46
|
+
| [图表](./02.guide/03-mermaid) | 使用 Mermaid 绘制流程图和图表 |
|
|
47
|
+
| [数学公式](./02.guide/06-latex) | LaTeX 数学公式渲染 |
|
|
48
|
+
| [视频嵌入](./02.guide/07-video) | 嵌入 YouTube、Bilibili 等视频 |
|
|
49
|
+
| [图标](./02.guide/04-icons) | 使用多个图标库的图标 |
|
|
50
|
+
|
|
51
|
+
## 配置
|
|
52
|
+
|
|
53
|
+
自定义你的博客:
|
|
54
|
+
|
|
55
|
+
| 配置 | 描述 |
|
|
56
|
+
|------|------|
|
|
57
|
+
| [站点设置](./03.config/01-site) | 标题、描述和元数据 |
|
|
58
|
+
| [侧边栏](./03.config/02-sidebar) | 导航和文档树 |
|
|
59
|
+
| [多语言](./03.config/03-i18n) | 添加多语言支持 |
|
|
60
|
+
|
|
61
|
+
## 快速开始
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# 安装依赖
|
|
65
|
+
npm install
|
|
66
|
+
|
|
67
|
+
# 启动开发服务器
|
|
68
|
+
npm run dev
|
|
69
|
+
|
|
70
|
+
# 构建生产版本
|
|
71
|
+
npm run build
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
然后访问 `http://localhost:4321` 查看你的博客!
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
准备好了吗?从 [介绍](./01.get-started/) 开始!
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-astro-blog",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "astro dev",
|
|
7
|
+
"start": "astro dev",
|
|
8
|
+
"build": "astro build",
|
|
9
|
+
"preview": "astro preview",
|
|
10
|
+
"astro": "astro"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@astrojs/mdx": "^4.3.12",
|
|
14
|
+
"@astrojs/rss": "^4.0.14",
|
|
15
|
+
"@astrojs/tailwind": "^5.1.3",
|
|
16
|
+
"@astrojs/vue": "^5.0.6",
|
|
17
|
+
"@jet-w/astro-blog": "file:../../",
|
|
18
|
+
"@tailwindcss/typography": "^0.5.15",
|
|
19
|
+
"astro": "^5.14.1",
|
|
20
|
+
"echarts": "^6.0.0",
|
|
21
|
+
"fuse.js": "^7.0.0",
|
|
22
|
+
"mermaid": "^11.12.2",
|
|
23
|
+
"rehype-katex": "^7.0.1",
|
|
24
|
+
"rehype-raw": "^7.0.0",
|
|
25
|
+
"remark-directive": "^4.0.0",
|
|
26
|
+
"remark-math": "^6.0.0",
|
|
27
|
+
"tailwindcss": "^3.4.17",
|
|
28
|
+
"typescript": "^5.7.2",
|
|
29
|
+
"vue": "^3.5.13"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -5,12 +5,16 @@ import { site } from './site';
|
|
|
5
5
|
import { menu } from './menu';
|
|
6
6
|
import { footer } from './footer';
|
|
7
7
|
import { sidebar } from './sidebar';
|
|
8
|
+
import { ui } from './ui';
|
|
8
9
|
|
|
9
10
|
export const enConfig = {
|
|
10
11
|
site,
|
|
11
12
|
menu,
|
|
12
13
|
footer,
|
|
13
14
|
sidebar,
|
|
15
|
+
ui,
|
|
16
|
+
// Content path prefix for filtering posts by locale
|
|
17
|
+
contentPathPrefix: 'blog_docs_en',
|
|
14
18
|
};
|
|
15
19
|
|
|
16
|
-
export { site, menu, footer, sidebar };
|
|
20
|
+
export { site, menu, footer, sidebar, ui };
|
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export const menu = [
|
|
8
8
|
{ name: 'Home', href: '/', icon: 'home' },
|
|
9
|
-
{ name: '
|
|
9
|
+
{ name: 'Get Started', href: '/posts/blog_docs_en/01.get-started', icon: 'posts' },
|
|
10
|
+
{ name: 'Guide', href: '/posts/blog_docs_en/02.guide', icon: 'posts' },
|
|
11
|
+
{ name: 'Config', href: '/posts/blog_docs_en/03.config', icon: 'posts' },
|
|
10
12
|
{ name: 'Slides', href: '/slides', icon: 'slides' },
|
|
11
13
|
{ name: 'About', href: '/about', icon: 'about' },
|
|
12
14
|
];
|
|
@@ -10,9 +10,25 @@ export const sidebar = {
|
|
|
10
10
|
type: 'scan' as const,
|
|
11
11
|
title: 'Documentation',
|
|
12
12
|
icon: 'ri:book-open-line',
|
|
13
|
-
scanPath: 'blog_docs_en',
|
|
13
|
+
scanPath: 'blog_docs_en/01.get-started',
|
|
14
14
|
collapsed: false,
|
|
15
|
-
showForPaths: ['/posts/blog_docs_en/**'],
|
|
15
|
+
showForPaths: ['/posts/blog_docs_en/01.get-started/**'],
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
type: 'scan' as const,
|
|
19
|
+
title: 'Documentation',
|
|
20
|
+
icon: 'ri:book-open-line',
|
|
21
|
+
scanPath: 'blog_docs_en/02.guide',
|
|
22
|
+
collapsed: false,
|
|
23
|
+
showForPaths: ['/posts/blog_docs_en/02.guide/**'],
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
type: 'scan' as const,
|
|
27
|
+
title: 'Documentation',
|
|
28
|
+
icon: 'ri:book-open-line',
|
|
29
|
+
scanPath: 'blog_docs_en/03.config',
|
|
30
|
+
collapsed: false,
|
|
31
|
+
showForPaths: ['/posts/blog_docs_en/03.config/**'],
|
|
16
32
|
},
|
|
17
33
|
],
|
|
18
34
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* English UI translations
|
|
3
|
+
*
|
|
4
|
+
* Override any UI strings here. The library provides default English translations,
|
|
5
|
+
* so you only need to add strings you want to customize.
|
|
6
|
+
*
|
|
7
|
+
* See UITranslations interface for all available keys:
|
|
8
|
+
* - Navigation: home, blog, about, search
|
|
9
|
+
* - Posts: posts, postList, noPostsFound, readMore, readingTime, minuteRead
|
|
10
|
+
* - Tags & Categories: tags, categories, allTags, allCategories, taggedWith, inCategory
|
|
11
|
+
* - Archives: archives, postsInArchive
|
|
12
|
+
* - Sidebar: recentPosts, popularTags, friendLinks, documentTree
|
|
13
|
+
* - Footer: quickLinks, contact
|
|
14
|
+
* - Search: searchPlaceholder, searchResults, noResults, searching, searchArticles, etc.
|
|
15
|
+
* - Hero: browsePosts, aboutMe
|
|
16
|
+
* - Pagination: previousPage, nextPage, page, of
|
|
17
|
+
* - Article: publishedOn, updatedOn, author, tableOfContents, relatedPosts, etc.
|
|
18
|
+
* - Misc: backToTop, copyCode, copied, expand, collapse, viewMode, sortBy, etc.
|
|
19
|
+
* - Slides: slides, slidesList
|
|
20
|
+
* - RSS: rssFeed
|
|
21
|
+
*/
|
|
22
|
+
import type { UITranslations } from '@jet-w/astro-blog';
|
|
23
|
+
|
|
24
|
+
export const ui: Partial<UITranslations> = {
|
|
25
|
+
// Example overrides:
|
|
26
|
+
// browsePosts: 'Browse Posts',
|
|
27
|
+
// aboutMe: 'About Me',
|
|
28
|
+
// searchPlaceholder: 'Search articles...',
|
|
29
|
+
};
|
|
@@ -5,12 +5,16 @@ import { site } from './site';
|
|
|
5
5
|
import { menu } from './menu';
|
|
6
6
|
import { footer } from './footer';
|
|
7
7
|
import { sidebar } from './sidebar';
|
|
8
|
+
import { ui } from './ui';
|
|
8
9
|
|
|
9
10
|
export const zhCNConfig = {
|
|
10
11
|
site,
|
|
11
12
|
menu,
|
|
12
13
|
footer,
|
|
13
14
|
sidebar,
|
|
15
|
+
ui,
|
|
16
|
+
// 内容路径前缀,用于按语言过滤文章
|
|
17
|
+
contentPathPrefix: 'blog_docs_zh',
|
|
14
18
|
};
|
|
15
19
|
|
|
16
|
-
export { site, menu, footer, sidebar };
|
|
20
|
+
export { site, menu, footer, sidebar, ui };
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 中文导航菜单配置
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* 当英文是默认语言且 prefixDefaultLocale: false 时,
|
|
5
|
+
* 中文路径需要包含 /zh-CN/ 前缀
|
|
6
6
|
*/
|
|
7
7
|
export const menu = [
|
|
8
|
-
{ name: '
|
|
9
|
-
{ name: '
|
|
10
|
-
{ name: '
|
|
8
|
+
{ name: '主页', href: '/zh-CN/', icon: 'home' },
|
|
9
|
+
{ name: '开始使用', href: '/zh-CN/posts/blog_docs_zh/01.get-started', icon: 'posts' },
|
|
10
|
+
{ name: '指南', href: '/zh-CN/posts/blog_docs_zh/02.guide', icon: 'posts' },
|
|
11
|
+
{ name: '配置', href: '/zh-CN/posts/blog_docs_zh/03.config', icon: 'posts' },
|
|
12
|
+
{ name: '幻灯片', href: '/zh-CN/slides', icon: 'slides' },
|
|
11
13
|
{ name: '关于', href: '/zh-CN/about', icon: 'about' },
|
|
12
14
|
];
|