Hexo博客教程

笔记

命令

hexo new "postName" # 新建文章
hexo new page "pageName" # 新建页面
hexo generate # 生成静态页面至public目录
hexo server # 开启预览访问端口(默认端口4000,'ctrl + c'关闭server)
hexo deploy # 部署到GitHub
hexo help # 查看帮助
hexo version # 查看Hexo的版本

按文章更新时间排序

# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
# order_by: Posts order. (Order by date descending by default)
index_generator:
path: ''
per_page: 10
order_by: -updated # 默认是-date

背景设置

把你挑选的背景图片命名为:background.jpg,放在blog\themes\next\source\images里,在blog\themes\next\source\css_custom文件的custom.styl首部添加

body {
background:url(/images/background.jpg);
background-attachment: fixed;
}

符号链接

# Windows,有些文件需要文件名相同才能打开
# -d 目录符号链接
mklink /d C:\file\path\Target C:\file\path\Source

安装主题

  1. npm安装在modules下
cd hexo-site
npm install hexo-theme-next
  1. git clone安装
cd hexo-site
git clone https://github.com/next-theme/hexo-theme-next themes/next
# Upgrade
cd themes/next
git pull origin master
# Configuration
cp themes/next/_config.yml _config.next.yml

Hexo

我的配置

# 设置英文字体
global:
family: Source Serif Pro

# layout\_partials\head\head.njk 设置中文字体
{{ next_font() }}
{{ next_vendors('fontawesome') }}
<link href="https://fonts.googleapis.com/css?family=Noto+Serif+SC&display=swap" rel="stylesheet">
# source\css\_variables 添加中文字体
$font-family-chinese = "Noto Serif SC"

codes:
family: IBM Plex Mono

codeblock:
theme:
light: stackoverflow-light

Quick Start

npm install hexo-cli -g
hexo init blogFolderName
cd blog
npm install
hexo server

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Create a new post

$ hexo new "My New Post"

More info: Writing

Run server

$ hexo server

More info: Server

Generate static files

$ hexo generate

More info: Generating

Deploy to remote sites

$ hexo deploy

More info: Deployment