安装

参考 文档 | Hexo

npm install -g hexo-cli
hexo init my-blog && cd my-blog
npm install

配置 Hexo

我们需要区分两个 _config.yml

After the installation of Hexo and NexT, you may found that there are two configuration files using by Hexo and both called _config.yml:

  1. The first one is under {% label info@site root directory %}, which contains Hexo’s config.
  2. The second one is under {% label primary@theme root directory %} (e.g. themes/next/_config.yml or node_modules/hexo-theme-next/_config.yml), which is provided by NexT and contains theme’s config.

Let’s call the first one – {% label info@Hexo config file %}, and the second one – {% label primary@NexT config file %}.1

编辑 _config.yml

title: "wsm 的小站"
# subtitle: ''
# description: ''
# keywords:
author: 'wsm'
timezone: 'Asia/Shanghai'
# url: https://example.com

theme: next
language: zh-CN
tags:
# - tag1
# - tag2

# 行号太丑了
highlight:
  line_number: false
  wrap: false
  hljs: true

# 设置每页最多文章数
index_generator:
  per_page: 20
archive_generator:
  per_page: 20

配置一键 sftp deploy

# 坑:Node.js 不支持 ed25519
ssh-keygen -m PEM -t rsa -C "hexo-update" -f hexo -N ""
npm install hexo-deployer-sftp --save
# 建议配置一个单独的低权限用户操作,注意配置好目录权限
sudo adduser hexouser --ingroup nogroup # 然后无脑回车
sudo su hexouser
cd && mkdir .ssh && nano .ssh/authorized_keys # 输入生成的公钥

mkdir hexo && exit
sudo ln /home/hexouser/hexo /var/www/hexo -s
# 示例:
deploy:
  type: sftp
  host: hostname
  user: username
  remotePath: "/home/hexouser/hexo"
  privateKey: "hexo" 

配置 NexT

git clone https://github.com/next-theme/hexo-theme-next themes/next
minify: true # 删除部分不需要文件
# 顶部菜单设置
menu: 
  home: / || home
  #about: /about/ || user
  tags: /tags/ || tags
  #categories: /categories/ || th
  archives: /archives/ || archive
  #schedule: /schedule/ || calendar
  #sitemap: /sitemap.xml || sitemap
  #commonweal: /404/ || heartbeat
# CDN 设置,采用支持 http2 的 bootcdn
sidebar:
  display: hide
vendors:
  plugins: custom
  custom_cdn_url: https://cdn.bootcdn.net/ajax/libs/${cdnjs_name}/${version}/${cdnjs_file}
# 代码高亮和复制键设置
codeblock:
  theme:
    light: stackoverflow-light
    dark: stackoverflow-dark
  copy_button:
    enable: true
    style: flat
# 关掉动画
motion: 
  enable: false

配置 Tag

参考 Adding «Tags» Page

Sitemap

npm install hexo-generator-sitemap --save
curl https://github.com/hexojs/hexo-generator-sitemap/raw/master/sitemap.txt -o sitemap_template.txt
curl https://github.com/hexojs/hexo-generator-sitemap/raw/master/sitemap.xml -o sitemap_template.xml
sitemap:
  path: 
    - sitemap.xml
    - sitemap.txt
  template: ./sitemap_template.xml
  template_txt: ./sitemap_template.txt
  rel: false
  tags: true
  categories: true

代码样式

$code-block {
  margin: 1em 1em;
  border-radius: 8px;
}
$figcaption {
  background: #666;
  color: #fff;
  font-family: $code-font-family;
}
// 然后把所有 figcaption  padding-left 改成 1em

数学公式

npm un hexo-renderer-marked
npm i hexo-renderer-markdown-it-plus
math:
  katex:
    enable: true
    copy_tex: true

Mermaid

npm install --save hexo-filter-mermaid-diagrams
mermaid:
  enable: true
  # Available themes: default | dark | forest | neutral
  theme:
    light: default
    dark: dark
highlight:
  exclude_languages:
    - mermaid