Building a Professional Blog With Hexo and Theme-NexT
Build a professional blog with Hexo and Theme-NexT. This guide covers installation, configuration, and essential integrations like SEO, analytics, and custom plugins to elevate your writing experience.
| Component | Version |
|---|---|
| hexo | 7 |
| hexo-theme-next | 8 |
| NODE_VERSION | 24 |
Getting Started
Initialize your Hexo blog system
1 | ❯ npm install hexo-cli -g |
NOTICE:Hexo init should be run in the empty folder.
Mermaid Diagrams
Hexo Next already supported the mermaid nested, here is the guideline:
https://theme-next.js.org/docs/tag-plugins/mermaid
and we needn’t install additional plugin for it.
npm install hexo-filter-mermaid-diagrams save
RSS Feed
Installation
1 | ❯ npm install hexo-generator-feed --save |
Configuration
Config feed file in {ROOT}/_config.yml, refer to the link below:
https://github.com/hexojs/hexo-generator-feed
Config the RSS link icon in the social section:
In {ROOT}/_config.next.yml
or
In {ROOT}/themes/theme_next/_config.yml
1 | social: |
Theme Customization
Here we use the theme-next as the example.
Installation
1 | ❯ cd hexo-site |
Configuration
Change the content in the _config.yml
1 | theme: next |
1 | ❯ hexo clean # rememeber to clean public/ |
Refer to the official site of theme-next:
https://theme-next.org
https://github.com/next-theme/hexo-theme-next
Avatar Settings
Add the url into the Avatar section in the _config
1 | # Sidebar Avatar |
Create your gravatar account here:
https://en.gravatar.com/emails/
Cloudflare Analytics
Enable with JS Snippet installation in the dashboard of cloudflare analytics,
then you would get a the JS Snippet needs to be installed manually.
1 | <!-- Cloudflare Web Analytics --><script defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "301040bd778923748972389sdfsdf105d8"}'></script><!-- End Cloudflare Web Analytics --> |
the token value is unique for your site and that is what we need to config in the theme-next.
Config the cloudflare analytics in the _config.next.yml of theme-next
1 | # Cloudflare Web Analytics |
Google Fonts
Prevew the google fonts here:
https://fonts.google.com/
Enable Google Fonts in the _config.next.yml of theme-next
1 | font: |
Categories and Tags
Categories apply to the posts in order, resulting in a hierarchy of classifications and sub-classifications.
Tags are all defined on the same hierarchical level so the order in which they appear is not important.
Example
1 | # Baseball is a sub-category of Sports. |
The classification records in the front-matter of the the source of markdown file
https://raw.githubusercontent.com/qzi/qzi.github.io/hexo/source/_posts/technology/hexo-go.md
Front-matter is a block of YAML or JSON at the beginning of the file that is used to configure settings for your writings. Front-matter is terminated by three dashes when written in YAML or three semicolons when written in JSON.
https://hexo.io/docs/front-matter.html
Display in the menu
Config in the [hexo_project]/_config.next.yml
1 | menu: |
Markdown Editors
Typora
Typora is a what you see is what you get editor for markdown file.
Here is my another tutorial for Typora
https://leonvision.online/technology/wysiwyg-markdown-editor-typora/
and visual studio code with markdown plugin is also another alternative choice.
Visual Studio Code
Visual Studio Code comes with a powerful built-in markdown preview feature. Simply press Cmd+Shift+V on macOS to toggle the preview panel for your markdown file.
To customize the preview styling to match your Hexo blog’s appearance, create a .vscode/markdown.css file in your project root and reference it in .vscode/settings.json:
1 | { |
markdown.css: Here is the example of markdown.css for vscode
Showing Whitespaces ExplicitlyCmd + Shift + P → “View: Toggle Render Whitespace”
Auto-Insert Markdown Line Breaks
Configure a keyboard shortcut to automatically insert two spaces and a newline when pressing Shift + Enter:
Cmd + Shift + P → “Preferences: Open Keyboard Shortcuts (JSON)” and add:
1 | { |
Now press Shift + Enter to insert a hard line break in Markdown files.
Search
Enable the feature of local serach in the _config.next.yml of theme-next
1 | # Local Search |
Post Excerpt
Manually add excerpt in the front-matter of the markdown file
1 |
|
Configuration
Config in the [hexo_project]/_config.next.yml
1 | # Automatically excerpt description in homepage as preamble text. |
Refer to https://hexo.io/docs/tag-plugins#Post-Excerpt
Asset Links
Installation
1 | ❯ npm i --save hexo-asset-link |
Configuration
Config in the [hexo_project]/_config.yml
1 | ... |
Markdown Syntax
1 |  |
Reference
homepage of hexo-asset-link
https://github.com/liolok/hexo-asset-link
Custom Domain Email Forwarding
Cloudflare offers free email forwarding for custom domains.
There is a another article for it: Custom domain email forwarding
Sitemap and SEO
Installation
1 | ❯ npm install hexo-generator-sitemap --save |
Configuration
Config in the [hexo_project]/_config.yml
1 | # hexo-generator-sitemap |
and then submit the url of sitemap to google search console to improve your performance on Google Search.
https://search.google.com/search-console/
Google AdSense
Register the account of google adsense and generate a unique in-article ads code snippet for your site. f
Uncomment the custom_file_path in ./_config.next.yml
1 | custom_file_path: |
Create a new file source/_data/post-body-end.njk
Paste the code snippet of in-article ads from google adsense into post-body-end.njk
More detail in google-analytics-and-adsense-in-hexo
Google Analytics
Register the account of google analysis and get the TAG ID for your site.
Config in {hexo_root}/_config.next.yml
1 | # Google Analytics |
Comment Systems
Disqus
Disqus can allow the anonymous comment, but it is blocked in China mainland.
Here is a guide to setup Disqus in Hexo with Theme-NexT:
Add Comments Section to Your Hexo Blog
Configuration in the {hexo_root}/_config.next.yml
1 | # For more information: https://disqus.com |
Auto-Update Timestamp
I developed a new vscode extension - Hexo Auto Updated to update last modified date and time automatically when we saved the markdown file.
Link to Hexo Auto Updated
Video Embedding
Open the video in youtube, click the share button to get the embed code snippet.
Paste the code snippet into the markdown file directly.
1 | <iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/E46_veB0DPU" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> |
Force Refresh
Presss Shift + Command + r to force to refresh the browser(Chrome) to test the result in Mac
Presss Option + Command + r to force to refresh the browser(Safari) to test the result in Mac
1 | # clean the desktop before we work |
References
- Hexo Configuration: Official Hexo configuration documentation.
- Hexo Backup Guide: A comprehensive guide to backing up Hexo sites.
- Adding Google AdSense: Tutorial on integrating Google AdSense with Hexo.
- Theme-NexT Third-Party Services: Guide for integrating third-party services with Theme-NexT.
- Writing Posts in Hexo: Official documentation on creating posts in Hexo.
- Front-matter Documentation: Learn about front-matter configuration in Hexo.
- Asset Folders: Managing assets in Hexo posts.
- Hexo Theme-NexT: Official GitHub repository for Theme-NexT.
- Mermaid Theming: Configuration guide for Mermaid diagram themes.