使用VuePress2.X构建个人知识博客,域名部署到GitHub Pages中
liuian 2025-06-18 22:21 40 浏览
使用VuePress2.X构建个人知识博客,并且用个人域名部署到GitHub Pages中
什么是VuePress
VuePress 是一个以 Markdown 为中心的静态网站生成器。你可以使用 Markdown 来书写内容(如文档、博客等),然后 VuePress 会帮助你生成一个静态网站来展示它们。VuePress 诞生的初衷是为了支持 Vue.js 及其子项目的文档需求,但是现在它已经在帮助大量用户构建他们的文档、博客和其他静态网站。官网:
https://vuepress.vuejs.org/zh/VuePress1.X和VuePress2.X区别
最开始星哥使用的是VuePress1.X(https://vuepress.xgss.net/),后期由于nodejs升级了导致VuePress1.X使用不了,一直报错。
无奈升级到VuePress2.X,2.x和1.x有很多不兼容的地方,也踩了很多坑,记录一下。
安装VuePress
环境: window10
最好有自己的域名,星哥这里使用的事vuepress-v2.xgss.net
软件安装:nodejs和git
由于官方的教程docs.yml文件是pnpm作为包管理器,本人最开始使用的是yarn导致GitHub Actions失败,所以使用pnpm重新安装VuePress
星哥最开始使用的yarn,后来改成了pnpm,所以这个笔记遇到yarn一律改成pnpm既可。
https://vuepress.vuejs.org/zh/guide/deployment.html#github-pages重新安装VuePress
安装
$ npm install -g pnpm
added 1 package in 3s
$ pnpm -v
10.11.1
pnpm create vuepress vuepress-starter
mkdir vuepress-starter
cd vuepress-starter
安装vuepress
pnpm init
pnpm add -D vuepress@next vue
pnpm add -D @vuepress/bundler-vite@next @vuepress/theme-default@next
安装调试插件
pnpm add -D sass-embedded
安装搜索插件
pnpm add -D @vuepress/plugin-search@next
启动开发服务器
pnpm docs:dev
构建网站:
pnpm docs:build以下是使用yarn安装,这里推荐使用pnpm安装
你可以通过 create-vuepress 直接创建项目模板。
yarn create vuepress vuepress-starter
创建并进入一个新目录
mkdir vuepress-starter
cd vuepress-starter
初始化项目
git init
yarn init
# 安装 vuepress
yarn add -D vuepress@next
# 安装打包工具和主题
yarn add -D @vuepress/bundler-vite@next @vuepress/theme-default@next
创建 VuePress 配置文件
docs/.vuepress/config.js
mkdir -p docs/.vuepress/
vi docs/.vuepress/config.js
填入一下配置:
import { viteBundler } from '@vuepress/bundler-vite'
import { defaultTheme } from '@vuepress/theme-default'
import { defineUserConfig } from 'vuepress'
export default defineUserConfig({
bundler: viteBundler(),
theme: defaultTheme(),
})创建你的第一篇文档
echo '# Hello VuePress' > docs/README.md启动开发服务器
你可以在 package.json 中添加一些 scripts :
{
"scripts": {
"docs:dev": "vuepress dev docs",
"docs:build": "vuepress build docs"
}
}运行 docs:dev 脚本可以启动开发服务器:
yarn docs:devVuePress 会在 http://localhost:8080 启动一个热重载的开发服务器。当你修改你的 Markdown 文件时,浏览器中的内容也会自动更新。
报错:
yarn add -D sass-embedded再启动开发服务器
$ yarn docs:dev
yarn run v1.22.22
$ vuepress dev docs
√ Initializing and preparing data - done in 58ms
10:22:16 [vite] (client) Re-optimizing dependencies because lockfile has changed
vite v6.3.5 dev server running at:
Local: http://localhost:8080/
Network: http://192.168.1.251:8080/
Network: http://192.168.52.1:8080/
Network: http://192.168.152.1:8080/
使用浏览器访问http://localhost:8080/
构建你的网站
运行 docs:build 脚本可以构建你的网站:
yarn docs:build查看vuepress版本
yarn list vuepressvuepress主题(报错)
更换主题,一直报错就决定不换主题了,使用默认主题了!
官网: https://marketplace.vuejs.press/zh/themes/
VuePress Theme Mix
https://vuepress-theme-mix.netlify.app/zh/guide/getting-started.html
安装VuePress Theme Mix
yarn add -D vuepress-theme-mix@next使用与配置
import { defineUserConfig } from 'vuepress'
import mixTheme from 'vuepress-theme-mix'
export default defineUserConfig({
// ...
theme: mixTheme({
// 在这里配置主题
}),
// ...
})VuePress配置搜索
安装插件
首先,在你的 VuePress 项目中安装该插件:
pnpm add -D @vuepress/plugin-search@next
# 或者
yarn add -D @vuepress/plugin-search@next
# 或者
npm i -D @vuepress/plugin-search@next
配置config.js
.vuepress/config.js 示例:
import { searchPlugin } from '@vuepress/plugin-search'
module.exports = {
plugins: [
searchPlugin({
// 插件选项
// 可以配置的选项包括:
// maxSuggestions: 5, // 最多显示多少条搜索结果
// isSearchable: (page) => page.path !== '/', // 排除特定页面
// hotKeys: ['s', '/'], // 激活搜索框的快捷键
// locales: { // 多语言支持
// '/': {
// placeholder: '搜索',
// },
// '/en/': {
// placeholder: 'Search',
// },
// },
// get.Display.Text: (page) => { /* 自定义搜索结果显示文本 */ },
// search: (query, pages) => { /* 自定义搜索逻辑 */ },
}),
],
}
报错1
使用
yarn docs:build报错,由于图片没有上传到oss中导致报错。
error [vite:asset] Could not load G:/STAR学习/vuepress-starter/docs/./chatgpt/H:/typora_images/image-20240415180831846.png (imported by docs/.vuepress/.temp/pages/chatgpt/15.免费使用GPT-4的3种方法,白嫖大模型.html.vue): ENOENT: no such file or directory, open 'G:\STAR学习\vuepress
-starter\docs\chatgpt\H:\typora_images\image-20240415180831846.png'解决:
grep -R 'typora_images' ./*| grep -v '.vuepress/'
查看所有未上传的图片把所有的图片上传到oss中,再生成yarn docs:build
配置到GitHub Pages
前置条件,需要你有自己的域名,如果没有自有的域名,也可以使用github的域名,但是国内可能访问不畅。
自己的域名CNAME到 https://<USERNAME>.github.io
或者使用官方域名: https://<USERNAME>.github.io/<REPO>/这里星哥使用vuepress-v2.xgss.net 解析到 funet8.github.io
1.github新建仓库
新建git 仓库
vuepress-v2.xgss.net
克隆到本地
git clone git@github.com:funet8/vuepress-v2.xgss.net.git
把docs的文档拷贝进去2.执行
#提交到github仓库-vuepress-v2分支
#git init
git add -A
git commit -m 'deploy.sh-vuepressV2脚本自动提交'
git push -f git@github.com:funet8/vuepress-v2.xgss.net.git main有两个分支
3.设置域名访问
自有域名 vuepress-v2.xgss.net 解析到github中
Settings --> Pages
把 vuepress-v2.xgss.net CNAME解析到 funet8.github.io
把 你的域名 解析到 <你的github账号名>.github.io
等待解析生效,github会提示DNS check successful
勾选 Enforce HTTPS,强制
直接根据官方文档先初始化项目就行了,注意文档的版本,v1和v2还是有很多地方不同的。
4.用 GitHub Actions 部署到 GitHub Pages
参考:https://vuepress.vuejs.org/zh/guide/deployment.html#github-pages
创建 .github/workflows/docs.yml 文件来配置工作流。
name: docs
on:
# 每当 push 到 main 分支时触发部署
push:
branches: [main]
# 手动触发部署
workflow_dispatch:
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0
- name: 设置 pnpm
uses: pnpm/action-setup@v4
- name: 设置 Node.js
uses: actions/setup-node@v4
with:
# 选择要使用的 node 版本
node-version: 22
# 缓存 pnpm 依赖
cache: pnpm
- name: 安装依赖
run: pnpm install --frozen-lockfile
# 运行构建脚本
- name: 构建 VuePress 站点
run: pnpm docs:build
# 查看 workflow 的文档来获取更多信息
# @see https://github.com/crazy-max/ghaction-github-pages
- name: 部署到 GitHub Pages
uses: crazy-max/ghaction-github-pages@v4
with:
# 部署到 gh-pages 分支
target_branch: gh-pages
# 部署目录为 VuePress 的默认输出目录
build_dir: docs/.vuepress/dist
env:
# @see https://docs.github.com/cn/actions/reference/authentication-in-a-workflow#about-the-github_token-secret
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}提交代码,触发Actions
报错没有配置packageManagerError: No pnpm version is specified. Please specify it by one of the following ways: - in the GitHub Action config with the key "version" - in the package.json with the key "packageManager"
解决
在 package.json添加
"packageManager": "pnpm@10.11.1"
或者在 .github/workflows/docs.yml 文档中添加
- name: 设置 pnpm
uses: pnpm/action-setup@v4
with:
version: '8.x'报错无pnpm-lock.yaml
Dependencies lock file is not found in /home/runner/work/vuepress-v2.xgss.net/vuepress-v2.xgss.net. Supported file patterns: pnpm-lock.yaml解决
安装pnpm
$ npm install -g pnpm
added 1 package in 3s
$ pnpm -v
10.11.1
$rm -rf node_modules/
$ pnpm installpnpm包管理的问题
由于官方的教程docs.yml文件是pnpm作为包管理器,本人最开始使用的是yarn导致GitHub Actions失败,所以重新安装VuePress
https://vuepress.vuejs.org/zh/guide/deployment.html#github-pages重新安装VuePress
mv package.json package-yarn.json
rm -rf node_modules
安装vuepress
pnpm init
pnpm add -D vuepress@next vue
pnpm add -D @vuepress/bundler-vite@next @vuepress/theme-default@next
调试插件
pnpm add -D sass-embedded
搜索插件
pnpm add -D @vuepress/plugin-search@next
启动开发服务器
pnpm docs:dev
构建网站:
pnpm docs:build5.工作流权限
在仓库的 Settings > Actions > General,确保 GITHUB_TOKEN 的权限被设置为 write 权限(即推送权限)。
如图,勾选:Read and write permissions
保存。
6.提交成功
但是当我访问页面的时候
https://funet8.github.io/vuepress-v2.xgss.net/无尽的404让人头疼
再次修改
docs\.vuepress\config.js
里面的配置
base: '/vuepress-v2.xgss.net/', // 部署到github相关的配置
则是使用https://funet8.github.io/vuepress-v2.xgss.net/ 访问改成使用域名,发现缺少CNAME 文件
于是在docs.yml文件中添加一步
- name: Add CNAME file # 添加 CNAME 文件
run: echo 'vuepress-v2.xgss.net' > docs/.vuepress/dist/CNAME最终使用域名 vuepress-v2.xgss.net 可以访问博客页面了。
最后
写文不易,如果你都看到了这里,请点个赞和在看,分享给更多的朋友;也别忘了关注星哥玩云!这里有满满的干货分享,还有轻松有趣的技术交流~点个赞、分享给身边的小伙伴,一起成长,一起玩转技术世界吧!
通过以上步骤,你成功地使用VuePress 2.X搭建了一个个人知识博客,并将其部署到GitHub Pages,同时还配置了自己的个人域名。这不仅为你提供了一个高效的知识管理平台,还能让你更好地记录学习过程并分享给他人。希望这篇教程对你有所帮助,祝你搭建博客愉快!
相关推荐
- 搜狗中文手写输入法下载(下载搜狗手写版)
-
点击输入框弹出搜狗键盘,进入搜狗工具栏的设置图标,手写设置,勾选“手写注音”。在输入法点击那个键盘,就会有那个输入方式的选项,选择手写输入就可以了。呼出输入法,点击输入法上方的键盘图样,找到手写输入,...
- 免费云服务器怎么样(云服务器哪些是免费)
-
搞软件开发的人都知道,对于一些网络应用软件必须要租用服务器存放才能被更多用户使用。如一些应用于浏览软件、传输软件、远程登录软件等。如果是像以往那样租用物理机服务器,成本费用非常高昂。但是现在有云服务器...
- 斐讯路由器登录密码忘记了怎么办
-
1.斐讯无线路由器密码忘记,要重设密码,首先长按路由器背面的reset键,将路由器恢复出厂设置。2.路由器恢复出厂设置以后,在电脑浏览器地址栏中输入:192.168.1.1并按下回车键,“用户名”输...
- 软件之家软件分享(软件之家软件合集)
-
驱动精灵,驱动人生,360驱动大师。云之家挺好用的,通讯录是按组织架构的,跟微信一样可以看到所有人的动态,还有小组一般是按公司、部门、行业、兴趣分的,老板开讲可以把最上级的意思快速传达给所有员工。我们...
- 鲁大师下载安装免费版(鲁大师app下载)
-
解决方法吧。第一种方法:一般情况下,我们安装的时候软件也需要一定的时间,我们可以多等待一会。第二种方法:安装到99%你直接关掉安装。然后自己到安装目录文件里找到启动程序,就可以用了。第三种方法:1、可...
- ssd坏道检测与修复(ssd硬盘坏道检测)
-
1、固态硬盘(SSD硬盘)损坏分两方面,一方面是出现硬盘坏块,另一方面是出现物理损坏。2、固态硬盘如果出现坏块是不可修复的。SSD硬盘坏块不是所谓的逻辑坏块。SSD硬盘内部是晶体管,损坏后不能恢复,这...
- win10专业工作版激活密钥(windows10 专业版激活密钥)
-
要获得Windows10专业版永久激活密钥,可以通过微软官方零售渠道或可靠的第三方卖家购买正版产品密钥。使用第三方卖家时,务必注意其信誉和真实性。激活后,密钥将与您的Microsoft帐户关...
- 键盘下载安装(维语输入法键盘下载安装)
-
以惠普星14,win10系统为例,具体的操作步骤入如下:1、开启电脑后,在电脑的浏览器中搜索“输入法”。2、在页面中挑选一款自己喜欢的输入法软件,并点击旁边的下载按钮。3、随后在弹出的对话框中选择下载...
- office 2010怎么激活(office 2010如何激活)
-
1.打开下载好的Office,点击左上角的“文件”,然后在下拉菜单上点击“帮助”,显示需要激活Office。? 2.找到解压缩好的安装文件,打开里面的“激活破解”文件夹。? 3.在文件夹中运行激...
- 笔记本xp系统忘记开机密码(笔记本xp开机密码忘了怎么办最简单的方法)
-
xp系统忘记开机密码解锁方法如下1、在需要破解开机密码的xp电脑上插入pe启动盘,启动电脑后不停按F12、F11、Esc等快捷键,在弹出的启动菜单选择框中选择识别到的usb启动项,比如General...
- isofix接口(isofix接口怎么拆卸)
-
isofix接口上有isofix的字样,它的图标是一个类似人坐在座椅上。在汽车座椅靠垫与坐垫之间的连接处有2个接口,那就是isofix接口,是一种硬连接方式,为了防止撞击时发生座椅翻转,一些座椅在IS...
- 无线路由器怎么设置不让别人连接
-
要设置无线路由器不让别人连接,可以采取以下措施:1.配置路由器密码:在路由器设置中,可以设置密码,限制只有授權的人才能连接到网络。2.配置防火墙:可以安装防火墙软件,如OpenDNS,限制...
- fast迅捷路由器(fast迅捷路由器配置上网教程)
-
http://www.fastcom.com.cn/上面这个就迅捷官网的网址老版本的迅捷路由器默认登录地址为“192.168.1.1”,新版本的迅捷路由器默认登录地址为“falogin.cn”。02...
- 一周热门
-
-
飞牛OS入门安装遇到问题,如何解决?
-
如何在 iPhone 和 Android 上恢复已删除的抖音消息
-
Boost高性能并发无锁队列指南:boost::lockfree::queue
-
大模型手册: 保姆级用CherryStudio知识库
-
用什么工具在Win中查看8G大的log文件?
-
如何在 Windows 10 或 11 上通过命令行安装 Node.js 和 NPM
-
威联通NAS安装阿里云盘WebDAV服务并添加到Infuse
-
Trae IDE 如何与 GitHub 无缝对接?
-
idea插件之maven search(工欲善其事,必先利其器)
-
如何修改图片拍摄日期?快速修改图片拍摄日期的6种方法
-
- 最近发表
- 标签列表
-
- python判断字典是否为空 (50)
- crontab每周一执行 (48)
- aes和des区别 (43)
- bash脚本和shell脚本的区别 (35)
- canvas库 (33)
- dataframe筛选满足条件的行 (35)
- gitlab日志 (33)
- lua xpcall (36)
- blob转json (33)
- python判断是否在列表中 (34)
- python html转pdf (36)
- 安装指定版本npm (37)
- idea搜索jar包内容 (33)
- css鼠标悬停出现隐藏的文字 (34)
- linux nacos启动命令 (33)
- gitlab 日志 (36)
- adb pull (37)
- python判断元素在不在列表里 (34)
- python 字典删除元素 (34)
- vscode切换git分支 (35)
- python bytes转16进制 (35)
- grep前后几行 (34)
- hashmap转list (35)
- c++ 字符串查找 (35)
- mysql刷新权限 (34)
