前言
使用hexo和github搭建自己的博客小站
前提
安装Node.js
使用hexo需要安装node.js node.js官网 下载安装即可!
控制台查看node版本号
node -v
查看npm版本号
npm -v
返回版本号,即代表安装成功!
安装git
如果网站需要部署到 github 或者 gitee 上面,这个工具必不可少! git官网 下载安装即可!
开始hexo
安装hexo-cli脚手架
在终端输入:
npm install -g hexo-cli
注:如果安装时网络不好,出错的话,可以安装cnpm,使用cnpm安装hexo-cli脚手架
安装cnpm
终端输入(使用淘宝镜像):
npm install -g cnpm --registry=https://registry.npm.taobao.org
等待安装完成即可!
cnpm安装hexo-cli脚手架
在终端输入
cnpm install -g hexo-cli
等待安装完成!
hexo -v
开始hexo创建
-
创建一个文件夹(用于博客)
-
终端初始化
hexo initnode_modules: 依赖包 public:存放生成的页面 scaffolds:生成文章的一些模板 source:用来存放你的文章 themes:主题
_config.yml: 博客的配置文件
-
开启本地服务
hexo s -
查看
完成!
几个基本命令
-
初始化项目
hexo init -
打包生成已经写好的文章
hexo g -
清理旧的生成的文件(public文件夹)
hexo clean -
开启本地服务
hexo s -
推送本地项目至github(public文件夹)
hexo d
目录结构
.
├── node_modules 依赖包
├── scaffolds 生成文章的一些模板
├── public 存放生成的页面
├── source 资源目录
| ├── _drafts
| └── _posts *你写的md博客文件放在这里
├── themes 下载的主题在这里
├── _config.yml *整个项目的配置文件
└── package.json 包管理
github配置
-
创建仓库
==必须是这个格式:
你的用户名.github.io== -
git配置
cmd终端输入 配置用户名和邮箱地址
git config --global user.name "yourname" git config --global user.email "youremail"在项目中根目录的
_config.yml文件配置仓库deploy: type: git repo: https://github.com/你的仓库地址 branch: main -
安装deploy-git插件
在项目根目录下安装:(安装之后才支持git提交)
npm install hexo-deployer-git --save
部署到git
#清除缓存文件 db.json 和已生成的静态文件 public
hexo c
#生成网站静态文件到默认设置的 public 文件夹(hexo generate 的缩写)
hexo g
#自动生成网站静态文件,并部署到设定的仓库(hexo deploy 的缩写)
hexo d
注意deploy时会让输个yes
主题美化(可选)
1、安装
cd ./themes/
git clone https://github.com/JoeyBling/hexo-theme-yilia-plus.git
文件夹改名为 yilia-plus
2、配置
修改hexo根目录下的 _config.yml ➡️ theme: yilia-plus
3、更新
cd themes/yilia-plus
git pull
4、配置
主题内容配置文件在theme/yilia-plus目录下的_config.yml,请根据自己需要修改使用。
注:主题配置 原文章
未完待续。。。