Blog Upgrade Log for Next Theme Version 7.7
I've been writing blogs for almost a year now, and the Next theme has gone through many updates. The addition of pjax is really fantastic, so I decided to update it. By the way, I also transferred my blog's local directory from Windows to macOS.
This post was translated from my Chinese blog post with the aid of ChatGpt.
Update Notes
The changes from Next theme version 7.1 to 7.7.2 are quite significant. Upgrading directly may lead to various minor issues. Therefore, this update involves a fresh installation.
Version Comparison
Hexo version before the upgrade:
1 | hexo: 3.8.0 |
Hexo version after the upgrade:
1 | hexo: 4.2.0 |
New Features
- PJAX (Partial Page Refresh Loading)
- Dark Mode (Supports system-level dark mode like on Mac)
- Gitalk Comments (Added a comment system after Gitment was discontinued)
- Mediumzoom (Image plugin)
- Language Switching (New)
- CDN Integration
- Echarts Integration
Removed Features
- Dynamic Background (High resource consumption, causing lag, overheating, and fast battery drain on mobile and tablet devices)
- i18n-generator (Haven’t written any English blogs for a year, and this solution had significant flaws)
- NetEase Cloud Music Widget (Very low usage frequency, slowing down page loading)
Retained Features
- Site Search
- Word Count and Reading Time Statistics
- Website Uptime
- Loading Progress Bar
- Crash Deception
- Background Images
- Mouse Click Effects
- Busuanzi (Page view counter)
- Live2D Virtual Assistant
MacOS Configuration Process
Install Software Dependencies
First, download and install git
and node.js
from the official websites:
Once installed, open the terminal and enter the following commands one by one to check if they were installed successfully:
1 | git --version |
A successful installation will display the software version numbers.
Configure Local Directory
- Create a folder to store your blog files.
- Open a terminal window at the location of the folder.
- Enter
npm install hexo -g
to install Hexo.- This step might encounter errors. If so, use the command
sudo npm install --unsafe-perm --verbose -g hexo
to install Hexo.
- This step might encounter errors. If so, use the command
- Enter
npm install
to install other dependencies. - Enter
npm install hexo-deployer-git --save
to install the deployment plugin. - Enter
hexo v
to check if the installation was successful. A successful installation will return the Hexo version number.
Configure SSH
- Open the terminal.
- Enter
ls -al ~/.ssh
to check if you have previously generated SSH Keys. If not, continue. - Enter
ssh-keygen -t rsa -C "YourGitHubEmailAddress"
and press Enter three times. - The terminal will display the path where the files were generated. Find and open
id_rsa.pub
. - Copy all the contents from the file.
- Open GitHub, click on your profile picture in the top right corner, and select
Settings
. - Open
SSH and GPG keys
, click on the top-rightNew SSH key
button. - Fill in a
Title
(can be anything) and paste the copied key intoKey
. - Click
Add SSH key
. - Back in the Git bash, enter
ssh -T git@github.com
and press Enter. - The first time you enter, you may receive a prompt. Type
yes
and press Enter. - Success will display:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
- Enter
git config --global user.name "YourUsername"
. - Enter
git config --global user.email "YourEmailAddress"
.
Install the Next Theme
In the terminal, enter the following command to install the latest Next theme:
1 | git clone https://github.com/theme-next/hexo-theme-next themes/next |
Customizing the Next Theme
I won’t go into detail about configuring Hexo, as it can be done based on your existing _config.yml
. Instead, let’s focus on customizing the Next theme.
Separating Configuration Files
Starting from Next theme version 7.3, configuration files have been separated from the main theme. For details, please refer to Xiao Ding’s Personal Blog.
- Create a new folder:
hexo/source/_data
. - Copy
./themes/next/_config.yml
to thehexo/source/_data
directory and rename it tonext.yml
. - Set
override
totrue
withinnext.yml
to use it as the theme’s configuration file. - In
hexo/source/_data
, createbody-end.swig
andstyles.styl
files. - Remove the
#
from thecustom_file_path
innext.yml
to enablebodyEnd
andstyle
. - Depending on your needs, create and enable other files in the
custom_file_path
section ofnext.yml
.
Pjax
Pjax is an Ajax-based plugin that enables partial page loading without full refresh, which sounds great. However, it has some minor issues:
- When using Mediumzoom, images don’t load when navigating from the archive to a blog post. You need to refresh the page to load them.
- Echarts charts don’t display until a page is refreshed; otherwise, they remain blank.
To install Pjax, use the following command:
1 | git clone https://github.com/theme-next/theme-next-pjax source/lib/pjax |
In your next.yml
configuration file, search for pjax
and set it to:
1 | pjax: true |
Dark Mode
The Next theme has introduced a dark mode feature that can be synchronized with your system’s dark theme settings.
In your next.yml
configuration file, search for darkmode
, and set it to auto
. This setting will enable automatic switching between light and dark modes based on your system’s theme.
Gitalk Comments
Gitalk is a commenting system. Initially, I thought about using Valine, but it required real-name authentication, so I decided against it.
Here’s how to set up Gitalk comments:
- Create a new GitHub repository named
gitalk-comment
to store issues generated for comments. - Click on your GitHub profile picture in the upper right, go to
Settings
, thenDeveloper settings
, and finallyOAuth Apps
. - Fill in the
Application name
field with any name. - For both
Homepage URL
andAuthorization callback URL
, enter your blog’s address. - Click
Register application.
- In your
next.yml
configuration file, search forgitalk
. - Copy the obtained
Client ID
andClient Secret
and paste them into their respective fields. - Set
enable
totrue
. - Set
github_id
andadmin_user
to your username. - Set
repo
to the name of the repository you created earlier, which isgitalk-comment
. distraction_free_mode
is a feature similar to Facebook’s comment overlay.
The specific configuration in next.yml
is as follows:
1 | # Gitalk |
Mediumzoom
This plugin emulates the image viewing behavior found on Medium.com.
To install, run the following command:
1 | npm install medium-zoom |
In your next.yml
configuration file, search for mediumzoom
, and set it to:
1 | mediumzoom: true |
Bilingual Switching (Chinese and English)
Please refer to another blog post for information on enabling bilingual switching in Hexo Next 7.7: Hexo Next 7.7 Bilingual Switching
Local Site Search
This feature allows you to search for content within your blog.
To install, run the following command:
1 | npm install hexo-generator-searchdb |
In your next.yml
configuration file, search for local_search
, and set it to:
1 | enable: true |
Word Count and Reading Time Statistics
To enable word count and reading time statistics, you can install the following plugin:
1 | npm install hexo-symbols-count-time |
In your root _config.yml
file, add the following configuration:
1 | symbols_count_time: |
Then, in your next.yml
configuration file, search for symbols_count_time
, and set it to:
1 | symbols_count_time: |
Adding jQuery
The newer version of the Next theme has removed jQuery, which may affect some of your custom settings. You can add jQuery back by following these steps:
- Copy the jQuery file from the older version of the Next theme or download it from the official jQuery website. The file path should be like this:
./hexo/themes/next/source/libs/jquery/jquery-2.2.0.min.js
. - Place the jQuery file in the
./hexo/source/js
directory. - In your
./hexo/source/_data/body-end.swig
file, add the following code. Be sure to adjust the version if necessary:1
2<!-- jQuery -->
<script type="text/javascript" src="/js/jquery-2.2.0.min.js"></script>
Website Uptime
To display the website’s uptime, open the ./hexo/themes/next/layout/_partials/footer.swig
file and add the following code:
1 | <div> |
Loading Progress Bar
Display the loading progress bar for the current webpage.
Installation:
1 | git clone https://github.com/theme-next/theme-next-pace source/lib/pace |
In the next.yml
file, search for Progress bar in the top during page loading
and set it to:
1 | pace: |
Crash Deception
Add a crash deception effect to the webpage title. The title will change when leaving the page and revert to normal when returning. This feature requires jquery.
Create a new file named crash_cheat
in ./hexo/source/js
and copy the following code:
1 | <!--Crash Deception--> |
Then, add the following code to ./hexo/source/_data/body-end.swig
:
1 | <!--Crash Deception--> |
Background Image
Place the background image in ./hexo/themes/next/source/images
and name it background.jpg
. Then, add the following code to ./hexo/source/_data/styles.styl
:
1 | body { |
Mouse Click Effects
According to Xiaoding’s personal blog, the mouse click effect has been changed to be more friendly for low-performance devices. Create a new file named fireworks.js
in ./hexo/themes/next/source/js/cursor
and add the following code.
1 | class Circle { |
Then, add the following code to ./hexo/source/_data/body-end.swig
:
1 | {# Mouse Click Effects #} |
In next.yml
, add the following:
1 | # Mouse Click Effects |
Busuanzi
Next comes with built-in Busuanzi statistics. In next.yml
, search for busuanzi_count
and set it to:
1 | enable: true |
Customizing Single Line Code Color
To customize the color of single-line code in ./hexo/source/_data/styles.styl
, add the following CSS code:
1 | code { |
Live2D Virtual Assistant
Using the example of the tororo
model I have installed, for other models, please refer to the official documentation.
Installation:
1 | npm install --save hexo-helper-live2d |
In your next.yml
file, search for the section labeled “Progress bar in the top during page loading” and configure it as follows:
1 | live2d: |
This configuration will enable Live2D with the tororo
model and display it on the right side of the page with the specified width and height. Adjust the configuration as needed for your specific use case or model.
Echarts
Echarts is a visualization chart library developed by Baidu. It’s important to note that there might be conflicts with Echarts when using PJAX, and a page refresh may be required to successfully load Echarts. Some Google search results suggest modifying PJAX to resolve this issue, but due to limited expertise, I was unable to successfully implement this solution.
If you have installed a plugin that uses Echarts 4.3, some charts may not display correctly. In such cases, manual modifications may be needed to update Echarts to the latest version. To do this, you can visit the ECharts official website and open any example. Then, use your browser’s console to find the URL of the latest JavaScript file and replace it.
To make these changes, open ./hexo/node_modules/hexo-tag-echarts4/template.html
and modify the line <script src="https://cdn.bootcss.com/echarts/4.3.0/echarts.common.min.js"></script>
to <script src="https://www.echartsjs.com/examples/vendors/echarts/echarts.min.js?_v_=1584687926098"></script>
.
Additionally, some map-based charts may require the inclusion of map-related JavaScript files. You can find these URLs by inspecting the page with your browser’s console and then add them to ./hexo/node_modules/hexo-tag-echarts4/template.html
. For example, for China map and world map:
1 | <script src="https://www.echartsjs.com/examples/vendors/echarts/map/js/china.js?_v_=1584687926098"></script> |
In summary, you should add any missing components as needed.
Installation
1 | npm install hexo-tag-echarts4 --save |
Usage
You can specify the chart’s height and width in your content. For example, to create a chart with a height of 400px and a relative width of 85%, you can use the following syntax:
1 | {% echarts 400 '85%' %} |
If you don’t specify the dimensions, the default values are a height of 400px and a width of 81%.
Example:
1 | {% echarts %} |
Abandoned on 2022.5.13
CDN
GitHub’s servers are located outside of China, which can result in significantly longer loading times when accessing websites from within China. However, you can effectively alleviate this issue by using CDN acceleration.
Here are the steps to set up CDN acceleration:
- Log in to Cloudflare.
- Enter your domain name and click on
Add site.
- Choose a plan; the
free
plan is sufficient. - Click
Confirm plan
. - Cloudflare will scan your DNS records, and after a moment, it will display your domain’s current resolution records.
- Click
Continue
. - Visit your domain name service provider’s website and replace the original servers with the two DNS servers provided by Cloudflare.
- Once you’ve completed this step, return to Cloudflare and click
Done, check nameservers
. - Now, patiently wait for the changes to take effect. You will receive a notification email when they do.
- While waiting, you can configure some settings.
- SSL/TLS Options:
- Set the Mode to the default
Full
. - Turn on
Always Use HTTPS
. - Turn on
Opportunistic Encryption
. - Turn on
Authenticated Origin Pills
.
┏(^0^)┛
Reference: Xiaoding’s Personal Blog