Quantum
Quest

Algorithms, Math, and Physics

Building Hexo toolkit

In my quest to streamline and enhance my blogging workflow with Hexo, I’ve embarked on creating a suite of utilities and scripts collectively known as the Hexo Toolkit. This toolkit is designed to address various challenges and extend the functionality of the Hexo platform, making blogging not just easier, but also more efficient and enjoyable.

Inspiration behind the toolkit

The idea for the Hexo Toolkit was born out of my personal need to solve specific problems I encountered while using Hexo for my blog. From organizing posts in nested directories for better structure to including raw HTML content seamlessly in my posts, each utility in the toolkit serves a purpose that makes managing a Hexo blog more intuitive and less time-consuming.

Key components of the toolkit

Nested directory structure for posts

One of the first utilities I developed was a script to allow Hexo to handle posts in nested directories, enabling a more organized file structure akin to YYYY/MM/DD/post-title.md. This was achieved through a custom filter named before_post_render, which dynamically adjusts the slug based on the post’s file path.

Including raw HTML content

To facilitate the inclusion of raw HTML or code snippets directly into blog posts without the hassle of embedding them into Markdown, I created the include_raw_contents tag. This simple yet powerful tag reads content from a specified file in the _raw directory and includes it directly in the post, maintaining the original formatting and structure.

Serving static assets

Another significant addition to the toolkit is the middleware for serving static assets from a root /assets directory, regardless of the blog’s base URL. This utility, integrated into the Hexo server, ensures that static files are easily accessible, which is particularly useful for blogs hosted as a subset of a larger site.

Environment configuration for templates

Recognizing the need to adapt template behavior based on the development or production environment, I introduced a filter to inject the NODE_ENV environment variable into template locals. This small yet crucial addition allows for conditional logic in templates, making it easier to toggle features or debug information based on the environment.

Conclusion and future directions

The Hexo Toolkit is a testament to the flexibility and extendability of Hexo as a blogging platform. By sharing these utilities, I hope to contribute to the Hexo community and assist others in overcoming similar challenges.

The toolkit is available on GitHub at Hexo Toolkit Repository. I welcome contributions, suggestions, and feedback from fellow Hexo users and enthusiasts to make this toolkit even more robust and useful.

Stay tuned for more updates and utilities as I continue to explore new ways to enhance the Hexo blogging experience.