博客初始化

生成使用hexo,主题使用next。部署在github pages。

hexo

安装

安装nodejs,选择LTS版本

安装hexo

1
npm install hexo

初始化

参考:建站

1
2
3
hexo init <folder>
cd <folder>
npm install

基本配置

编辑模板:scaffolds/posts.md

1
2
3
4
5
6
7
8
9
---
title: {{ title }}
date: {{ date }}
updated: {{ date }}
categories:
- 计算机
tags:
- 未分类
---

文件名YYYYMMDD_title.md:_config.yml

1
new_post_name: :year:month:day_:title.md # File name of new posts

next

文档:Getting Started | NexT (theme-next.js.org)

安装

1
2
cd <folder>
npm install hexo-theme-next

配置

生效

_config.yml

1
theme: next

next配置文件初始化

需要建立文件_config.next.yml,同时赋予默认值

1
cp node_modules/hexo-theme-next/_config.yml _config.next.yml

选择Genimi主题及暗黑风格

1
2
scheme: Gemini
darkmode: true

显示tags

_config.yml禁止:

1
2
tag_generator:
enable_index_page: false

新建tags页面:

1
hexo new page tags

修改tags页面source/tags/index.md的type为tags

1
2
3
4
5
---
title: tags
date: 2023-10-11 12:24:52
type: tags
---

显示categories

新建categories页面:

1
hexo new page categories

修改categories页面source/categories/index.md的type为categories

1
2
3
4
5
---
title: categories
date: 2023-10-11 12:24:52
type: categories
---

停止动画

_config.next.yml:

1
2
motion:
enable: false

备案号

_config.next.yml:

1
2
3
beian:
enable: true
icp: "XXXXXXXXX"

since

_config.next.yml:

1
2
footer:
since: "2023"

部署

参考:在 GitHub Pages 上部署 Hexo | Hexo

自定义域名

添加文件:source/CNAME:

1
www.mytips.cn

GitHub Actions

添加文件:.github/workflows/pages.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
25
26
27
28
29
30
31
32
33
34
name: Pages

on:
push:
branches:
- main # default branch

jobs:
pages:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v2
- name: Use Node.js v18.x
uses: actions/setup-node@v2
with:
node-version: "18"
- name: Cache NPM dependencies
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.OS }}-npm-cache
restore-keys: |
${{ runner.OS }}-npm-cache
- name: Install Dependencies
run: npm install
- name: Build
run: npm run build
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public