使用Gitee+Hexo搭建高速稳定的个人博客

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/meifannao789456/article/details/81532924

为了更好的阅读体验,请访问个人博客地址:
https://xiuxiuing.gitee.io/blog/2018/08/08/giteepage/

为何使用Gitee而不是GitHub

目前国内访问GitHub速度慢,还可能被墙,所以Gitee来构建个人博客。Gitee类似国内版的GitHub,访问速度有保证。

环境要求

  • Git
  • NodeJs
    默认你已经安装了Git和NodeJS(推荐使用cnpm)

开始搭建

1. 安装Hexo

打开 shell 终端,输入命令`npm install -g hexo`
$ sudo cnpm install -g hexo
Password:
Downloading hexo to /usr/local/lib/node_modules/hexo_tmp
Copying /usr/local/lib/node_modules/hexo_tmp/[email protected]@hexo to /usr/local/lib/node_modules/hexo
Installing hexo's dependencies to /usr/local/lib/node_modules/hexo/node_modules
[1/27] abbrev@^1.0.7 installed at node_modules/[email protected]@abbrev
[2/27] archy@^1.0.0 installed at node_modules/[email protected]@archy
[3/27] hexo-i18n@^0.2.1 installed at node_modules/[email protected]@hexo-i18n
[4/27] js-yaml@^3.6.1 existed at node_modules/[email protected]@js-yaml
[5/27] bluebird@^3.4.0 installed at node_modules/[email protected]@bluebird
[6/27] chalk@^2.3.1 installed at node_modules/[email protected]@chalk
[7/27] hexo-front-matter@^0.2.2 installed at node_modules/[email protected]@hexo-front-matter
[8/27] minimatch@^3.0.4 installed at node_modules/[email protected]@minimatch
[9/27] pretty-hrtime@^1.0.2 installed at node_modules/[email protected]@pretty-hrtime
[10/27] hexo-util@^0.6.3 installed at node_modules/[email protected]@hexo-util
[11/27] hexo-cli@^1.1.0 installed at node_modules/[email protected]@hexo-cli
[12/27] resolve@^1.5.0 installed at node_modules/[email protected]@resolve
[13/27] strip-indent@^2.0.0 installed at node_modules/[email protected]@strip-indent
[14/27] strip-ansi@^4.0.0 installed at node_modules/[email protected]@strip-ansi
[15/27] text-table@^0.2.0 installed at node_modules/[email protected]@text-table
[16/27] tildify@^1.2.0 existed at node_modules/[email protected]@tildify
[17/27] titlecase@^1.1.2 installed at node_modules/[email protected]@titlecase
[18/27] moment@^2.19.4 installed at node_modules/[email protected]@moment
[19/27] moment-timezone@^0.5.14 installed at node_modules/[email protected]@moment-timezone
[20/27] hexo-log@^0.2.0 installed at node_modules/[email protected]@hexo-log
[21/27] [email protected] installed at node_modules/[email protected]@swig-extras
[22/27] lodash@^4.17.5 installed at node_modules/[email protected]@lodash
[23/27] [email protected] installed at node_modules/[email protected]@cheerio
[email protected] download from binary mirror: {"module_name":"fse","module_path":"./lib/binding/{configuration}/{node_abi}-{platform}-{arch}/","remote_path":"./v{version}/","package_name":"{module_name}-v{version}-{node_abi}-{platform}-{arch}.tar.gz","host":"https://cdn.npm.taobao.org/dist/fsevents"}
[24/27] nunjucks@^3.1.2 installed at node_modules/[email protected]@nunjucks
[25/27] swig-templates@^2.0.2 installed at node_modules/[email protected]@swig-templates
[26/27] hexo-fs@^0.2.0 installed at node_modules/[email protected]@hexo-fs
[27/27] warehouse@^2.2.0 installed at node_modules/[email protected]@warehouse
execute post install 2 scripts...
[1/2] scripts.postinstall nunjucks@^3.1.2 run "node postinstall-build.js src"
[1/2] scripts.postinstall nunjucks@^3.1.2 finished in 109ms
[2/2] scripts.install [email protected][email protected] › fsevents@^1.0.0 run "node install"
[fsevents] Success: "/usr/local/lib/node_modules/hexo/node_modules/[email protected]@fsevents/lib/binding/Release/node-v64-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
[2/2] scripts.install [email protected][email protected] › fsevents@^1.0.0 finished in 306ms
deprecate titlecase@^1.1.2 no longer maintained
Recently updated (since 2018-08-01): 1 packages (detail see file /usr/local/lib/node_modules/hexo/node_modules/.recently_updates.txt)
 2018-08-06
   → [email protected] › path-parse@^1.0.5(1.0.6) (14:32:36)
