@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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: Multi-language Support
|
|
3
3
|
description: Add multiple language support to your blog
|
|
4
4
|
pubDate: 2025-01-01
|
|
5
|
-
author:
|
|
5
|
+
author: jet-w
|
|
6
6
|
categories:
|
|
7
7
|
- Documentation
|
|
8
8
|
tags:
|
|
@@ -66,13 +66,15 @@ src/config/locales/
|
|
|
66
66
|
│ ├── site.ts
|
|
67
67
|
│ ├── menu.ts
|
|
68
68
|
│ ├── footer.ts
|
|
69
|
-
│
|
|
69
|
+
│ ├── sidebar.ts
|
|
70
|
+
│ └── ui.ts # UI translations
|
|
70
71
|
└── zh-CN/
|
|
71
72
|
├── index.ts
|
|
72
73
|
├── site.ts
|
|
73
74
|
├── menu.ts
|
|
74
75
|
├── footer.ts
|
|
75
|
-
|
|
76
|
+
├── sidebar.ts
|
|
77
|
+
└── ui.ts # UI translations
|
|
76
78
|
```
|
|
77
79
|
|
|
78
80
|
### 3. Configure Each Language
|
|
@@ -84,12 +86,14 @@ import { site } from './site';
|
|
|
84
86
|
import { menu } from './menu';
|
|
85
87
|
import { footer } from './footer';
|
|
86
88
|
import { sidebar } from './sidebar';
|
|
89
|
+
import { ui } from './ui';
|
|
87
90
|
|
|
88
91
|
export const enConfig = {
|
|
89
92
|
site,
|
|
90
93
|
menu,
|
|
91
94
|
footer,
|
|
92
95
|
sidebar,
|
|
96
|
+
ui,
|
|
93
97
|
};
|
|
94
98
|
```
|
|
95
99
|
|
|
@@ -190,32 +194,47 @@ Each locale can override:
|
|
|
190
194
|
|
|
191
195
|
## UI Translations
|
|
192
196
|
|
|
193
|
-
|
|
197
|
+
The blog includes built-in translations for 50+ UI strings in English and Chinese. You can override any string in your locale's `ui.ts` file.
|
|
194
198
|
|
|
195
|
-
|
|
196
|
-
// Already included for en and zh-CN
|
|
197
|
-
const translations = {
|
|
198
|
-
home: 'Home',
|
|
199
|
-
posts: 'Posts',
|
|
200
|
-
tags: 'Tags',
|
|
201
|
-
readMore: 'Read more',
|
|
202
|
-
// ... 50+ strings
|
|
203
|
-
};
|
|
204
|
-
```
|
|
199
|
+
### Creating UI Translations
|
|
205
200
|
|
|
206
|
-
|
|
201
|
+
**English (`en/ui.ts`):**
|
|
207
202
|
|
|
208
203
|
```typescript
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
204
|
+
import type { UITranslations } from '@jet-w/astro-blog';
|
|
205
|
+
|
|
206
|
+
export const ui: Partial<UITranslations> = {
|
|
207
|
+
// Override any UI strings here
|
|
208
|
+
browsePosts: 'Browse Posts',
|
|
209
|
+
aboutMe: 'About Me',
|
|
210
|
+
searchPlaceholder: 'Search articles...',
|
|
211
|
+
readMore: 'Continue reading',
|
|
216
212
|
};
|
|
217
213
|
```
|
|
218
214
|
|
|
215
|
+
### Available UI Keys
|
|
216
|
+
|
|
217
|
+
| Category | Keys |
|
|
218
|
+
|----------|------|
|
|
219
|
+
| Navigation | `home`, `blog`, `about`, `search` |
|
|
220
|
+
| Posts | `posts`, `postList`, `noPostsFound`, `readMore`, `readingTime`, `minuteRead` |
|
|
221
|
+
| Tags & Categories | `tags`, `categories`, `allTags`, `allCategories`, `taggedWith`, `inCategory` |
|
|
222
|
+
| Archives | `archives`, `postsInArchive` |
|
|
223
|
+
| Sidebar | `recentPosts`, `popularTags`, `friendLinks`, `documentTree` |
|
|
224
|
+
| Footer | `quickLinks`, `contact` |
|
|
225
|
+
| Search | `searchPlaceholder`, `searchResults`, `noResults`, `searching`, `searchArticles`, `searchTips`, etc. |
|
|
226
|
+
| Hero | `browsePosts`, `aboutMe` |
|
|
227
|
+
| Pagination | `previousPage`, `nextPage`, `page`, `of` |
|
|
228
|
+
| Article | `publishedOn`, `updatedOn`, `author`, `tableOfContents`, `relatedPosts`, `sharePost` |
|
|
229
|
+
| Misc | `backToTop`, `copyCode`, `copied`, `expand`, `collapse`, `viewMode`, `sortBy`, `draft` |
|
|
230
|
+
| Slides | `slides`, `slidesList` |
|
|
231
|
+
| RSS | `rssFeed` |
|
|
232
|
+
|
|
233
|
+
::: tip Tip
|
|
234
|
+
|
|
235
|
+
You only need to override strings you want to customize. The library provides sensible defaults for all strings.
|
|
236
|
+
:::
|
|
237
|
+
|
|
219
238
|
## Adding a New Language
|
|
220
239
|
|
|
221
240
|
1. Add to `locales` array:
|
|
@@ -236,10 +255,55 @@ src/config/locales/ja/
|
|
|
236
255
|
├── site.ts
|
|
237
256
|
├── menu.ts
|
|
238
257
|
├── footer.ts
|
|
239
|
-
|
|
258
|
+
├── sidebar.ts
|
|
259
|
+
└── ui.ts # UI translations
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
3. Create `ui.ts` with translations:
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
import type { UITranslations } from '@jet-w/astro-blog';
|
|
266
|
+
|
|
267
|
+
export const ui: Partial<UITranslations> = {
|
|
268
|
+
// Navigation
|
|
269
|
+
home: 'ホーム',
|
|
270
|
+
posts: '記事',
|
|
271
|
+
tags: 'タグ',
|
|
272
|
+
categories: 'カテゴリー',
|
|
273
|
+
search: '検索',
|
|
274
|
+
|
|
275
|
+
// Hero section
|
|
276
|
+
browsePosts: '記事を見る',
|
|
277
|
+
aboutMe: '私について',
|
|
278
|
+
|
|
279
|
+
// Search
|
|
280
|
+
searchPlaceholder: '記事を検索...',
|
|
281
|
+
noResults: '結果が見つかりません',
|
|
282
|
+
|
|
283
|
+
// Add more translations as needed...
|
|
284
|
+
};
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
4. Create `index.ts`:
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
import { site } from './site';
|
|
291
|
+
import { menu } from './menu';
|
|
292
|
+
import { footer } from './footer';
|
|
293
|
+
import { sidebar } from './sidebar';
|
|
294
|
+
import { ui } from './ui';
|
|
295
|
+
|
|
296
|
+
export const jaConfig = {
|
|
297
|
+
site,
|
|
298
|
+
menu,
|
|
299
|
+
footer,
|
|
300
|
+
sidebar,
|
|
301
|
+
ui,
|
|
302
|
+
contentPathPrefix: 'blog_docs_ja',
|
|
303
|
+
};
|
|
240
304
|
```
|
|
241
305
|
|
|
242
|
-
|
|
306
|
+
5. Add to `localeConfigs` in `astro.config.mjs`:
|
|
243
307
|
|
|
244
308
|
```typescript
|
|
245
309
|
import { jaConfig } from './src/config/locales/ja';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: Astro Blog Documentation
|
|
3
3
|
description: A modern blog system built with Astro, Vue, and Tailwind CSS
|
|
4
4
|
pubDate: 2025-01-01
|
|
5
|
-
author:
|
|
5
|
+
author: jet-w
|
|
6
6
|
categories:
|
|
7
7
|
- Documentation
|
|
8
8
|
tags:
|
|
@@ -20,6 +20,7 @@ A modern, feature-rich blog system built with **Astro**, **Vue 3**, and **Tailwi
|
|
|
20
20
|
- **Modern** - Built with the latest web technologies
|
|
21
21
|
- **Flexible** - Markdown, MDX, and rich component support
|
|
22
22
|
- **Beautiful** - Clean design with dark mode support
|
|
23
|
+
|
|
23
24
|
:::
|
|
24
25
|
|
|
25
26
|
## Get Started
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 介绍
|
|
3
|
+
description: 什么是 Astro 博客?为什么要使用它?
|
|
4
|
+
pubDate: 2025-01-01
|
|
5
|
+
author: jet-w
|
|
6
|
+
categories:
|
|
7
|
+
- 文档
|
|
8
|
+
tags:
|
|
9
|
+
- 入门
|
|
10
|
+
- 介绍
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# 介绍
|
|
14
|
+
|
|
15
|
+
Astro 博客是一个为开发者和内容创作者打造的**现代博客系统**,提供快速、美观且功能丰富的写作体验。
|
|
16
|
+
|
|
17
|
+
## 什么是 Astro 博客?
|
|
18
|
+
|
|
19
|
+
Astro 博客基于 [Astro](https://astro.build) 构建,这是一个现代静态站点生成器。它结合了:
|
|
20
|
+
|
|
21
|
+
- **Astro** - 闪电般快速的静态站点生成
|
|
22
|
+
- **Vue 3** - 用于交互组件
|
|
23
|
+
- **Tailwind CSS** - 美观、响应式的样式
|
|
24
|
+
|
|
25
|
+
::: tip 静态站点生成
|
|
26
|
+
你的博客被预先构建为静态 HTML 文件,这意味着:
|
|
27
|
+
- **即时页面加载** - 无需服务器处理
|
|
28
|
+
- **更好的 SEO** - 搜索引擎喜欢静态内容
|
|
29
|
+
- **易于托管** - 可部署到任何地方(Vercel、Netlify、GitHub Pages)
|
|
30
|
+
:::
|
|
31
|
+
|
|
32
|
+
## 核心特性
|
|
33
|
+
|
|
34
|
+
### 写作功能
|
|
35
|
+
|
|
36
|
+
| 特性 | 描述 |
|
|
37
|
+
|------|------|
|
|
38
|
+
| Markdown/MDX | 使用 Markdown 写作,支持组件 |
|
|
39
|
+
| 代码高亮 | 100+ 种语言的精美语法高亮 |
|
|
40
|
+
| 数学公式 | 使用 KaTeX 渲染 LaTeX 数学公式 |
|
|
41
|
+
| 图表 | 使用 Mermaid 绘制流程图和图表 |
|
|
42
|
+
| 容器 | 标注、提示、警告等 |
|
|
43
|
+
| 视频 | 嵌入 YouTube、Bilibili 或自托管视频 |
|
|
44
|
+
|
|
45
|
+
### 系统功能
|
|
46
|
+
|
|
47
|
+
| 特性 | 描述 |
|
|
48
|
+
|------|------|
|
|
49
|
+
| 深色模式 | 切换浅色和深色主题 |
|
|
50
|
+
| 响应式 | 完美适配桌面、平板和手机 |
|
|
51
|
+
| 搜索 | 全文搜索所有文章 |
|
|
52
|
+
| RSS 订阅 | 自动生成 RSS 供订阅者使用 |
|
|
53
|
+
| SEO | 优化的 meta 标签和站点地图 |
|
|
54
|
+
| 多语言 | 多语言支持 |
|
|
55
|
+
|
|
56
|
+
## 何时使用 Astro 博客?
|
|
57
|
+
|
|
58
|
+
Astro 博客非常适合:
|
|
59
|
+
|
|
60
|
+
::: info 适用场景
|
|
61
|
+
- **技术博客** - 分享教程和技术知识
|
|
62
|
+
- **个人博客** - 记录你的旅程和想法
|
|
63
|
+
- **文档站点** - 创建产品或项目文档
|
|
64
|
+
- **作品集** - 展示你的作品
|
|
65
|
+
:::
|
|
66
|
+
|
|
67
|
+
## 技术栈
|
|
68
|
+
|
|
69
|
+
::: details 查看完整技术栈
|
|
70
|
+
- **框架**: [Astro](https://astro.build) v5.x
|
|
71
|
+
- **UI 组件**: [Vue 3](https://vuejs.org)
|
|
72
|
+
- **样式**: [Tailwind CSS](https://tailwindcss.com) v4.x
|
|
73
|
+
- **代码高亮**: [Shiki](https://shiki.style)
|
|
74
|
+
- **数学**: [KaTeX](https://katex.org)
|
|
75
|
+
- **图表**: [Mermaid](https://mermaid.js.org)
|
|
76
|
+
- **图标**: Font Awesome、Material Icons、Remix Icon、Bootstrap Icons
|
|
77
|
+
:::
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
准备好设置你的博客了吗?继续阅读 [安装](./02-install)。
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 安装
|
|
3
|
+
description: 设置你的开发环境并安装 Astro 博客
|
|
4
|
+
pubDate: 2025-01-01
|
|
5
|
+
author: jet-w
|
|
6
|
+
categories:
|
|
7
|
+
- 文档
|
|
8
|
+
tags:
|
|
9
|
+
- 入门
|
|
10
|
+
- 安装
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# 安装
|
|
14
|
+
|
|
15
|
+
本指南将帮助你在电脑上设置 Astro 博客。
|
|
16
|
+
|
|
17
|
+
## 前置要求
|
|
18
|
+
|
|
19
|
+
在开始之前,请确保你已具备:
|
|
20
|
+
|
|
21
|
+
### Node.js
|
|
22
|
+
|
|
23
|
+
需要 Node.js 18.x 或更高版本。
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# 检查你的 Node.js 版本
|
|
27
|
+
node --version
|
|
28
|
+
# 应该输出:v18.x.x 或更高
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
::: tip 安装 Node.js
|
|
32
|
+
如果你没有 Node.js,请从 [nodejs.org](https://nodejs.org) 下载。
|
|
33
|
+
选择 **LTS** 版本以获得最佳稳定性。
|
|
34
|
+
:::
|
|
35
|
+
|
|
36
|
+
### 包管理器
|
|
37
|
+
|
|
38
|
+
npm 随 Node.js 一起安装。你也可以使用 pnpm 或 yarn:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# 检查 npm 版本
|
|
42
|
+
npm --version
|
|
43
|
+
|
|
44
|
+
# 或使用 pnpm(推荐,安装更快)
|
|
45
|
+
npm install -g pnpm
|
|
46
|
+
pnpm --version
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## 安装依赖
|
|
50
|
+
|
|
51
|
+
进入你的博客项目文件夹并安装依赖:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# 使用 npm
|
|
55
|
+
npm install
|
|
56
|
+
|
|
57
|
+
# 或使用 pnpm
|
|
58
|
+
pnpm install
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
这将安装 `package.json` 中定义的所有必需包。
|
|
62
|
+
|
|
63
|
+
## 启动开发服务器
|
|
64
|
+
|
|
65
|
+
启动本地开发服务器:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
# 使用 npm
|
|
69
|
+
npm run dev
|
|
70
|
+
|
|
71
|
+
# 或使用 pnpm
|
|
72
|
+
pnpm dev
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
你应该看到类似这样的输出:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
🚀 astro v5.x.x ready in 1234ms
|
|
79
|
+
|
|
80
|
+
┃ Local http://localhost:4321/
|
|
81
|
+
┃ Network use --host to expose
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
::: tip 热重载
|
|
85
|
+
开发服务器支持热重载。当你保存文件时,浏览器会自动刷新以显示你的更改。
|
|
86
|
+
:::
|
|
87
|
+
|
|
88
|
+
## 在浏览器中打开
|
|
89
|
+
|
|
90
|
+
在浏览器中访问 `http://localhost:4321`。你应该能看到你的博客首页!
|
|
91
|
+
|
|
92
|
+
## 验证安装
|
|
93
|
+
|
|
94
|
+
检查一切是否正常工作:
|
|
95
|
+
|
|
96
|
+
1. **首页加载** - 你看到博客首页
|
|
97
|
+
2. **文章列表** - 导航到 `/posts` 查看文章
|
|
98
|
+
3. **深色模式** - 切换顶部的主题开关
|
|
99
|
+
4. **搜索** - 尝试搜索功能
|
|
100
|
+
|
|
101
|
+
## 常见问题
|
|
102
|
+
|
|
103
|
+
### 端口已被占用
|
|
104
|
+
|
|
105
|
+
如果端口 4321 被占用,Astro 会使用其他端口。检查终端输出获取实际 URL。
|
|
106
|
+
|
|
107
|
+
或者指定不同的端口:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
npm run dev -- --port 3000
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 依赖安装失败
|
|
114
|
+
|
|
115
|
+
尝试清除缓存:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
# 删除 node_modules 和 lock 文件
|
|
119
|
+
rm -rf node_modules package-lock.json
|
|
120
|
+
|
|
121
|
+
# 重新安装
|
|
122
|
+
npm install
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Node.js 版本过旧
|
|
126
|
+
|
|
127
|
+
将 Node.js 更新到 18 或更高版本。考虑使用 [nvm](https://github.com/nvm-sh/nvm) 来管理 Node 版本:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
# 安装 nvm 后:
|
|
131
|
+
nvm install 20
|
|
132
|
+
nvm use 20
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
开发服务器运行起来了吗?太好了!让我们 [创建你的第一篇文章](./03-create-post)。
|
|
@@ -0,0 +1,176 @@
|
|
|
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
|
+
所有博客文章都放在 `content/posts/` 目录:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
content/
|
|
23
|
+
└── posts/
|
|
24
|
+
├── my-first-post.md ← 你的文章放在这里
|
|
25
|
+
├── another-post.md
|
|
26
|
+
└── tech/ ← 或者放在子目录中
|
|
27
|
+
└── tutorial.md
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## 创建新文章
|
|
31
|
+
|
|
32
|
+
在 `content/posts/` 中创建一个名为 `hello-world.md` 的文件:
|
|
33
|
+
|
|
34
|
+
```markdown
|
|
35
|
+
---
|
|
36
|
+
title: Hello World
|
|
37
|
+
description: 我的第一篇博客文章
|
|
38
|
+
pubDate: 2025-01-15
|
|
39
|
+
author: 你的名字
|
|
40
|
+
tags:
|
|
41
|
+
- 介绍
|
|
42
|
+
categories:
|
|
43
|
+
- 个人
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
# Hello World
|
|
47
|
+
|
|
48
|
+
欢迎来到我的博客!这是我的第一篇文章。
|
|
49
|
+
|
|
50
|
+
## 我为什么开始写博客
|
|
51
|
+
|
|
52
|
+
我开始写这个博客是为了:
|
|
53
|
+
|
|
54
|
+
1. 分享我学到的东西
|
|
55
|
+
2. 记录我的旅程
|
|
56
|
+
3. 与他人建立联系
|
|
57
|
+
|
|
58
|
+
> 最好的开始时间是昨天,其次是现在。
|
|
59
|
+
|
|
60
|
+
## 接下来
|
|
61
|
+
|
|
62
|
+
敬请期待更多关于以下内容的文章:
|
|
63
|
+
|
|
64
|
+
- Web 开发
|
|
65
|
+
- 我的项目
|
|
66
|
+
- 经验教训
|
|
67
|
+
|
|
68
|
+
感谢阅读!
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## 查看你的文章
|
|
72
|
+
|
|
73
|
+
保存文件后访问:
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
http://localhost:4321/posts/hello-world
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
你的文章应该会以完整的样式呈现!
|
|
80
|
+
|
|
81
|
+
## 理解 Frontmatter
|
|
82
|
+
|
|
83
|
+
`---` 标记之间的部分称为 **frontmatter**。它包含文章的元数据:
|
|
84
|
+
|
|
85
|
+
```yaml
|
|
86
|
+
---
|
|
87
|
+
title: Hello World # 必填 - 文章标题
|
|
88
|
+
description: 我的第一篇文章 # 用于 SEO 和预览
|
|
89
|
+
pubDate: 2025-01-15 # 发布日期
|
|
90
|
+
author: 你的名字 # 作者名称
|
|
91
|
+
tags: # 标签(数组)
|
|
92
|
+
- 介绍
|
|
93
|
+
categories: # 分类(数组)
|
|
94
|
+
- 个人
|
|
95
|
+
draft: false # true = 从列表中隐藏
|
|
96
|
+
star: false # true = 精选文章
|
|
97
|
+
---
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
::: tip 必填与可选
|
|
101
|
+
只有 `title` 是必填的。其他字段都是可选的,但建议填写以便更好地组织和优化 SEO。
|
|
102
|
+
:::
|
|
103
|
+
|
|
104
|
+
## 使用子目录
|
|
105
|
+
|
|
106
|
+
使用子目录来组织相关文章:
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
content/posts/
|
|
110
|
+
├── tutorials/
|
|
111
|
+
│ ├── README.md ← 显示在 /posts/tutorials
|
|
112
|
+
│ ├── javascript.md ← 显示在 /posts/tutorials/javascript
|
|
113
|
+
│ └── css.md ← 显示在 /posts/tutorials/css
|
|
114
|
+
└── projects/
|
|
115
|
+
└── my-app.md ← 显示在 /posts/projects/my-app
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 目录 README
|
|
119
|
+
|
|
120
|
+
每个目录可以有一个 `README.md` 作为该目录的索引页面:
|
|
121
|
+
|
|
122
|
+
```markdown
|
|
123
|
+
---
|
|
124
|
+
title: 教程
|
|
125
|
+
description: 一步步学习 Web 开发
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
# 教程
|
|
129
|
+
|
|
130
|
+
欢迎来到我的教程专区!
|
|
131
|
+
|
|
132
|
+
- [JavaScript 基础](./javascript)
|
|
133
|
+
- [CSS 技巧](./css)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## URL 路径规则
|
|
137
|
+
|
|
138
|
+
你的文件路径决定了 URL:
|
|
139
|
+
|
|
140
|
+
| 文件路径 | URL |
|
|
141
|
+
|----------|-----|
|
|
142
|
+
| `posts/hello.md` | `/posts/hello` |
|
|
143
|
+
| `posts/tech/intro.md` | `/posts/tech/intro` |
|
|
144
|
+
| `posts/tech/README.md` | `/posts/tech` |
|
|
145
|
+
|
|
146
|
+
::: info 大小写不敏感
|
|
147
|
+
URL 会自动转为小写。`Hello-World.md` 变成 `/posts/hello-world`。
|
|
148
|
+
:::
|
|
149
|
+
|
|
150
|
+
## 添加图片
|
|
151
|
+
|
|
152
|
+
将图片放在 `public/images/` 目录并引用:
|
|
153
|
+
|
|
154
|
+
```markdown
|
|
155
|
+

|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
对于文章专用的图片,你可以创建一个文件夹:
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
public/
|
|
162
|
+
└── images/
|
|
163
|
+
└── posts/
|
|
164
|
+
└── hello-world/
|
|
165
|
+
└── cover.jpg
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
然后使用:
|
|
169
|
+
|
|
170
|
+
```markdown
|
|
171
|
+

|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
恭喜你发布了第一篇文章!接下来,让我们了解 [项目结构](./04-structure)。
|