本地安装

vuePress 官方文档
首先使用官方的脚手架生成基本的项目结构

1
2
pnpm create vuepress blog
#下面选择blog 之后一直回车

项目结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
├── README.md
├── blog
│   └── \_posts
│   ├── 2018-11-7-frontmatter-in-vuepress-2.md
│   ├── 2018-11-7-frontmatter-in-vuepress-3.md
│   ├── 2018-11-7-frontmatter-in-vuepress.md
│   ├── 2019-2-26-markdown-slot-2.md
│   ├── 2019-2-26-markdown-slot-3.md
│   ├── 2019-2-26-markdown-slot-4.md
│   ├── 2019-2-26-markdown-slot.md
│   ├── 2019-5-6-writing-a-vuepress-theme-2.md
│   ├── 2019-5-6-writing-a-vuepress-theme-3.md
│   ├── 2019-5-6-writing-a-vuepress-theme-4.md
│   └── 2019-5-6-writing-a-vuepress-theme.md
└── package.json

其中_post 文件夹下面就是我们的博客,官方推荐我们使用日期作为文件名称

升级一下 package.json 版本

1
2
3
4
5
6
7
pnpm up

# package.json
"devDependencies": {
"@vuepress/theme-blog": "^2.3.3",
"vuepress": "^1.9.1"
}

部署

新建 deploy.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env sh

# 确保脚本抛出遇到的错误
set -e

# 生成静态文件
npm run build

# 进入生成的文件夹
cd blog/.vuepress/dist

# 如果是发布到自定义域名
# echo 'www.example.com' > CNAME

git init
git add -A
git commit -m 'deploy'

# 如果发布到 https://<USERNAME>.github.io
git push -f git@github.com:<USERNAME>/<USERNAME>.github.io.git master:gh-pages

# 如果发布到 https://<USERNAME>.github.io/<REPO>
# git push -f git@github.com:<USERNAME>/<REPO>.git master:gh-pages

cd -

package.json 增加部署命令

1
2
3
4
5
"scripts": {
"dev": "vuepress dev blog",
"build": "vuepress build blog",
"deploy": "bash deploy.sh"
}

github 静态 pages

新建仓库名称为 USERNAME.github.io 仓库

在仓库 Settings —> pages

img
然后就可以访问 USERNAME.github.io