hexo 环境变量_10分钟搭建专属于自己的博客(hexo+gitee)

一直都有一个建一个自己博客的想法,直到最近朋友说起hexo(一个基于nodejs 的静态博客网站生成器)很简单,就去看了下,Linux和Windows都可以,文章是存到码云(gitee)上的(用码云是因为国内的git仓库,速度还是要比放到GitHub上快一点的),我是在Linux下部署的

环境准备

安装git和nodejs

安装git[root@localhost ~]# yum -y install git 安装nodejs下载二进制文件,我的是 12.18.3版本的(目前长期支持版本)[root@iZbp1098qx0mbltjlw3l1zZ ~]# wget https://nodejs.org/dist/v12.18.3/node-v12.18.3-linux-x64.tar.xz解压文件,我习惯性的解压到/usr/local/下[root@iZbp1098qx0mbltjlw3l1zZ ~]# tar xf node-v12.18.3-linux-x64.tar.xz  -C /usr/local/[root@iZbp1098qx0mbltjlw3l1zZ ~]# cd /usr/local/node-v12.18.3-linux-x64/ [root@iZbp1098qx0mbltjlw3l1zZ node-v12.18.3-linux-x64]# lsbin  CHANGELOG.md  include  lib  LICENSE  README.md  share检查版本,因为Node官网已经把 linux下载版本更改为已编译好的版本了,我们直接下载解压后就可以使用[root@iZbp1098qx0mbltjlw3l1zZ node-v12.18.3-linux-x64]# ./bin/node -vv12.18.3设置软连接(或者在环境变量中添加node的bin目录到path中也可以,就是方便使用这两个命令)[root@iZbp1098qx0mbltjlw3l1zZ node-v12.18.3-linux-x64]# ln -s /usr/local/node-v12.18.3-linux-x64/bin/npm /usr/local/bin/[root@iZbp1098qx0mbltjlw3l1zZ node-v12.18.3-linux-x64]# ln -s /usr/local/node-v12.18.3-linux-x64/bin/node /usr/local/bin/

开始安装hexo

1.安装hexo

[root@localhost ~]# npm install -g hexo/usr/local/node-v12.18.3-linux-x64/bin/hexo -> /usr/local/node-v12.18.3-linux-x64/lib/node_modules/hexo/bin/hexonpm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/hexo/node_modules/chokidar/node_modules/fsevents):npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})+ hexo@5.1.1added 88 packages from 348 contributors in59.674s设置软连接[root@localhost ~]# ln -s /usr/local/node-v12.18.3-linux-x64/bin/hexo /usr/local/bin/

2.初始化hexo

创建一个文件夹,并进入到文件夹内,初始化hexo

[root@localhost ~]# mkdir /blog[root@localhost ~]# cd /blog[root@localhost blog]# hexo initINFO  Cloning hexo-starter https://github.com/hexojs/hexo-starter.gitSubmodule 'themes/landscape' (https://github.com/hexojs/hexo-theme-landscape.git) registered for path 'themes/landscape'Cloning into 'themes/landscape'...remote: Enumerating objects: 28, done.remote: Counting objects: 100% (28/28), done.remote: Compressing objects: 100% (25/25), done.remote: Total 1106 (delta 9), reused 13 (delta 2), pack-reused 1078Receiving objects: 100% (1106/1106), 3.23 MiB | 30.00 KiB/s, done.Resolving deltas: 100% (595/595), done.Submodule path 'themes/landscape': checked out '73a23c51f8487cfcd7c6deec96ccc7543960d350'INFO  Install dependenciesadded 183 packages from 420 contributors and audited 189 packages in19.021s8 packages are looking for funding  run `npm fund`for detailsfound 0 vulnerabilitiesINFO  Start blogging with Hexo!

初始化完成后的项目结构

36610188eb3aa1de26e358d7cff03eb6.png

3.修改_config.yml对博客进行基础配置

[root@localhost blog]# vim _config.yml# Sitetitle: zhangxiaoxing  #博客名字subtitle: ''description: ''keywords:author: zhangxiaoxing  #作者名language: entimezone: ''# Extensions## Plugins: https://hexo.io/plugins/## Themes: https://hexo.io/themes/theme: landscape  #主题名

4.启动

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

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

[root@localhost blog]# hexo gINFO  Validating configINFO  Start processingINFO  Files loaded in131 msINFO  Generated: archives/index.htmlINFO  Generated: archives/2020/index.htmlINFO  Generated: archives/2020/09/index.htmlINFO  Generated: index.htmlINFO  Generated: img/favicon.pngINFO  Generated: img/logo.pngINFO  Generated: photoswipe/default-skin/default-skin.pngINFO  Generated: js/typed.jsINFO  Generated: 2020/09/05/hello-world/index.htmlINFO  Generated: photoswipe/photoswipe-ui-default.min.jsINFO  Generated: photoswipe/photoswipe.cssINFO  Generated: photoswipe/default-skin/default-skin.cssINFO  Generated: css/diaspora.cssINFO  Generated: photoswipe/default-skin/default-skin.svgINFO  Generated: photoswipe/default-skin/preloader.gifINFO  Generated: js/diaspora.jsINFO  Generated: photoswipe/photoswipe-ui-default.jsINFO  Generated: photoswipe/photoswipe.min.jsINFO  Generated: js/plugin.jsINFO  Generated: img/cover.jpgINFO  Generated: img/welcome-cover.jpgINFO  Generated: js/jquery.min.jsINFO  Generated: photoswipe/photoswipe.jsINFO  23 files generated in40 ms[root@localhost blog]# hexo sINFO  Validating configINFO  Start processingINFO  Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.

这时候就可以访问http://localhost:4000看一下基本样子了,如果是云上服务器要先开安全组766b2ecc826472f75116b7fde41f4a00.png

部署hexo到码云

gitee账号创建已经提前创建好了(没有的可以直接搜官网创一个账号),创建直接在官网创建就好了

1.新建仓库

在gitee右上角,找到+号,点击新建仓库

输入名称,选择公开

点击创建就好了

7034fbfa8db529ab0de0164685848a02.png

创建好后 复制项目地址

2.在_config.yml中配置Git

[root@localhost blog]# vim _config.ymldeploy:  type: git  repo: https://gitee.com/zhang-xiaoxing/blog.git  branch: master

3.发布到码云上

安装自动部署发布工具

[root@localhost blog]# npm install hexo-deployer-git --save

在配置文件中增加博客地址

[root@localhost blog]# vim _config.ymlurl: https://gitee.com/zhang-xiaoxing/blogroot: /blog

发布博客

[root@localhost blog]# hexo clean && hexo g && hexo d

首次发布需要在shell中输入账号和密码

4.Gitee Pages设置

在服务中选择Gitee Pages

07649732de9964a85b02e0cde7944dbe.png

c142234fece792ff2ee4194d93f91e84.png

稍等一会后,就可以访问了

https://zhang-xiaoxing.gitee.io/blog/

到这里简单的博客就搭建好了

886ace68ccd4c64640de835782d6b0e8.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值