我用Hexo写博客

声明: 本文禁止转载,发布地址为我的 个人博客知乎专栏,其它地方看到均为抄袭。

基本介绍

Hexo 是一款简单、快速、强大的 node.js 静态博客框架。

npm 是 node.js 的包管理工具,我们通过使用 npm 来安装 Hexo。

node.js 和 npm 安装这里不再赘述,网上有很多教程,提醒的是需要到官网下载新版的安装包,直接通过 apt-get 安装的版本太低。

npm 官方镜像一般连接速度太慢,我都是通过淘宝的 npm 镜像安装的,地址和使用方式如下。

npm.taobao.org/

直接使用:npm install -g cnpm --registry=registry.npm.taobao.org

alias使用:

alias cnpm="npm --registry=https://registry.npm.taobao.org \
--cache=$HOME/.npm/.cache/cnpm \
--disturl=https://npm.taobao.org/dist \
--userconfig=$HOME/.cnpmrc"
# Or alias it in .bashrc or .zshrc
$ echo '\n#alias for cnpm\nalias cnpm="npm --registry=https://registry.npm.taobao.org \
  --cache=$HOME/.npm/.cache/cnpm \
  --disturl=https://npm.taobao.org/dist \
  --userconfig=$HOME/.cnpmrc"' >> ~/.zshrc && source ~/.zshrc

Hexo安装,-g 全局安装

npm install hexo -g

博客创建

hexo init noogel

扩展插件安装

sudo npm install hexo-server --save --registry=https://registry.npm.taobao.org
sudo npm install hexo-admin --save --registry=https://registry.npm.taobao.org
sudo npm install hexo-generator-archive --save --registry=https://registry.npm.taobao.org
sudo npm install hexo-generator-feed --save --registry=https://registry.npm.taobao.org
sudo npm install hexo-generator-search --save --registry=https://registry.npm.taobao.org
sudo npm install hexo-generator-tag --save --registry=https://registry.npm.taobao.org
sudo npm install hexo-deployer-git --save --registry=https://registry.npm.taobao.org
sudo npm install hexo-generator-sitemap --save --registry=https://registry.npm.taobao.org

之后新的机器部署环境可以直接

sudo npm install --registry=https://registry.npm.taobao.org

会自动读取 package.json 文件进行安装

Hexo服务启动

有如下两种命令

hexo serve
hexo s -g

一键发布到 git

修改 _config.yml 配置

## Docs: https://hexo.io/docs/deployment.html
deploy:
  # 类型
  type: git
  # 仓库
  repo: git@github.com:noogel/noogel.github.io.git
  # 分支
  branch: master

发布命令

hexo d -g

清除发布结果

hexo clean

组合命令:alias hexod="hexo d -g && hexo clean"

添加tags

执行 hexo new page "tags",然后编辑 source/tags/index.md

配置修改

博客配置修改 _config.yml,主题配置修改 themes/<themes>/_config.yml

Hexo自动提交命令

这里设置了一个自动提交的命令,源码自动提交到 sources 分支

alias hexodp="hexo d -g && git add --all && git commit -am 'auto commit' && git push origin sources"

hexo-admin 管理文章

安装

npm install --save hexo-admin --registry=https://registry.npm.taobao.org

打开 localhost:4000/admin/

然后可以在里面配置登录账号密码,并添加到 _config.yml 文件中

# hexo-admin authentification
admin:
  username: noogel
  password_hash: $2a$10$CMR/GX.e6TuoGGOYOF7ks.R.WmSUC8RvelPPXIH5wV3S6hPLYPnx6
  secret: a33x8sd83ndfus82jrfi8sj28djk438ds

预览界面如下:

b46bdb3fc82e1081adeda50071e18c26.png

Hexo常见问题解决办法

hexo.io/docs/troublesho
hexo 先介绍到这里,我的个人博客地址 Noogle's notes ,欢迎大家到评论区进行交流~~
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值