Windows安装Node.js
安装Node.js
- Node.js下载地址: https://nodejs.org/en
- 测试是否安装成功: npm -v
配置模块和cache路径
- 全局模块路径: npm config set prefix "D:\software\nodejs\node_global"
- cache路径: npm config set cache "D:\software\nodejs\node_cache"
- 查看配置: npm config list
安装包到全局路径
- 安装包: npm install @vue/cli -g(将全局模块路径添加到环境变量才能使得安装的包直接使用)
安装Hexo并配置站点
安装Hexo
以下安装和发布等操作均在Git Bash中执行
- 安装Hexo: npm install hexo -g
- 查看Hexo版本: hexo -v
- 初始化Hexo: hexo init
修改站点信息及发布配置
- Github创建public仓库: 仓库名为username.github.io
- 修改站点_config.yml:1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15# Site 
 title: Blog
 subtitle: ''
 description: ''
 keywords:
 author: test
 language: en
 timezone: ''
 post_asset_folder: true #创建文章时自动创建文章同名目录用来存放文章中的图片,插入图片时使用图片名插入不需带路径
 deploy:
 type: git
 repo: https://github.com/username/username.github.io.git
 branch: master
更换主题
本例以melody主题为例,Hexo版本<5.0
- git clone -b master https://github.com/Molunerfinn/hexo-theme-melody themes/melody
- npm install hexo-renderer-pug hexo-renderer-stylus
- 创建目录source/_data,将melody的配置文件拷贝至该目录并重命名为melody.yml
- 修改站点_config.yml文件的theme为melody
Hexo使用
- 新建文章: hexo new "article"(也可以直接在source/_posts目录下新建article.md)- 文章中插入图片: - 设置post_asset_folder: true, 
- 创建目录source/images, 
 
- 设置post_asset_folder: true, 
 
- 文章中插入图片: 
- 新建页面: hexo new page categories- 在source/categories/index.md中添加type: “categories”即可添加分类属性,此时在文章中可使用categories属性添加分类  1 
 2
 3
 4
 5
 6--- 
 title: Hexo+Github-Pages搭建个人博客
 date: 2023-02-17 15:59:33
 categories: Hexo
 password: hexo
 ---
- 文章加密: 安装npm install --save hexo-blog-encrypt,在文章头信息添加password
 
- 在source/categories/index.md中添加type: “categories”即可添加分类属性,此时在文章中可使用categories属性添加分类  
- 预览站点: hexo server/hexo s(hexo s --debug可以测试站点,站点默认地址是http://localhost:4000/)
- 清除缓存: hexo clean/hexo c
- 生成待发布文件: hexo generate/hexo g
- 部署: hexo deploy/hexo d- 部署到Github需要安装依赖: npm install hexo-deployer-git --save
- 部署到Github: hexo c && hexo g && hexo d
- 访问: https://username.github.io/
 
- 部署到Github需要安装依赖: 
melody主题设置
| 1 | #设置导航栏 | 
*具体主题设置参考: https://molunerfinn.com/hexo-theme-melody-doc/zh-Hans/
