30 Days of Programming

Setting up Hexo to add Per-Post Javascript and CSS

I mentioned earlier that I’d like to be able to seperate Javascript/CSS
in a per-post basis. Well, after some digging I found a solution and thought
it’d be nice to post here.

First, find your themes/your_theme/scripts folder and add
a new *.js file with the following:

1
2
3
4
5
6
7
8
9
10
11
hexo.extend.filter.register('after_init', function () {
// Remove json / js files being inserted to db.json -> Pages
var listSync = hexo.extend.renderer.list(true),
listAsync = hexo.extend.renderer.list();
delete listSync.json;
delete listAsync.json;
delete listSync.js;
delete listAsync.js;
delete listSync.css;
delete listAsync.css;
});

Courtesy of cnotethegr8