Skip to content

Commit

Permalink
📃 docs: 文档更新
Browse files Browse the repository at this point in the history
  • Loading branch information
白云苍狗 committed Aug 24, 2024
1 parent 0f35de3 commit 81bfff6
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 29 deletions.
40 changes: 40 additions & 0 deletions docs/.vitepress/assets/log.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,46 @@
{
"large_version": "v0.0.x",
"children": [
{
"version": "0.0.12",
"date": "2024-08-24",
"logs": [
{
"type": "feat",
"text": "数据加载自动获取 srcDir 目录"
},
{
"type": "feat",
"text": "404 自定义文案"
},
{
"type": "docs",
"text": "文档完善"
}
]
},
{
"version": "0.0.11",
"date": "2024-08-24",
"logs": [
{
"type": "feat",
"text": "支持时间轴样式配置"
},
{
"type": "feat",
"text": "首页分类卡片配置"
},
{
"type": "fix",
"text": "文章路径兼容 rewrites 设置"
},
{
"type": "fix",
"text": "gray-matter 类型错误导致 excerpt 截取失效"
}
]
},
{
"version": "0.0.10",
"date": "2024-08-22",
Expand Down
14 changes: 11 additions & 3 deletions docs/guide/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default defineConfig({

::: warning 注意

vitepress 中存在根目录和源目录,默认情况下两者是相等的,如果您对 `srcDir` 进行了修改,则也同时需要对 `postDir` 进行修改。
~~vitepress 中存在根目录和源目录,默认情况下两者是相等的,如果您对 `srcDir` 进行了修改,则也同时需要对 `postDir` 进行修改。~~ v0.0.12 后版本数据加载自动获取 srcDir 目录进行同步

了解根目录和源目录的区别 [请看这里](https://vitepress.dev/guide/routing#root-and-source-directory)

Expand Down Expand Up @@ -50,6 +50,12 @@ export default defineConfig({
rewritePost: true // [!code ++]
},
});
//等效于
export default defineConfig({
rewrites: {
'posts/(.*)': '(.*)' // [!code ++]
},
});
```

```[生成路径]
Expand Down Expand Up @@ -546,9 +552,11 @@ globalComponents?: boolean | Array<string>;

主题内置 css 变量参考 `vitepress-theme-async/styles/_variables/index.less` 文件

::: details vitepress-theme-async/styles/\_variables/index.less
<<< @/../packages/vitepress-theme-async/styles/\_variables/index.less#NoticeOutdateConfig
<!-- prettier-ignore-start -->
::: details vitepress-theme-async/styles/_variables/index.less
<<< @/../packages/vitepress-theme-async/styles/_variables/index.less
:::
<!-- prettier-ignore-end -->

## 自定义组件

Expand Down
105 changes: 94 additions & 11 deletions docs/guide/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

检查安装主题版本,然后查看更新日志里是否发生变更,参考文档配置说明,确保配置正确。

## 目录结构如何选择
## 目录结构是怎么的

### 单仓库

如果仅仅是单个博客站点,可以将 `srcDir` 设置为根目录
如果仅仅是单个博客站点,目录结构应该是下面样子的

::: code-group

Expand Down Expand Up @@ -62,21 +62,21 @@ npm create async-theme@latest my-first-blog

### 多仓库

当然你也可以选择多个包的 monorepo 结构
如果是 monorepo 结构,目录结构应该是下面样子的

::: code-group

```[目录结构]
.
├─ .vitepress
├─ blog
│ ├─ posts
│ │ ├─ test.md
│ │ ├─ demo.md
│ │ └─ ...
│ ├─ about.md
│ ├─ index.md
│ ├─ ...
│ ├─ .vitepress
│ ├─ posts
│ │ ├─ test.md
│ │ ├─ demo.md
│ │ └─ ...
│ ├─ about.md
│ ├─ index.md
│ ├─ ...
├─ other
│ ├─ ...
```
Expand All @@ -92,3 +92,86 @@ npm create async-theme@latest my-first-blog
```

:::

## hexo-theme-async 如何迁移?

### 文件和配置迁移

- 首先可以修改配置 `postDir` 改为 `_posts`

```ts
export default defineConfig({
themeConfig: {
postDir: '_posts', //[!code ++]
},
});
```

- 然后将 hexo 里 `source` 里文件都复制到你的 vitpress 目录下

```
.
├─ .vitepress
├─ _posts
│ ├─ test.md
│ ├─ demo.md
│ └─ ...
├─ about
│ ├─ index.md
├─ img
│ ├─ xxx.png
├─ ...
```

- 去除 \_data、\_drafts 等文件夹

- 在源目录下新建 public 文件,将静态文件如 图片、脚本、字体文件等等放到里面

```
.
├─ .vitepress
├─ _posts
│ ├─ test.md
│ ├─ demo.md
│ └─ ...
├─ about
│ ├─ index.md
├─ img // [!code --]
│ ├─ xxx.png // [!code --]
├─ public // [!code ++]
│ ├─ img // [!code ++]
│ ├─ xxx.png // [!code ++]
├─ ...
```

- 找到配置文件 \_config.async.yaml 然后转成 json 格式后,将其放置 themeConfig 里

将所有的 key 格式从 xxx_xx 改为 xxxXx 格式后,就可以根据 ts 错误提示对字段进行修改

如果是没有字段进行补充,如果是提示多余字段,可以在文档搜索下确认没有情况下删除

```ts
export default defineConfig({
themeConfig: {
postDir: '_posts',
user: { // [!code ++]
name: "ThemeAsync", // [!code ++]
first_name: "Theme", // [!code ++]
last_name: "Async", // [!code ++]
email: null, // [!code ++]
domain: "站点域名", // [!code ++]
avatar: "/img/avatar.jpg", // [!code ++]
describe: "网站简介。", // [!code ++]
rule_text: null // [!code ++]
} // [!code ++]
... // 更多配置 // [!code ++]
},
});
```

### 文件内容

- 如果原来文章里使用了 hexo tag,需要对其进行修改

- 文章里使用了 script、style 等语句块的需要对其 vitepress 里 [\<script> 和 \<style>](https://vitepress.dev/zh/guide/using-vue#script-and-style)
规则进行调整
31 changes: 21 additions & 10 deletions docs/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ npm i vitepress-theme-async@latest

- 使用 Npm 安装方式

`.vitepress/config.ts` 增加如下代码
在如下文件下添加对应代码

```ts
::: code-group

```ts [.vitepress/config.ts]
import { defineConfig } from "vitepress-theme-async/config";

export default defineConfig({
Expand All @@ -79,21 +81,21 @@ export default defineConfig({
});
```

然后再 `.vitepress/theme/index.ts` 添加如下代码

```ts
```ts [.vitepress/theme/index.ts]
import ThemeAsync from "vitepress-theme-async";

export default {
...ThemeAsync,
};
export default ThemeAsync;
```

:::

- 复制到本地方式

如果您是将文件复制到本地,将 `.vitepress/config.ts` 改为:
如果您是将文件复制到本地,修改如下:

::: code-group

```ts
```ts [.vitepress/config.ts]
import { defineConfig } from "vitepress-theme-async/config"; // [!code --]
import { defineConfig } from "./theme/config"; // [!code ++]

Expand All @@ -104,6 +106,15 @@ export default defineConfig({
});
```

```ts [.vitepress/theme/index.ts]
import ThemeAsync from "vitepress-theme-async"; // [!code --]
import ThemeAsync from "./main"; // [!code ++]

export default ThemeAsync;
```

:::

## 配置主题 Config

配置主题 [请看这里](./config)
13 changes: 8 additions & 5 deletions packages/vitepress-theme-async/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,16 @@ export const defineConfig = config => {
config.vite.css.preprocessorOptions.less.globalVars.isSearch = Boolean(config.themeConfig?.search?.provider === 'local');
config.vite.css.preprocessorOptions.less.globalVars.isCustomMdStyle = Boolean(config.themeConfig?.customMdStyle);

if (config.themeConfig.rss.enable) {
const selfBuildEnd = config.buildEnd;
config.buildEnd = async siteConfig => {
const selfBuildEnd = config.buildEnd;
config.buildEnd = async siteConfig => {
console.log();
console.log(`💖 Vitepress-Theme-Async. Guide: https://vitepress-theme-async.imalun.com`);
console.log();
if (config.themeConfig.rss.enable) {
await selfBuildEnd?.(siteConfig);
(await import('../plugin/rss.js'))?.genFeed(siteConfig);
};
}
}
};

return config;
};
Expand Down

0 comments on commit 81bfff6

Please sign in to comment.