A Brief Tutorial to Build Homepage
Getting start
Overview
- Hexo
- Hexo is a fast, simple and powerful blog framework. You write posts in Markdown (or other markup languages) and Hexo generates static files with a beautiful theme in seconds.
- home
- NexT
- NexT is a high quality elegant theme for Hexo. It is crafted from scratch, with love.
Requirements
Installing Hexo is quite easy and only requires the following beforehand: - Node.js - Git
Install Hexo
Once all the requirements are installed, you can install Hexo with
npm: 1
npm install -g hexo-cli
If meet access errors, run the following code installed:
1
sudo npm install --unsafe-perm --verbose -g hexo
Initialize Hexo
Once Hexo is installed, run the following commands to initialize Hexo
in the target <site-folder>. 1
2
3
4cd <github>
hexo init <site-folder>
cd <site-folder>
npm install<site-folder> with
<username>.github.io. - Reminder: please run the code
above when there is no folder named as
<site-folder>.
Once initialized, here’s what your project folder will look like:
1
2
3
4
5
6
7
8.
├── _config.yml
├── package.json
├── scaffolds
├── source
| ├── _drafts
| └── _posts
└── themes
Install NexT Theme
If you're using Hexo 5.0 or later, the simplest way to install is
through npm. Open your Terminal, change to Hexo site
root directory and install NexT theme: 1
2cd <site-folder>
npm install hexo-theme-next
Config File
- Prepare the NexT config file
1
2# Installed through npm
cp node_modules/hexo-theme-next/_config.yml _config.next.yml - Edit Hexo config file. Open
_config.yml, and edit1
2
3
4
5
6
7title: This is title
subtitle: This is subtitle
description: This is description
keywords:
author: Alice Bob
language: en # zh-CN
timezone: ''1
2
3# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
url: http://<username>.github.io #http://example.com1
2
3
4# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: next1
2
3
4
5
6
7# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: git
repo: https://github.com/<username>/<username>.github.io
# example, https://github.com/hexojs/hexojs.github.io
branch: gh-pages - Install
hexo-deployer-git.1
npm install hexo-deployer-git --save
- Edit NexT config file. Open
_config.next.yml.- choose your preferred scheme by deleting the
#before the scheme and add#befor others.1
2
3
4
5
6
7
8
9# Schemes
# scheme: Muse
#scheme: Mist
scheme: Pisces
#scheme: Gemini
```
2. You can run the code to preview your website locally.
```bash
hexo server
- choose your preferred scheme by deleting the
Setup Deployment
- Create a repo named
<username>.github.io, where<username>is your username on GitHub. If you have already uploaded to other repo, rename the repo instead. - Push the files of your Hexo folder to the default branch of your
repository. The default branch is usually main, older
repository may use master branch.
- The
public/folder is not (and should not be) uploaded by default, make sure the.gitignorefile containspublic/line.
- The
- Check what version of Node.js you are using on your local machine
with
node --version. Make a note of the major version (e.g.,v16.y.z) - Create
.github/workflows/pages.ymlin your repo with the following contents (substituting16to the major version of Node.js that you noted in previous step):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
35
36name: Pages
on:
push:
branches:
- main # default branch
jobs:
pages:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
# If your repository depends on submodule, please see: https://github.com/actions/checkout
submodules: recursive
- name: Use Node.js 16.x
uses: actions/setup-node@v2
with:
node-version: '16'
- 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 - One-command deployment Run
1
hexo clean && hexo deploy
- Once the deployment is finished, the generated pages can be found in
the
gh-pagesbranch of your repository. - In your GitHub repo’s setting, navigate to Settings >
Pages > Source. Change the branch to
gh-pagesand save. - Check the webpage at username.github.io.
Customize Your Site
1 | cd <site-folder> |
Add an Avatar
- Create folder
source/uploads. - Save your avatar image
avatar.pnginsource/uploads. - Edit
_config.next.yml#### Add1
2
3
4
5
6
7
8# Sidebar Avatar
avatar:
# Replace the default image and set the url here.
url: /uploads/avatar.png
# If true, the avatar will be displayed in circle.
rounded: false
# If true, the avatar will be rotated with the cursor.
rotated: falseaboutmenu If you want to addaboutmenu andaboutpage, - Run the code
1
hexo new page about
- Open
source/about/index.md, and write something you want. - Open
_config.next.yml, add theabout:code inmenu:1
2menu:
about: /about/ || fa fa-user
Add tags menu
If you want to add tags menu, 1. Run the code
1
hexo new page tags
source/tags/index.md, and add
type: tags 1
2
3
4
5---
title: tags
date: 2022-11-11 19:56:45
type: tags
---_config.next.yml, add the tags: code in
menu: 1
2menu:
tags: /tags/ || fa fa-tags
Add categories Menu
If you want to add categories menu, 1. Run the code
1
hexo new page categories
source/tags/index.md, and add
type: tags 1
2
3
4
5---
title: categories
date: 2022-11-11 20:41:43
type: categories
---_config.next.yml, add the categories: code in
menu: 1
2menu:
categories: /categories/ || fa fa-th
Create a custom homepage
- Remove the hexo-generator-index package
1
2npm remove hexo-generator-index
npm remove hexo-generator-index-pin-top - You can now put your index page in
/source/index.md.1
2
3
4
5---
layout: page
title: homepage
permalink: index.html
--- - Open
_config.next.yml,1
2
3
4# index_generator:
# path: about
# per_page: 0
# order_by: -date
Maintain Homepage
Hexo Command
one command deploy
Each time you edit your homepage, and want to deploy, you can run the
following code. 1
hexo clean && hexo deploy
1
hexo clean && hexo d
preview website
If you want to preview your website locally, you can run
1
hexo server
1
hexo clean && hexo g && hexo s
Writing Articles
new article
1 | hexo new <post-name> |
Then, you can write your article in the file
source/_posts/<post-name>.md.
article folding in home page
Add the following code just after what you want to show on the index
page in your article **.md. 1
<!-- more -->
tags
1 | tags: [tag1,tag2] |
or 1
2
3tags:
- tag1
- tag2
categories
1 | categories: |
or multiple catecories: 1
2
3
4
5categories:
- [cate1, cate1-1, cate1-1-1]
- [cate1, cate1-2]
- [cate2, cate2-1]
- cate3
math equation
- Open
_config.next.yml, and editWe choose mathjax as our render engine. > - For now, NexT provides two rendering engines for displaying Math Equations: MathJax and KaTeX. > - MathJax is a JavaScript display engine for mathematics that works in all browsers. It is highly modular on input and output. Use MathML, TeX, and ASCIImath as input and produce HTML+CSS, SVG, or MathML as output. > - KaTeX is a faster math rendering engine compared to MathJax 3. And it could survive without JavaScript. But, for now KaTeX supports less features than MathJax. Here is a list of TeX functions supported by KaTeX.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16# Math Formulas Render Support
math:
# Default (false) will load mathjax / katex script on demand.
# That is it only render those page which has `mathjax: true` in front-matter.
# If you set it to true, it will load mathjax / katex script EVERY PAGE.
every_page: false
mathjax:
enable: true
# Available values: none | ams | all
tags: none
katex:
enable: false
# See: https://github.com/KaTeX/KaTeX/tree/master/contrib/copy-tex
copy_tex: false - Then you need to uninstall the original renderer
hexo-renderer-marked, and installhexo-renderer-pandoc:1
2npm un hexo-renderer-marked
npm i hexo-renderer-pandoc - pandoc is required for hexo-renderer-pandoc, here's how to install pandoc.
- Numbering and Referring Equations in MathJax
- NexT v6.3.0 has added feature to automatic equation numbering with opportunity to make reference to that equations.
- To enable this feature, you need to set
mathjax.tagstoamsin_config.next.yml.1
2
3
4
5math:
mathjax:
enable: true
# Available values: none | ams | all
tags: ams
If this is your first time inserting math equations, please see
Prepare first. 1. Insert to your
<post-name>.md 1
mathjax: true
\(x+y\) or \[x+y\]
images
- Create a folder named
<post-name>which is the same as your article<post-name>.md- or you can edit
_config.ymlThen, each time you1
post_asset_folder: true
hexo new <post-name>, there will be a folder named<post-name>created at the same time
- or you can edit
- save your
<image-name>.jpgin folder./source/_posts/<post-name>/1

- Reminder: using this method, you won't have a correct
image preview on your home page. So please insert your image after
<!-- more -->
- Reminder: using this method, you won't have a correct
image preview on your home page. So please insert your image after
add tabs
- usage. (see
details)
1
2
3
4
5{% tabs Unique name, [index] %}
<!-- tab [Tab caption] [@icon] -->
Any content (support inline tags too).
<!-- endtab -->
{% endtabs %} - examples
ex
1
2
3
4
5
6
7
8
9
10
11
12
13{% tabs First unique name, -1 %}
<!-- tab -->
**This is Tab 1.**
<!-- endtab -->
<!-- tab -->
**This is Tab 2.**
<!-- endtab -->
<!-- tab haha -->
**This is Tab 3.**
<!-- endtab -->
{% endtabs %}This is Tab 1.
This is Tab 2.
This is Tab 3.
Upgrading
upgrading NexT
1 | cd <hexo-site> |