基于Windows搭建,依托Github的博客。
1. Github创建Repository
Respository的名字必须是:你的github账户名.github.io (下图由于我已经创建过了,所以被标红)

2. 本地安装NodeJS和Git
NodeJS官网和Git官网
安装完成后,在CMD中运行如下命令,并能返回版本信息,则说明安装完成。
node -v
npm -v
git --version

第一次使用Git的话,还需要设置用户名和邮箱,以及配置SSH绑定Github账号。具体可以参考这篇文章。
3. 安装Hexo
先切换npm到淘宝源。
npm config set registry https://registry.npm.taobao.org

选择一个新文件夹来存储博客文件,可以命名为Hexo,然后右键选择打开Git Bash,运行
npm install hexo-cli -g
等待安装完成后,再依次运行 (有时可能需要管理员权限打开Git Bash,再CD到Hexo文件夹)
hexo init Hexo
npm install
hexo g // g是generate的意思
hexo s // s是server,即启动服务器
这时就可以在本地浏览器访问博客了。 如果有需要,可以更换端口,命令如下
hexo s -p 6000
4. 部署到Github
需要在Git Bash中运行下列命令下载插件。
npm install hexo-deployer-git --save
打开上述的Hexo文件夹中的配置文件:_config.yml
在末尾的deploy中添加如下信息:(respository要更换成自己的地址)

之后运行如下命令,就可以把博客部署到Github
hexo d // d是deploy
然后打开Github上的Repository的Settings,在GitHub Pages下就有博客地址了,可以直接访问,但要记住是https,不是http:


网友评论