1.安装node
安装地址:https://nodejs.org/en/download/Download | Node.js;
检验是否安装成功:打开 cmd 命令行(win+r 输入 cmd 回车)执行 :
node -v
安装成功之后显示版本号:

2.安装git
安装地址:https://www.git-scm.com/download;
检验是否安装成功:打开 cmd 命令行(win+r 输入 cmd 回车)执行 :
git --version
安装成功之后显示版本号:

3.安装hexo
Hexo 是一个快速、简洁且高效的博客框架。
(1)鼠标右键 点击Git Bash Here
(2)输入安装命令
$ npm install -g hexo-cli
成功标志:

4.初始化hexo
(1)创建hexo工程(切换到要生成blog项目的目录下,此例在d盘的根目录下)
$ hexo init blog
等待执行完毕之后会出现


(2)新建POST
$ cd blog
$ hexo new “newblog”
切换到blog目录,创建名为newblog的文件,此时会在 /blog/sources/_post/ 目录下生成 newblog.md 文件。
(3)生成静态文件
$ hexo generate
使用 Hexo 引擎将 Markdown 格式的文件解析成可以使用浏览器查看的 HTML 文件,HTML 文件存储在 blog/public 目录下。
(4)运行hexo服务器
$ hexo server
成功标志

打开浏览器输入 :http://localhost:4000/,(命令行提示网址,如果此步出现异常有可能是hexo -server未安装,google/百度自行解决)
不出意外的话会出现如下界面:

(5)安装主题
Hexo 提供了默认主题 landscape,主题的位置在 blog ->themes 文件夹下。主题根据自己喜好可以在网上找到,更多主题,通过 Git 进行相应的下载,下面以安装next主题为例。
$ cd /blog/themes
切换到themes主题目录下,执行git命令进行对应主题的下载
git clone https://github.com/iissnan/hexo-theme-next
等待执行完毕

此时themes文件夹下会多一个刚刚下载的主题文件夹,在此我将文件夹重命名为next(简洁),不改也可以。
然后再修改 /blog/config.yml 文件,将其中的 theme 改成 next。(这个是改变主题的地方,如果你用的是其他的主题,将这个 next 改成你下载下来的主题的文件夹的名称),完成后保存。执行以下命令:
$ hexo generate
$ hexo server
等待启动完成重新访问:http://localhost:4000/,就可以看到新换的主题。
5.将项目发布到github上
(1)注册github账户

注意:
Respository name一定要和注册账户名一致(图中框内),否则访问不了。

Public profile 下面的name一定要和注册账户名一致(图中框内),否则访问不了。

(3)将 Hexo上传到Github上
第一步:安装 deployer-git (安装部署工具)
$ npm install hexo-deployer-git --save
第二步:在 /blog/_config.yml 中修改 deploy 属性(注意“:”之后有空格 ) 否侧无法布署。
deploy:
type: git
repository: https://github.com/yuandatoucx/yuandatoucx.github.io.git
branch: master
将上方的 Repository 换成你申请的 Git 仓库地址,这里使用的是https方式,ssh方式自行google/百度

第三步:初始化本地仓库。
git init
第四步:连接远程仓库 ( 如果是第一次使用 git,在使用 git 的时候会提示输入用户名和密码)
git remote add origin https://github.com/yuandatoucx/yuandatoucx.github.io.git
第五步:发布 hexo 到 github page
//依次执行了,清空、重新生成静态文件、部署三个命令
hexo clean && hexo g && hexo d
等待执行完毕,刷新github,会出现(刚刚上传的项目):

打开浏览器访问:https://yourname.github.io/ (yourname为自己注册的用户名),如果出现如下界面,那么恭喜你,你的blog创建成功。

更多内容请关注公众号

网友评论