Skip to main content

How to Write a Plugin

Less than 1 minute

How to Write a Plugin


ShokaX Inject is a code injection system highly similar to NexT Inject (core code sourced from Theme NexT, based on AGPLv3). This system aims to integrate existing community modifications for Shoka/ShokaX, resolving conflicts between community mods and theme updates while enhancing ShokaX's extensibility.

Before You Start

As the Inject system is based on Hexo's filteropen in new window mechanism, you should have some understanding of how filters work.

Basic Code


The templates and stylesheets for ShokaX Inject require a JavaScript function injection, referred to as an "injector" in this document. Generally, an injector template looks like this:

hexo.extend.filter.register("theme_inject", function (injects) {
  // Place injection code here

You can define multiple injectors within a file and perform npm module usage and file system operations similar to regular filters.

Injection Points

Injection points refer to the target positions for templates and styles. As of v0.3.0, ShokaX Inject has the following injection points:

Code NamePointDescription
headHeaderInjects templates before </head> tag
sidebarSidebarInjects templates above the social area
rightNavRight NavInjects templates to the right of day/night mode toggle and search
postMetaPost InfoInjects templates to the right of word count in the card
postBodyEndPost EndInjects templates at the end of an article
footerFooterInjects templates at the bottom of a page
commentCommentsInjects templates in the comment section (above main theme comments)
bodyEndBody EndInjects templates before </body> tag
statusFooter StatusBefore record number and copyright