var join = require('path').join; hexo.extend.helper.register('show_lang', function (lang) { if (this.page.lang != 'en') { return '/' + this.page.lang; } }); hexo.extend.helper.register('lang_name', function(lang) { var data = this.site.data.languages[lang]; return data.name || data; }); hexo.extend.helper.register('sidebar', function (path) { return ` ` }); function genSidebarList(parent, entries) { /* necessary due to changed context of map() */ let self = this /* all languages except english needs a path prefix */ let lang = (self.page.lang != 'en' && parent == "") ? self.page.lang : '' return entries.map(entry => { /* normally path needs to be prefixed with lang and parent path */ let fullPath; if (entry.path.startsWith('#')) { fullPath = join('', lang, parent) + entry.path; } else if (entry.path.startsWith('empty')) { fullPath = 'empty'; } else { fullPath = join('', lang, entry.path); } /* sometimes paths are full URLs instead of sub-paths */ if (entry.path.startsWith('http')) { fullPath = entry.path } /* path is active when it's the one we are on currently */ let isActive = (self.path).startsWith(fullPath) return `
  • ${(fullPath == 'empty') ? ` ${entry.title} ` : `${entry.title}` } ${(entry.children != undefined) ? ` ` : ''}
  • ` }).join('\n') }