Hexo

使用Markdown语法写博客,可免去把文本转换成HTML的痛苦,因此对Markdown支持得好,是下面一切选择的前提。支持Markdown的博客工具之中,比较入眼的有ghost, Jekyll和hexo。

Hexo 初探

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

后台管理程序: hexo-admin

Local use vs deployment

This plugin was originally designed as a local editor – you run hexo locally, use hexo-admin to author posts, and then use hexo generate or hexo deploy to send the generated static HTML files up to github pages or some other static server.

However, hexo-admin can be run on your live blog, as long as you’re using a non-static hosting service such as Heroku, DigitalOcean, etc. Static hosting services such as Github pages and Surge.sh does not support running hexo-admin from your live site.
If you’re using Hexo admin from your live blog, you should definitely set up a password (see below) – otherwise anyone will be able to edit your content.

Quickstart

1. Setup hexo & create a blog

1
2
3
4
5
npm install -g hexo
cd ~/
hexo init my-blog
cd my-blog
npm install

2. Install the admin & start things up

1
2
3
npm install --save hexo-admin
hexo server -d
open http://localhost:4000/admin/

3. Profit!

The UI should be pretty discoverable – let me know if you can’t find something.

4. Password protection

If you’re using Hexo admin on your live server, you want some password
protection. To enable this, you just add a few config variables to your hexo
_config.yml:

1
2
3
4
admin:
username: myfavoritename
password_hash: be121740bf988b2225a313fa1f107ca1
secret: a secret something

The password_hash is the bcrypt hash of your password. The secret is used
to make the cookies secure, so it’s a good idea to have it be long and
complicated.

A utility in Hexo admin’s Settings can hash your password and generate the admin
section for you. Start Hexo and go to Settings > Setup authentification
and fill out your information. Copy the generated YAML into your _config.yml.

Once that’s in place, start up your hexo server and going to /admin/ will
require you to enter your password.

5. Custom post metadata

To add and edit your own post metadata with the admin interface, add the
metadata variable and your custom variables to your hexo _config.yml:

1
2
3
metadata:
author_id: defaultAuthorId
language:

You can provide default values that will be used to initialize the metadata
of a new post.

安装主题: Anatole

1
2
3
4
5
git clone https://github.com/Ben02/hexo-theme-Anatole.git themes/anatole
# 安装插件
npm install --save hexo-renderer-jade hexo-generator-archive
# _config.yml
theme: anatole

安装自动部署发布工具:hexo-deployer-git

安装:npm instal lhexo-deployer-git --save
配置:

1
2
3
4
5
6
7
# _config.yml
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: https://github.com/XXX/XXX.github.io.git
branch: master

发布到Github: hexo clean && hexo g && hexo d