Created
March 3, 2017 09:07
-
-
Save iissnan/b641af0468a32a7c6f6802e9b161e197 to your computer and use it in GitHub Desktop.
Categories State Helper for Hexo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global hexo */ | |
/** | |
* options {Object} | |
* options.url {Function} hexo url_for | |
* options.label {String} label | |
*/ | |
hexo.extend.helper.register('categories_state', function(options){ | |
var pages = hexo.locals.get('pages'); | |
var categories = hexo.locals.get('categories'); | |
if (categories.length === 0) { | |
return ''; | |
} | |
var query = pages.find({ type: 'categories' }); | |
var hasCategoriesPage = query.count() > 0; | |
var result = [ | |
'<div class="site-state-item site-state-categories">', | |
' <span class="site-state-item-count">' + categories.length + '</span>', | |
' <span class="site-state-item-name">' + options.label + '</span>', | |
'</div>' | |
]; | |
if (hasCategoriesPage) { | |
result.splice(1, 0, '<a href="' + options.url(query.first().path) + '">'); | |
result.splice(4, 0, '</a>'); | |
} | |
return result.join('\n'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment