参考视频链接:https://www.bilibili.com/video/BV1Yb411a7ty?from=search&seid=3816734260261191496
一、创建本地博客
- 安装
node.js
,查看版本node -v
,npm -v
。 - 更换镜像源
npm install -g cnpm --registry=https://registry.npm.taobao.org
- 查看
cnpm
安装情况,cnpm -v
- 安装hexo框架
cnpm install -g hexo-cli
hexo -v
验证安装完成
cd
到准备放置博客的文件夹,然后mkdir blog
新建名为blog的文件夹。- 进入blog文件夹,然后初始化博客
hexo init
,克隆一些主题等文件。
hexo s
启动博客,可以在本地浏览器中输入localhost:4000
打开。hexo n
新建文章,hexo n "文章名字"
,进入文章的位置,vim 文章名字
,编辑文章。- 写好文章后,在blog中先清理一下
hexo clean
,然后hexo g
生成添加新的博客,然后hexo s
启动可以在本地查看最新添加的文章。
二、利用GitHub将本地博客推到远端
- 将博客部署至github中,可以在远端查看博客。首先在GitHub中新建仓库,仓库的命名很重要,设置成
用户名.github.io
- 安装git部署的插件:
cnpm install --save hexo-deployer-git
- 设置_config.yml。
vim _config.yml
编辑配置,在最后写成如下
# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: 'git'
repo: https://github.com/ld1461575230/ld1461575230.github.io.git
branch: main
- 部署远端
hexo d
,将配置好的文件推到GitHub上。 - 在浏览器中访问
用户名.github.io
,有页面则部署成功。
三、博客更换主题(简单更换)
- 更换主题,克隆已有的主题
git clone https://github.com/litten/hexo-theme-yilia.git themes/yilia
其中,themes/yilia表示下载并放到themes文件夹中。
- 设置_config.yml,
vim _config.yml
编辑配置
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: yilia
- 配置完新的主题,运行三个命令
hexo clean
、hexo g
、hexo s
后,本地主题更改完成。 - 最后将主题推到远端
hexo d
,刷新用户名.github.io
,远端主题已更改。