All packages installed (280 packages installed from npm registry, used 4s, speed 1.65MB/s, json 236(1.51MB), tarball 5.8MB)
[[email protected]] link /usr/local/bin/hexo@ -> /usr/local/lib/node_modules/hexo/bin/hexo

注:如果提示权限错误,命令前加sudo,cnpm 是淘宝的开源镜像,国内访问比npm快。

2. 初始化Hexo

在你的电脑上创建Hexo文件夹,在shell终端中切换到Hexo目录,输入命令 hexo init

$ cd /work/Hexo 
/work/Hexo $ hexo init
INFO  Cloning hexo-starter to /work/Hexo
Cloning into '/work/Hexo'...
remote: Counting objects: 65, done.
remote: Total 65 (delta 0), reused 0 (delta 0), pack-reused 65
Unpacking objects: 100% (65/65), done.
Submodule 'themes/landscape' (https://github.com/hexojs/hexo-theme-landscape.git) registered for path 'themes/landscape'
Cloning into '/work/Hexo/themes/landscape'...
^Cwarning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry the checkout with 'git checkout -f HEAD'

INFO  See you again

初始化完成后Hexo的目录结构:
初始化后目录结构

3. 获取博客主题

在shell中输入命令:git clone https://gitee.com/xiuxiuing/hexo-theme-even themes/even

/work/Hexo $ git clone https://gitee.com/xiuxiuing/hexo-theme-even themes/even
Cloning into 'themes/even'...
remote: Counting objects: 136, done.
remote: Compressing objects: 100% (123/123), done.
remote: Total 136 (delta 4), reused 128 (delta 2)
Receiving objects: 100% (136/136), 264.27 KiB | 556.00 KiB/s, done.
Resolving deltas: 100% (4/4), done.

克隆完成后,在/Hexo/themes目录下,可以看到 landscapeeven 两个文件夹。
我们所要使用的主题都是放在这个目录下,Hexo默认使用的是landscape主题,由于第二步Hexo初始化时主题没有clone成功,所以我们这一步克隆了even主题,接下来会使用even主题进行演示。
想获取更多主题,可在网站:https://hexo.io/themes/ 选择自己喜欢的主题,按照此步的步骤clone下来。

4. _config.yml对博客进行基础配置

_config.yml文件修改,保存
_config.yml

5. 本地预览博客

编译项目,输入命令:hexo g
运行项目,输入命令:hexo s

$ hexo g
INFO  Start processing
INFO  Files loaded in 186 ms
INFO  Generated: archives/2018/08/index.html
INFO  Generated: archives/index.html
INFO  Generated: archives/2018/index.html
INFO  Generated: index.html
INFO  Generated: 2018/08/08/hello-world/index.html
INFO  5 files generated in 242 ms
$ hexo s
INFO  Start processing
INFO  Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.

在浏览器中输入`http://localhost:4000/``就可以看到效果啦

部署博客到Gitee上

1. 创建Gitee账号

到码云:https://gitee.com/ 上申请注册账号,码云类似国内版的GitHub,所以操作界面跟GitHub差不多,多了一些国产化的东西,这里不做更多介绍了,自己研究下。

扫描二维码关注公众号,回复: 3250837 查看本文章

2. 创建项目

创建项目
创建完成后,在项目中复制项目地址。

3. 在_config.yml中配置Git

deploy:
  type: git
  repo: https://gitee.com/xiuxiuing/blog.git
  branch: master

注意:冒号后面一定要有空格,否则不能正确识别。

4. 发布到Gitee

输入命令npm install hexo-deployer-git --save 安装自动部署发布工具
输入命令hexo clean && hexo g && hexo d 发布博客,首次发布需要在shell中输入账号和密码。

5. Gitee Pages设置

在项目的服务中选择Pages选项
Pages
选择 master分支,点击 部署/更新
部署
稍等一会儿博客就发布成功啦,访问博客地址:https://xiuxiuing.gitee.io/blog,就可预览在线博客啦!!!
如果博客的样式不对,则需要在_config.yml中配置下博客地址和路径:

url: https://xiuxiuing.gitee.io/blog/
root: /blog

再执行命令hexo clean && hexo g && hexo d 就可以啦。

至此,我们的博客就搭建完成啦!!!
/Hexo/source/_posts目录下就可以写我们的博客啦!!!

个人博客效果参考:https://xiuxiuing.gitee.io/blog/

觉得不错,麻烦帮忙分享给朋友,谢谢各位啦!!!

猜你喜欢

转载自blog.csdn.net/meifannao789456/article/details/81532924
今日推荐