搭建Hexo博客

1.安装GIT、node.js、cnpm

git

可以到git官网下载相应平台的版本进行安装。直接在(github/git)下载。

node.js

到node.js官网下载相应平台的最新版本

cnpm

因为要借助npm这个包管理器进行安装,但npm比较慢,因此用npm去安装cnpm,打开cmd:

npm install -g cnpm --registry=http://registry.npm.taobao.org

2.安装Hexo

打开cmd,执行以下命令:

cnpm install -g hexo

安装好了以后,用cmd跳到你想要放blog的目录下。

初始化:

hexo init

生成静态页面

hexo g

本地运行

hexo s

3.新建仓库并推送

在GitHub上,新建repository

建立与你用户名对应的仓库,仓库名必须为【 your_username.github.io】,例如我的是YDP1994.github.io。

复制repo

例如我的是https://github.com/xiaobinhong1/YDP1994.github.io.git

配置博客

进入你的hexo文件夹根目录下,用编辑器打开_config.yml,修改deploy项,如下(根据你的github进行相应更改):

ploy:
  type: git     
  repo: https://github.com/xiaobinhong1/YDP1994.github.io.git
  branch: master

注意:在分配符后面要加空格

推送到GitHub

hexo d

每次修改完本地的文件后要执行以下命令,重新部署到github上:

hexo clean
hexo g
hexo d

常用命令

hexo new "postName" #新建文章
hexo new page "pageName" #新建页面
hexo generate #生成静态页面至public目录
hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server)
hexo deploy #将.deploy目录部署到GitHub
hexo help # 查看帮助

4.常见错误

ERROR Deployer not found: git

解决方法:打开命令行,输入
npm install --save hexo-deployer-git

FATAL Something's wrong.

原因:需要为自己配置身份信息。
解决方法:打开命令行,输入
git config --global user.name "yourname"

git config --global user.email "youremail"

参考文章与视频

https://www.jianshu.com/p/8681ab76da08
https://www.bilibili.com/video/av44544186

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容