mirror of
https://github.com/eggjs/egg.git
synced 2024-12-04 07:14:30 +00:00
45 lines
1.0 KiB
JavaScript
45 lines
1.0 KiB
JavaScript
'use strict';
|
|
|
|
/* global hexo */
|
|
|
|
hexo.extend.helper.register('guide_toc', function() {
|
|
const toc = this.site.data.guide_toc;
|
|
let menu = '<dl>';
|
|
|
|
for (const title in toc) {
|
|
const subMenu = toc[title];
|
|
menu += `<dt>${this.__('guide_toc.' + title)}</dt><dd><ul>`;
|
|
for (const subTitle in subMenu) {
|
|
const url = subMenu[subTitle];
|
|
menu += `<li><a href="${url}">${this.__('guide_toc.' + subTitle)}</a></li>`;
|
|
}
|
|
menu += '</ul></dd>';
|
|
}
|
|
|
|
menu += '</dl>';
|
|
return menu;
|
|
});
|
|
|
|
hexo.extend.helper.register('menu_link', function() {
|
|
const menus = this.site.data.menu;
|
|
|
|
let links = '';
|
|
for (const menu in menus) {
|
|
let link = menus[menu];
|
|
const content = this.__(`menu.${menu}`);
|
|
if (menu === 'guide' && this.page.lang !== 'en') {
|
|
link = '/' + this.page.lang + link;
|
|
}
|
|
links += `<li><a href="${link}" alt="${content}">${content}</a></li>`;
|
|
}
|
|
|
|
return links;
|
|
});
|
|
|
|
hexo.extend.helper.register('index_link', function() {
|
|
if (this.page.lang !== 'en') {
|
|
return `/${this.page.lang}/`;
|
|
}
|
|
return '/';
|
|
});
|