Hexo Blog
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.
Quick Start
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
Install Hexo
Mac Install Homebrew
Install homebrew: 1
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
For Chinese mainland: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#Update Homebrew
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
#Update Homebrew-core
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
#Update Homebrew-cask(Last but not least)
cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
# If using zsh
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/' >> ~/.zshrc
source ~/.zshrc
update homebrew: 1
brew update -v
Install Hexo
Install Hexo and create a blog folder:
1 | brew install hexo |
cd blog and edit the last line of
_config.yml about github configuration:
1 | deploy: |
Install Next:
1 | git clone https://github.com/next-theme/hexo-theme-next.git themes/next |
Edit _config.yml, change theme: landscape
to theme: next
1 | npm install hexo-deployer-git --save |
Change Font:
Change Font to Noto Serif SC
1 | font: |
Change Font Size
Issue: Font size change ineffective
When modifying the font size in Hexo NexT, even though the default
size is set to 1em (16px), the actual body font appears
larger, at around 1.125em (18px).
After some research, I discovered that besides modifying font styles
and sizes in themes/next/_config.yml, there is another key
file controlling the font size:
themes/next/source/css/_variables/base.styl.
Below is the default configuration in base.styl:
1 | // Font size |
Change font size base
Even though the body font size was supposed to be 1em,
it appeared larger. Adjusting $font-size-base to
0.9em worked as a temporary solution.
The body font size on the webpage was 1.125em. Searching
for occurrences of 1.125em in the themes
folder pointed to the $font-size-large variable in the
above configuration. Searching for font-size-large led me
to the file:
themes/next/source/css/_common/components/post/post.styl.
The relevant section of the file is shown below:
1 | .post-body { |
Lines 5-7 configure the body text size using
$font-size-large by default. Changing this to
$font-size-medium solved the problem.
Change Code Block Font Size
To adjust the font size of code blocks, modify the
table-font-size in the
themes/next/source/css/_variables/base.styl file. Setting
it to 80% scales the code block font size to 80% of the main body font
size:
1 | // Table |
By modifying this configuration, the code block font size adjusts relative to the main font size.
Add Search Function
Run the following command to install the
hexo-generator-searchdb plugin:
1 | npm install hexo-generator-searchdb --save |
Then, find the Local Search section in the NexT
theme configuration file and set enable to
true:
1 | # Local Search |
Modify Link Styles
To customize the link styles, open the file:
themes/next/source/css/_common/components/post/post.styl
Add your desired styles at the end of the file.
Hexo LaTeX Support
Uninstall hexo-math Run the following
command to remove the hexo-math plugin:
1 | npm un hexo-math |
Switch to an Alternative Renderer
Uninstall the default renderer and install
hexo-renderer-pandoc:1
2npm un hexo-renderer-marked
npm i hexo-renderer-pandocInstall Pandoc on macOS (if not already installed):
1
brew install pandoc
Update hexo/_config.yml
Add the following configuration at the end of your Hexo configuration file:
1 | math: |
Update next/_config.yml
Modify the math settings in the NexT theme configuration
file:
1 | # Math Formulas Render Support |
Important Notes:
If per_page is set to false, add
mathjax: true to the front-matter of your Markdown files to
enable MathJax for specific pages. For example: 1
2
3
4
title: Example
mathjax: true
Commnet
Go to https://disqus.com/profile/signup/ , register and create a site, copy the short name
add disqus to active, and paste the short name
1 | # Multiple Comment System Support |
Encrypt
Encrypt Blog using Hexo-Blog-Encrypt
1 | npm install --save hexo-blog-encrypt |
Edit _config.yaml
1 | # Security |
Just need to add a prefix in the blog post:
1 | --- |
Deploy Hexo to Ubuntu
Git Prepare
Install Git:
1 | sudo apt-get install git-core |
Create a bare git repository
1 | mkdir ~/hexo |
Deploy using Nginx
Assume nginx is alreay installed, so create a website directory
1 | sudo mkdir -p /var/www/blog.yixingfu.net/html |
Create a git hook
1 | vim ~/hexo/hexo_static.git/hooks/post-receive |
put in the code below:
1 |
|
and make it executable
1 | chmod +x /home/ubuntu/hexo/hexo_static.git/hooks/post-receive |
create ssh file and put local public key into it
1 | mkdir ~/.ssh |
1 | sudo vim /etc/nginx/sites-available/blog.yixingfu.net |
Paste in the following configuration block, which is similar to the default, but updated for our new directory and domain name:
1 | server { |
Next, let’s enable the file by creating a link from it to the
sites-enabled directory, which Nginx reads from during
startup:
1 | sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/ |
Next, test to make sure that there are no syntax errors in any of your Nginx files:
1 | sudo nginx -t |
If there aren’t any problems, restart Nginx to enable your changes:
1 | sudo systemctl restart nginx |
Secure Nginx with Let's Encrypt
1 | sudo certbot --nginx -d example.com |