Next Theme Customization (Version 7.10)
The blog theme has been changed to Next. This blog post is only applicable to the Next 7.10 theme.
To save github storge space, I won’t include images in this post (it’s definitely not because I’m lazy).
Contents:
- Installation of the Next theme
- Configuration of the Next theme
- Advanced customization of the Next theme
Note: This method is not applicable to newer versions of the Next theme.
This post was translated from my Chinese blog post with the aid of ChatGpt.
Installing the Next Theme
Installing the Next theme is similar to the Flash theme. Simply clone it into your blog’s folder using the following command:
1 | git clone https://github.com/theme-next/hexo-theme-next themes/next |
Since the Next theme is relatively lightweight, it should install quickly. However, because the Next theme is frequently updated, it’s a good idea to add an update command as well:
1 | cd themes/next |
After the installation, go to the _config.yml
file in the root directory and add next
after theme:
to activate the Next theme.
Configuring the Next Theme
After the installation, further configuration is required for the theme.
Configuration in the Root _config.yml
Site Settings
1 | # Site |
URL Bar Settings
1 | # URL |
url:
should be filled with the second-level domain of your blog on Github, such as https://Siriusq.github.io
.
permalink:
is the path name used when generating blog pages, usually :year/:month/:day/:title/
.
Pagination Settings
There are two places where you can control the number of blog posts displayed on each page.
1 | # Home page setting |
Set the desired number of blog posts after per_page:
. Setting it to 0 means displaying all posts on a single page without pagination.
Deployment Settings
1 | # Deployment |
After branch:
, enter master
.
Replace the username
after repo:
with your own username.
Configuration in the _config.yml
file located in the theme directory
Many configurations in the file start with #
. Remove the #
to activate the option.
Website Logo Settings
1 | favicon: |
Place the chosen logo in the \themes\next\source\images
directory and rename it to the specified file name. Pay attention to the image dimensions.
Footer Settings
1 | footer: |
since:
represents the year when the website was established. If not set, it defaults to the current year and displays as “© 2019.”
icon:
allows you to set the icon after the year. By default, it’s a heart shape. If you want to change it, go to Fontawesome, choose an icon, and modify the name
field.
animated:
is used to control whether the heart icon beats.
color:
is used to set the color of the icon. You can find color references online.
copyright:
is the copyright owner or author’s name to be displayed after the icon. If not set, it defaults to the author name in the root configuration file.
powered:
The section afterward is used to determine whether to display “Powered by Hexo” and the current theme’s version information. Set it to true
to display.
theme:
The section afterward is used to determine whether to display the current theme’s version information. Set it to true
to display.
Copyright Info
1 | creative_commons: |
license:
is used to set the copyright standard. You can check Creative Commons for specific licensing types and examples.
sidebar:
is used to determine whether to display the copyright standard in the sidebar.
post:
is used to determine whether to display copyright information at the bottom of articles.
GitHub Banner
1 | # `Follow me on GitHub` banner in the top-right corner. |
After permalink:
, fill in your GitHub address.
title:
is used to set the text displayed when you hover the mouse over the Banner.
Menu Settings
1 | menu: |
||
before represents the page’s address, and after represents the displayed icon name.
about:
is used to set the “About” page. If it doesn’t exist, you can create it using hexo new page "about"
in Git Bash, and then open \source\about\index.md
to write the content.
tags:
is used to enable the “Tags” functionality. Similarly, use the command hexo new page "tags"
to create it, then open source\tags\index.md
and add a line type: "tags"
below the date. When writing a blog post, you can set tags at the top by adding tags: []
, separated by commas for multiple tags.
archives:
is used to set up the archive page.
categories:
is used to set up the categories page. When editing a blog post, you can specify the category by adding categories:
at the top.
Theme Selection
Next offers four themes to choose from. To use your preferred theme, remove the #
before it.
1 | # Schemes |
Social Links
1 | # Social Links |
In the ||
section, enter the links to your social media profiles, and use the space after them to set the corresponding icons.
For the E-mail:
section, the format is mailto:emailaddress
. On Windows 10, this will invoke the system’s email service and automatically populate the recipient field.
Sidebar Avatar
1 | # Sidebar Avatar |
After url:
, enter the path to your profile picture. By default, this picture should be in the \themes\next\source\images
directory.
rounded:
controls whether to display a rounded avatar.opacity:
sets the opacity of the avatar, with 1 being completely opaque.rotated:
determines whether the avatar rotates when the mouse hovers over it.
Table Of Contents in the Sidebar
1 | # Table Of Contents in the Sidebar |
enable:
determines whether to enable the sidebar table of contents.
number:
controls whether automatic numbering is enabled.
wrap:
determines if titles should wrap to the next line when they exceed the width of the sidebar.
expand_all:
specifies whether to expand all sections of the table of contents. If set to false, it will only expand the section you are currently viewing.
max_depth:
sets the maximum depth of the automatically generated table of contents, indicating how many levels of headings to include in the table of contents.
Sidebar Settings
1 | sidebar: |
position:
is used to set whether the sidebar is on the left or right side. Remove the #
before your desired position and add #
before the other one. This option only affects the Pisces
and Gemini
themes.
width:
specifies the width of the sidebar. The default is 320 for Muse
and Mist
, and 240 for Pisces
and Gemini
.
display:
determines the display style of the sidebar. This option only affects the Muse
and Mist
themes. You can try each one to see which works best for you.
offset:
sets the distance between the top introduction section and the sidebar. This option only affects the Pisces
and Gemini
themes.
onmobile:
controls whether the sidebar is displayed on smaller devices like smartphones. This option only affects the Muse
and Mist
themes.
dimmer:
determines whether clicking on the blank area of the screen closes the sidebar. This option also only affects the Muse
and Mist
themes.
Back to Top Button
1 | back2top: |
sidebar:
is used to determine whether to place the buttons in the sidebar.
scrollpercent:
is used to determine whether to display the reading progress percentage.
Read More Button
Find the following section and set read_more_btn:
to true
to enable the “Read More” button.
1 | # Read more button |
The next section is used to set up automatic generation of the “Read More” option:
1 | # Automatically Excerpt (Not recommend). |
The length
property indicates the character length up to which the text will be excerpted.
This section is for automatically scrolling the page to the section located under the <!-- more -->
marker:
1 | # Automatically scroll page to the section which is under <!-- more --> mark. |
Once these settings are configured, you can add <!--more-->
in your post to hide the remaining text on the homepage and display the “Read More” button.
Code Block Copy Button
1 | codeblock: |
show_result:
is used to determine whether to display a success message after copying.
Reward
1 | # Reward (Donate) |
enable:
is used to determine whether to display a reward button at the end of the article.
animation:
is used to determine whether the reward button should have animation.
To enable a specific reward option, remove the #
at the beginning of the line. Make sure to replace it with your own image, and the path to the image can be found in \themes\next\source\images
.
Code Highlight Theme
The Next theme comes with built-in Tomorrow code highlight themes, totaling five in number. You can preview them at Tomorrow. To select the one you prefer, modify it in the highlight_theme:
section below.
1 | # Code Highlight theme |
Bookmark
Display a bookmark button in the upper left corner to jump to the last bookmarked location. First, run the command git clone https://github.com/theme-next/theme-next-bookmark.git source/lib/bookmark
to install the bookmark plugin. Then, in the options below, set enable:
to true
.
1 | # Bookmark Support |
Enable RSS
Well, it seems like not many people use RSS anymore…
Installation
Execute the following command in your blog’s root directory to install the RSS plugin:
1 | npm install hexo-generator-feed --save |
Configuration
Open the configuration file _config.yml
in your blog’s root directory and add the following code at the end:
1 | # RSS Subscription Support |
Local Search
Enabling local search functionality for quick and easy navigation.
Installation
Execute the following command to install the plugin:
1 | npm install hexo-generator-searchdb --save |
Configuration
Open the configuration file _config.yml
in the Next theme’s directory and search for local_search
. Modify it as follows:
1 | # Local search |
In-Depth Beautification of the Next Theme
I can’t continue writing, take your time to fill it out, it’s all just for fun.
Top Reading Progress Bar
Add a Reading Progress bar at the top of the blog post pages to indicate the reading progress. The Next theme comes with built-in configuration files.
Installation
Navigate to the Next theme folder:
1 | cd themes/next |
Install the module into the source/lib
folder:
1 | git clone https://github.com/theme-next/theme-next-reading-progress source/lib/reading_progress |
Modify the Configuration File
Open the configuration file _config.yml
in the Next theme directory. Search for reading_progress
and locate the following code. Set enable:
to true
:
1 | # Reading progress bar |
You can find the color code by using ATOOL and directly modify it. The default color is cyan, and I changed it to pink. If the top reading progress bar overlaps with the loading bar, you can adjust the line height to ensure it covers the loading bar. I set my line height to 3px
.
Upgrading
Navigate to the installation directory:
1
cd themes/next/source/lib/reading_progress
Update the module:
1
git pull
1 | cd themes/next/source/lib/reading_progress |
1 | git pull |
Loading Bar
This feature displays the loading progress during website loading. The Next theme already supports the PACE functionality, and it offers multiple loading animations to choose from.
- pace-theme-big-counter
- pace-theme-bounce
- pace-theme-barber-shop
- pace-theme-center-atom
- pace-theme-center-circle
- pace-theme-center-radar
- pace-theme-center-simple
- pace-theme-corner-indicator
- pace-theme-fill-left
- pace-theme-flash
- pace-theme-loading-bar
- pace-theme-mac-osx
- pace-theme-minimal
Installation
Navigate to the Next theme folder.
1 | cd themes/next |
Install the module into the source/lib
folder.
1 | git clone https://github.com/theme-next/theme-next-pace source/lib/pace |
Modify Configuration File
Open the configuration file _config.yml
located in the Next theme folder. Search for pace
to locate the following code:
1 | # Progress bar in the top during page loading. |
Set pace:
to true
.
Set pace_theme:
to one of the themes listed under Themes list:
. You can check the available theme styles on the PACE documentation.
Adjusting Colors
To match the progress bar with the theme’s background, you can find the corresponding theme’s CSS file in ./themes/next/source/lib/pace
and modify the color settings accordingly.
The following code is an example of pace-theme-flash.min.css
.
1 | .pace { |
To modify the colors, search for #
within the code. There are a total of 5 instances where you can replace colors. Here are three methods to change the colors:
- Use ATOOL to look up color codes and directly replace the colors in the code.
- If you’re using Visual Studio Code, install a CSS plugin and click on the
#
to modify the color directly. - Visit PACE documentation, select your desired color, and copy the code to replace the original code in the file.
The default color is blue. After modifying the code, it will be pink.
Upgrade
Navigate to the installation directory:
1 | cd themes/next/source/lib/pace |
Update the module:
1 | git pull |
Dynamic Background
Next theme provides three default dynamic background options:
Canvas-nest
I chose this background as it’s fun.
Installation
Navigate to the Next theme folder:
1 | cd themes/next |
Install the module:
1 | git clone https://github.com/theme-next/theme-next-canvas-nest source/lib/canvas-nest |
Modify Configuration
Open the _config.yml
file in the Next theme directory and modify the following code:
1 | # Canvas-nest |
If you want to use CDN acceleration, set the following:
1 | vendors: |
Upgrade
Navigate to the installation directory:
1 | cd themes/next/source/lib/canvas-nest |
Update:
1 | git pull |
JavaScript 3D library
Installation
Navigate to the Next theme folder:
1 | cd themes/next |
Install the module:
1 | git clone https://github.com/theme-next/theme-next-three source/lib/three |
Modify Configuration
Open the _config.yml
file in the Next theme directory and modify the following code. There are three styles to choose from; set one to true
to enable it:
1 | # JavaScript 3D library. |
Upgrade
Navigate to the installation directory:
1 | cd themes/next/source/lib/three |
Update:
1 | git pull |
Canvas-ribbon
Installation
Navigate to the Next theme folder:
1 | cd themes/next |
Install the module:
1 | git clone https://github.com/theme-next/theme-next-canvas-ribbon source/lib/canvas-ribbon |
Modify Configuration
Open the _config.yml
file in the Next theme directory and modify the following code:
1 | # Canvas-ribbon |
Upgrade
Navigate to the installation directory:
1 | cd themes/next/source/lib/canvas-ribbon |
Update:
1 | git pull |
Mouse Click Effects
Add mouse click effects to your web page. Currently, there are two types of effects: heart and explosion. These effects can be combined, but be cautious, as they are not very friendly to devices with low performance, especially the explosion effect, which can make tablets as slow as a PowerPoint presentation. Use them sparingly.
Heart Effect
Create JS File
Create a new clicklove.js
in . /themes/next/source/js
and paste the following code.
1 | !function(e,t,a){function n(){c(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"),o(),r()}function r(){for(var e=0;e<d.length;e++)d[e].alpha<=0?(t.body.removeChild(d[e].el),d.splice(e,1)):(d[e].y--,d[e].scale+=.004,d[e].alpha-=.013,d[e].el.style.cssText="left:"+d[e].x+"px;top:"+d[e].y+"px;opacity:"+d[e].alpha+";transform:scale("+d[e].scale+","+d[e].scale+") rotate(45deg);background:"+d[e].color+";z-index:99999");requestAnimationFrame(r)}function o(){var t="function"==typeof e.onclick&&e.onclick;e.onclick=function(e){t&&t(),i(e)}}function i(e){var a=t.createElement("div");a.className="heart",d.push({el:a,x:e.clientX-5,y:e.clientY-5,scale:1,alpha:1,color:s()}),t.body.appendChild(a)}function c(e){var a=t.createElement("style");a.type="text/css";try{a.appendChild(t.createTextNode(e))}catch(t){a.styleSheet.cssText=e}t.getElementsByTagName("head")[0].appendChild(a)}function s(){return"rgb("+~~(255*Math.random())+","+~~(255*Math.random())+","+~~(255*Math.random())+")"}var d=[];e.requestAnimationFrame=function(){return e.requestAnimationFrame||e.webkitRequestAnimationFrame||e.mozRequestAnimationFrame||e.oRequestAnimationFrame||e.msRequestAnimationFrame||function(e){setTimeout(e,1e3/60)}}(),n()}(window,document); |
Modify the Layout File
Open ./themes/next/layout/_layout.swig
and add the following code at the end:
1 | <!-- Heart-shaped click effect --> |
Explosion Effect
Create a JavaScript File
Create a new firework.js
in . /themes/next/source/js
and paste the following code into it.
1 | function updateCoords(e){pointerX=(e.clientX||e.touches[0].clientX)-canvasEl.getBoundingClientRect().left,pointerY=e.clientY||e.touches[0].clientY-canvasEl.getBoundingClientRect().top}function setParticuleDirection(e){var t=anime.random(0,360)*Math.PI/180,a=anime.random(50,180),n=[-1,1][anime.random(0,1)]*a;return{x:e.x+n*Math.cos(t),y:e.y+n*Math.sin(t)}}function createParticule(e,t){var a={};return a.x=e,a.y=t,a.color=colors[anime.random(0,colors.length-1)],a.radius=anime.random(16,32),a.endPos=setParticuleDirection(a),a.draw=function(){ctx.beginPath(),ctx.arc(a.x,a.y,a.radius,0,2*Math.PI,!0),ctx.fillStyle=a.color,ctx.fill()},a}function createCircle(e,t){var a={};return a.x=e,a.y=t,a.color="#F00",a.radius=0.1,a.alpha=0.5,a.lineWidth=6,a.draw=function(){ctx.globalAlpha=a.alpha,ctx.beginPath(),ctx.arc(a.x,a.y,a.radius,0,2*Math.PI,!0),ctx.lineWidth=a.lineWidth,ctx.strokeStyle=a.color,ctx.stroke(),ctx.globalAlpha=1},a}function renderParticule(e){for(var t=0;t<e.animatables.length;t++){e.animatables[t].target.draw()}}function animateParticules(e,t){for(var a=createCircle(e,t),n=[],i=0;i<numberOfParticules;i++){n.push(createParticule(e,t))}anime.timeline().add({targets:n,x:function(e){return e.endPos.x},y:function(e){return e.endPos.y},radius:0.1,duration:anime.random(1200,1800),easing:"easeOutExpo",update:renderParticule}).add({targets:a,radius:anime.random(80,160),lineWidth:0,alpha:{value:0,easing:"linear",duration:anime.random(600,800)},duration:anime.random(1200,1800),easing:"easeOutExpo",update:renderParticule,offset:0})}function debounce(e,t){var a;return function(){var n=this,i=arguments;clearTimeout(a),a=setTimeout(function(){e.apply(n,i)},t)}}var canvasEl=document.querySelector(".fireworks");if(canvasEl){var ctx=canvasEl.getContext("2d"),numberOfParticules=30,pointerX=0,pointerY=0,tap="mousedown",colors=["#FF1461","#18FF92","#5A87FF","#FBF38C"],setCanvasSize=debounce(function(){canvasEl.width=2*window.innerWidth,canvasEl.height=2*window.innerHeight,canvasEl.style.width=window.innerWidth+"px",canvasEl.style.height=window.innerHeight+"px",canvasEl.getContext("2d").scale(2,2)},500),render=anime({duration:1/0,update:function(){ctx.clearRect(0,0,canvasEl.width,canvasEl.height)}});document.addEventListener(tap,function(e){"sidebar"!==e.target.id&&"toggle-sidebar"!==e.target.id&&"A"!==e.target.nodeName&&"IMG"!==e.target.nodeName&&(render.play(),updateCoords(e),animateParticules(pointerX,pointerY))},!1),setCanvasSize(),window.addEventListener("resize",setCanvasSize,!1)}"use strict";function updateCoords(e){pointerX=(e.clientX||e.touches[0].clientX)-canvasEl.getBoundingClientRect().left,pointerY=e.clientY||e.touches[0].clientY-canvasEl.getBoundingClientRect().top}function setParticuleDirection(e){var t=anime.random(0,360)*Math.PI/180,a=anime.random(50,180),n=[-1,1][anime.random(0,1)]*a;return{x:e.x+n*Math.cos(t),y:e.y+n*Math.sin(t)}}function createParticule(e,t){var a={};return a.x=e,a.y=t,a.color=colors[anime.random(0,colors.length-1)],a.radius=anime.random(16,32),a.endPos=setParticuleDirection(a),a.draw=function(){ctx.beginPath(),ctx.arc(a.x,a.y,a.radius,0,2*Math.PI,!0),ctx.fillStyle=a.color,ctx.fill()},a}function createCircle(e,t){var a={};return a.x=e,a.y=t,a.color="#F00",a.radius=0.1,a.alpha=0.5,a.lineWidth=6,a.draw=function(){ctx.globalAlpha=a.alpha,ctx.beginPath(),ctx.arc(a.x,a.y,a.radius,0,2*Math.PI,!0),ctx.lineWidth=a.lineWidth,ctx.strokeStyle=a.color,ctx.stroke(),ctx.globalAlpha=1},a}function renderParticule(e){for(var t=0;t<e.animatables.length;t++){e.animatables[t].target.draw()}}function animateParticules(e,t){for(var a=createCircle(e,t),n=[],i=0;i<numberOfParticules;i++){n.push(createParticule(e,t))}anime.timeline().add({targets:n,x:function(e){return e.endPos.x},y:function(e){return e.endPos.y},radius:0.1,duration:anime.random(1200,1800),easing:"easeOutExpo",update:renderParticule}).add({targets:a,radius:anime.random(80,160),lineWidth:0,alpha:{value:0,easing:"linear",duration:anime.random(600,800)},duration:anime.random(1200,1800),easing:"easeOutExpo",update:renderParticule,offset:0})}function debounce(e,t){var a;return function(){var n=this,i=arguments;clearTimeout(a),a=setTimeout(function(){e.apply(n,i)},t)}}var canvasEl=document.querySelector(".fireworks");if(canvasEl){var ctx=canvasEl.getContext("2d"),numberOfParticules=30,pointerX=0,pointerY=0,tap="mousedown",colors=["#FF1461","#18FF92","#5A87FF","#FBF38C"],setCanvasSize=debounce(function(){canvasEl.width=2*window.innerWidth,canvasEl.height=2*window.innerHeight,canvasEl.style.width=window.innerWidth+"px",canvasEl.style.height=window.innerHeight+"px",canvasEl.getContext("2d").scale(2,2)},500),render=anime({duration:1/0,update:function(){ctx.clearRect(0,0,canvasEl.width,canvasEl.height)}});document.addEventListener(tap,function(e){"sidebar"!==e.target.id&&"toggle-sidebar"!==e.target.id&&"A"!==e.target.nodeName&&"IMG"!==e.target.nodeName&&(render.play(),updateCoords(e),animateParticules(pointerX,pointerY))},!1),setCanvasSize(),window.addEventListener("resize",setCanvasSize,!1)}; ; |
Modify the Layout File
Open ./themes/next/layout/_layout.swig
and add the following code in the middle of the <head>
section:
1 | <!-- Explosion effect --> |
Configure the Theme File
Open the _config.yml
file in the ./themes/next
directory and add the following code at the end:
1 | # Fireworks |
Live2D Virtual Assistant
Add a virtual assistant similar to Bilibili’s “22/33” in the corner of your website. It can follow the mouse cursor and interact with users. You can check out the official documentation by xiazeyu on GitHub.
(Put your favorite character on there)
Installation
Execute the command
npm install --save hexo-helper-live2d
to install theLive2D
module.Choose your preferred model style and execute the command
npm install packagename
to install the model. Replacepackagename
with the name of the model you want to use. Here are some available models:- live2d-widget-model-chitose
- live2d-widget-model-epsilon2_1
- live2d-widget-model-gf
- live2d-widget-model-haru/01 (Install using
npm install --save live2d-widget-model-haru
) - live2d-widget-model-haru/02 (Install using
npm install --save live2d-widget-model-haru
) - live2d-widget-model-haruto
- live2d-widget-model-hibiki
- live2d-widget-model-hijiki
- live2d-widget-model-izumi
- live2d-widget-model-koharu
- live2d-widget-model-miku
- live2d-widget-model-ni-j
- live2d-widget-model-nico
- live2d-widget-model-nietzsche
- live2d-widget-model-nipsilon
- live2d-widget-model-nito
- live2d-widget-model-shizuku
- live2d-widget-model-tororo
- live2d-widget-model-tsumiki
- live2d-widget-model-unitychan
- live2d-widget-model-wanko
- live2d-widget-model-z16
You can see some previews here.
Configuration
Basic Configuration
- Open the configuration file
_config.yml
in your blog’s root directory. - Add the following code:
1 | live2d: |
About Tag Mode
To insert the Live2D model on specific pages, insert {{ live2d() }}
(Swig) before </body>
in the desired page. Set tagMode
to true
. The plugin will then only appear on pages with the live2d
tag.
(I didn’t enable this option; of course, I want my virtual assistant on all pages)
Advanced Configuration
If you want to use a custom-made model package, you can follow these steps:
- Create a new directory and run
npm init
in your Node environment. It’s recommended to use a package name likelive2d-widget-model-xxx
. - Create an
assets
subdirectory inside the newly created directory and place your model files inside it. - Publish the package using
npm publish
. - Then, install it using
npm install --save live2d-widget-model-xxx
. - Adjust the model name in the configuration file, and you can use it.
Netease Cloud Music Widget
Add background music to your blog, supporting Netease Cloud Music playlists. Follow these steps:
- First, log in to the Netease Cloud Music web version.
- Select the playlist you want to add.
- Share the playlist.
- Click on your profile picture in the upper right corner and go to “My Homepage.”
- Click on “Activity.”
- Find the playlist you just shared.
- Click on “Generate External Player.”
- Choose the “iframe” interface and adjust the player’s style and size.
- It’s recommended not to enable “Auto Play” under “Play Mode.”
- Copy the HTML code provided.
- Open
sidebar.swig
in the pathHexo root directory\themes\next\layout\_macro
. - Insert the following code at an appropriate location, adjusting the placement as needed. The
iframe
is the code you just copied.1
2
3<div id="music163player">
<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=280 height=450 src="//music.163.com/outchain/player?type=0&id=908252389&auto=1&height=430"></iframe>
</div> - The player may not display correctly due to insufficient sidebar width. You need to adjust the sidebar width in the theme configuration file.
- Open the
_config.yml
file under the Next theme. - Search for “width” and uncomment the last line by removing the “#” sign before “width” to make it effective.
1
2
3
4# Manual define the sidebar width. If commented, will be default for:
# Muse | Mist: 320
# Pisces | Gemini: 240
# width: 300 - Adjust the sidebar width according to your needs.
Code Folding Feature
Example
As of May 13, 2022, this feature is deprecated in Next 8.
You can use two folding blocks to hide large sections of text and reduce page space usage. Here’s an example for the Next theme:
1 | {% fold Folded Content %} |
Edit main.js
Open .\themes\next\source\js\post-details.js
and insert the following code under a code block similar to $(document).ready(function() {
:
1 | $(document).ready(function(){ |
Create tag.js
Open the . \themes\next\scripts
path and create a new tag.js
file, the code is as follows.
1 | const rEscapeContent = /<escape(?:[^>]*)>([\s\S]*?)<\/escape>/g; |
Create fold.js
Create a new fold.js
file in the same path with the following code.
1 | function fold (args, content) { |
Configure custom.styl
Open .\themes\next\source\css\_custom\custom.styl
, and insert the following code at the end:
1 | .hider_title { |
Usage
To fold a paragraph, simply add the tags before and after the content you want to fold, like this:
1 | {% fold Folded Content %} |
This code will achieve the same effect as the example above.
Reference: @Ryan Miao
Website Title Crash Deception
Add a title crash deception effect to the webpage title. When you leave the page, the title will change, and when you switch back, it will return to normal. It’s a fun way to deceive people.
Create a New File
In your_blog_root\themes\next\source\js
, create a new file called crash_cheat.js
, and copy the following code into it:
1 | <!--Title Crash Deception--> |
You can customize the content after document.title
. The first one is the text displayed in the title when the page is switched out, the second is the text briefly displayed when switching back, and the third is the original webpage title. Additionally, make sure to change the /favicon.ico
in the else
block to the path of your own logo in the public
directory. Otherwise, it will still display the symbol shown when the page crashes upon return.
Add Reference
Add the following code at the end of your_blog_root\themes\next\layout\_layout.swig
:
1 | <!--Title Crash Deception--> |
Background and Semi-transparent Effect
Emmm… I feel like the background is too plain, let’s add something to it.
Steps
- Place your chosen background image in
your_blog_root/themes/next/source/images
. - Open the
custom.styl
file inyour_blog_root/themes/next/source/css/_custom
. - Add the following code:
1 | body { |
Note
Don’t use a background image that’s too large, it will significantly slow down your website’s loading speed.
Don’t make the transparency too low, as it may affect readability.
Modify Hyperlink Style
Open themes/next/source/css/_common/components/post/post.styl
and add the following code above the series of @import
statements at the end:
1 | // Styles for links within the post content |
Modify Article Footer Tags Style
Open the file /themes/next/layout/_macro/post.swig
.
Search for rel="tag">#
and replace #
with <i class="fa fa-tag"></i>
.
Add End-of-Article Marker
Create passage-end-tag.swig
In the \themes\next\layout\_macro
directory, create a file named passage-end-tag.swig
and copy the following code into it:
1 | <div> |
Modify post.swig
Open the \themes\next\layout\_macro\post.swig
file, and add the following code after post-body
and before post-footer
:
1 | <div> |
Modify the Theme Configuration File
Open the theme configuration file _config.yml
and add the following at the end:
1 | # Add "End of Article" marker at the end of articles |
Blog Post Compression
After converting Markdown files to HTML, there may be many spaces, and there can also be numerous spaces in JS and CSS files. Spaces in JS can affect performance.
Installation
Execute the following command to install the hexo-neat
plugin:
1 | npm install hexo-neat --save |
Configuration
Open the configuration file _config.yml
in the root directory of your blog, and add the following code to the end:
1 | # hexo-neat |
Notes
Some plugins may report errors after compression. You can exclude the corresponding files by adding them to the exclude
section to disable compression for those files.
Modify Code Block Colors
Open the .\themes\next\source\css\_custom\custom.styl
file and add the following code. You can customize the color
according to your preference:
1 | // Single-line code block color |
Website Uptime
Open .\themes\next\layout\_partials\footer.swig
and add the following code:
1 | <div> |
This code adds a display to your website’s footer that shows how many days, hours, minutes, and seconds your site has been running. It calculates the uptime based on a specified start date and time (in this case, March 31, 2019).
Visitor Statistics
The Next theme has built-in support for Busuanzi statistics. In the Next theme’s configuration file _config.yml
, search for busuanzi_count
, and set enable
to true
. You can also customize the icon
settings. Below is an example configuration:
1 | # Show Views / Visitors of the website / page with busuanzi. |
Word and Reading Time Statistics
Installation
To install the statistics plugin, run the following command in your blog’s root directory:
1 | npm install hexo-symbols-count-time --save |
Configuration
Add the following code to your blog’s root configuration file _config.yaml
:
1 | symbols_count_time: |
In the Next theme’s configuration file _config.yaml
, search for symbol_count
and modify it to:
1 | symbols_count_time: |
Password-Protected Articles
Please note that the article encryption plugin may conflict with word count and table of contents generation. For example, a 9,000-word article may show as 43,000 words in word count statistics, and there may be issues with generating a table of contents. Please use this plugin with caution.
Installation
To install the plugin, run the following command in your blog’s root directory:
1 | npm install --save hexo-blog-encrypt |
Configuration
In your blog’s root configuration file _config.yml
, enable the plugin using the following code:
1 | # Security |
Usage
To use the encryption feature, add the following fields to the front-matter of your article’s Markdown file, like this:
1 | --- |
Replace password
with the desired password, abstract
with the summary to display on the homepage, and message
with the information to show in the password input box.
Pinning Articles to the Top
Installation
To install the plugin, run the following commands in your blog’s root directory:
1 | npm uninstall hexo-generator-index --save |
Configuration
Open .\themes\next\layout\_macro\post.swig
and search for <div class="post-meta">
. Add the following code within it to enable the pinning feature:
1 | {% if post.top %} |
Usage
To pin an article to the top, add top: true
to the front-matter of the article, like this:
1 | --- |
Modifying the Default Font Size
The default font size in the Next theme is 14px. You can adjust it by opening .\themes\next\source\css\_variables\base.styl
and searching for $font-size-base
. Change the value following it to adjust the font size.
Customizing the Mouse Cursor Style
To customize the mouse cursor style, open .\themes\next\source\css\_custom\custom.styl
and add the following code:
1 | /* Mouse cursor style */ |
Replace "image-link"
with the URL of your desired cursor image. The image file must be in the ico
format.
Reference: Blog
Image Lazy Loading
Image lazy loading allows images to load only when needed, rather than all at once, which can speed up your website’s performance. This is especially useful for blogs with many images.
Installation
To install the lazy loading plugin, execute the following command in your blog’s root directory:
1 | npm install hexo-lazyload --save |
Configuration
Add the following code to your blog’s root _config.yml
file to configure lazy loading:
1 | lazyload: |
Adding a Comment System
2020 New Year Update: Gitment is no longer actively maintained, so we will use Gitalk instead.
The comment system we will use is Gitalk, which is similar to the old Gitment.
Installation
The latest version of the Next theme comes with Gitalk built-in, so we only need to enable it. You can ignore the installation process below:
To install the Gitment plugin, execute the following command:
1 | npm i --save gitment |
Register OAuth Application
Click here to register a new OAuth application:
- For “Application name,” you can enter anything.
- For “Homepage URL” and “Authorization callback URL,” enter the URL of your website’s homepage.
- “Application description” is optional; you can describe the purpose of this application.
After filling in the information, click “Register application.” The page will display “Client ID” and “Client Secret” for later login.
Configuration
Open the Next theme’s configuration file .\themes\next\_config.yml
and search for gitalk
. Set enable
to true
and configure the relevant options:
1 | # Gitalk |
Initialization
After deploying to GitHub Pages, go to the bottom of the article where you want to enable comments. Initialize Gitalk and log in with your GitHub account to start commenting.
Note
Some articles may encounter an error like Error: Validation Failed
when initializing comments (it’s strange, but using a VPN sometimes solves the issue). This error is caused by label length overflow in the issue. Chinese characters are encoded, which can exceed the allowed limit. However, GitHub issues do support Chinese labels. To solve this issue, open C:\Users\oo\OneDrive\Hexo\themes\next\layout\_third-party\comments\gitment.swig
and search for id
. Modify the value after it to decodeURI(window.location.pathname)
.
Please note that Gitalk should work seamlessly without needing this modification.
Customizing the 404 Page
Since your website is hosted on GitHub, the default 404 page is provided by GitHub. It may not match your theme, and it lacks any guidance for visitors. To address this, you can create a custom 404 page that matches your theme. Here’s how to do it:
Create the Page
You can create a custom 404 page by writing HTML code yourself, but for simplicity, you can use an existing template. While searching on the internet, I found a few nice 404 templates on 404.life. I chose the acg-moe template. Download the template’s source code and extract it.
Configuration
Add Front Matter
First, copy the index.html
file from the extracted template to the .\source
folder at the root of your blog directory. Rename it to 404.html
. Then, open the 404.html
file and add the following front matter at the top:
1 | layout: false |
Head Section
Next, let’s configure the <head>
section of the HTML content. Here’s an example:
1 | <head> |
- In
<title>Page Eaten by Chewie ╭( ∀´ )╯</title>
, you can set the title of the web page, which will be displayed in the browser’s title bar. - In
<link rel="icon" href="https://siriusq.top/images/favicon.png">
, you can set the URL of your website’s icon.
JavaScript and CSS Files
In the <head>
section of your custom 404 page (404.html
), several <link rel
tags need to be customized. The original source code points to the author’s website, but for consistency, it’s better to host these files on your own website. Here’s what you need to do:
First, create a directory named 404
inside the .\source
directory. In this new directory, create two files: 404.css
and 404.js
. Copy and paste the following code into each file and save them. Then, replace the href=
links with your own website links. Only replace the part before /404/
:
CSS (404.css
):
1 | /* Your custom CSS styles for the 404 page */ |
JavaScript (404.js
):
1 | // Your custom JavaScript code for the 404 page |
After making these changes, your custom 404 page will reference the CSS and JavaScript files hosted on your own website, ensuring consistency and improving performance.
Body Section
Here is my configuration.
1 | <body> |
In the
<a href="https://siriusq.top/" title="Back to Siriusq"><img src="https://siriusq.top/images/avatar.gif" width="150" alt="Noisky logo" class="panel-cover__logo logo"></a>
section, set your own avatar’s URL and the link to your website. You can also customize the avatar’s rotation if desired.In the
</script><header class="panel-cover" style="background-image:url(https://siriusq.top/images/background.jpg)">
section, you can set the background image of your webpage. The path to the image can be found by inspecting the webpage with F12 in your browser.In the
<p class="panel-cover__description">Sorry, the page you're looking for has been eaten by Chewie.</p>
section, you can customize the two lines of text that appear.In the
<p class="footer">Siriusq © 2019 </p>
section, you can customize the website’s footer.The following
<li class="navigation__item"><a href="https://siriusq.top/" title="Visit the blog">Homepage</a></li>
items can be customized to create your navigation links. Set the label for the link between</a>
tags, and set the link’s URL afterhref
. The text displayed when hovering over the link can be set in thetitle
attribute.After
<!-- Github -->
, you can set your own GitHub link. Similarly, after<!-- Email -->
, you can set your email link. Set the website URL afterhref
, add a tooltip description in thetitle
attribute, and customize the icon using<i class="social fa fa-github"></i>
with the desired icon class.
Ending Section
In the ending section, you also need to replace the two JavaScript files with links from your own website. One is the earlier mentioned 404.js
, and the other is the jQuery file from the theme. You should check your website for the correct link addresses. In my case, it’s https://siriusq.top/lib/jquery/index.js?v=2.1.3
.
1 | <script type="text/javascript" src="https://siriusq.top/404/404.js"></script> |
Conclusion
That’s pretty much it. Beautifying your website can indeed be a big project.