搭建博客
- 安装node和git
在Windows中查看是否成功安装node
win + R 输入cmd打开命令行窗口
输入
node -v
回车后看到版本号
输入
npm -v
同样看到版本号即表示安装成功
2.安装hexo
- 安装cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
安装成功后输入
cnpm
可以看到相应信息
- 安装hexo
cnpm install -g hexo-cli
安装成功后可输入
hexo -v
验证是否成功
3.选择一个路径,新建文件夹blog(当然也可以用其他名称)
mkdir blog
cd blog //进入blog文件夹
hexo init //初始化文件夹,漫长的等待。。。
如果出现了错误,可以删掉blog文件夹,从新建文件夹blog重新开始
成功后可以看到blog文件夹下生成了一些文件
然后就可以启动博客了
hexo s
可以看到输出如下信息
INFO Start processing
INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.
在浏览器输入localhost:4000回车就可以看到博客了
如下图
默认生成了一篇Hello World的文章
新建文章
搭建完成后就可以写博客文章啦
先CTRL C断开
然后输入
hexo n "我的第一篇博客文章"
//可以看到在以下路径中创建了一个.md文件
INFO Created: D:\hexo\blog\source\_posts\我的第一篇博客文章.md
找到该文件用编辑器编辑(vscode、notepad++等)
编辑完后保存退出
输入
hexo clean
hexo g
就可以生成文章了
再输入
hexo s
打开localhost:4000就可以看到刚刚写的博客了
部署到github
- 在GitHub中new repository
仓库名: “GitHub账号名称”.github.io - 安装插件
cnpm install --save hexo-deployer-git
- 修改配置文件
找到blog文件夹中的_config.yml
用编辑器打开
在最后面找到Deployment
修改成如下
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: https://github.com/"GitHub账号"/"GitHub账号昵称".github.io.git
branch: master
保存退出
4. 部署
hexo d
然后就可以在GitHub中看到部署的文件了
以后直接在浏览器输入"GitHub账号昵称".github.io.git
就可以在公网访问个人博客了
更改hexo主题
- 下载主题
在GitHub上找到的一个主题
clone到本地
git clone https://github.com/litten/hexo-theme-yilia.git themes/yilia
- 修改配置文件
找到blog文件夹中的_config.yml
用编辑器打开
找到theme
将landscape修改为yilia
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: landscape
保存退出
- 重新生成,启动
hexo clean
hexo g
hexo s
hexo d//推送到GitHub