开始用Hexo了

Hexo

Hexo 是一个基于Node.js的静态博客生成软件。特点是用户只用专心写文章就行,它负责转成静态网页。

安装

  1. 安装Node.js
  2. 安装Hexo: npm install -g hexo

    建立网站

  3. 选好一个文件夹,在命令行下进入cd myhexo
  4. 执行命令hexo init
  5. 完成,可以用hexo server看看效果

配置

基本配置

所有配置都在_config.yml文件里,我改了这些

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
title: C++编程
subtitle: 我的学习记录
description: 其实不止C++啦
author: Ramy.Mao
language: zh-CN
timezone: Asia/Shanghai

url: http://www.cpp-prog.com

permalink: :category/:title/

new_post_name: :year-:month-:day-:title.md

post_asset_folder: true #这样用hexo new的时候就会生成同名文件夹,可以放图片

theme: hexo-theme-hueman

#我用sftp上传,需要hexo-deployer-sftp
deploy:
type: sftp
host: www.cpp-prog.com
user: ymao
remotePath: /var/www/html
privateKey: id_rsa

换主题

自带的主题也很好,但是不折腾会死-_-
我看中了hexo-theme-hueman主题

  1. 进入themes文件夹,git clone https://github.com/ppoffice/hexo-theme-hueman.git
  2. 打开hexo-theme-hueman里的_config.yml
  3. 修改LOGO customize\logo\url
  4. 语法高亮 customize\highlight:可选项可以在source\css\_highlight路径下查看。我选了VisualStudio配色。
  5. 关注我 customize\social_links:从https://fontawesome.com中找图标,名称作为键值,右边写url

使用

执行hexo new 标题会在_posts下生成一个.md文件
写好内容后执行hexo g生成静态网页
执行hexo d上传到服务器

小坑

hexo-theme-hueman主题每篇文章不给个配图就不好看了,用{% asset_img 1.jpg 图片说明 %}这种方式插入图片。
写关于页面:hexo new page "about"
要搜索功能才有用得装个东西: npm install --save hexo-generator-json-content
RSS订阅功能:npm install hexo-generator-feed --save,然后在主配置里加上:

1
2
3
4
5
6
7
8
#RSS订阅
plugin:
- hexo-generator-feed
#Feed Atom
feed:
type: atom
path: atom.xml
limit: 20

最后在主题里加上链接就行