Skip to content

Commit

Permalink
新增自定义链接
Browse files Browse the repository at this point in the history
  • Loading branch information
weizwz committed Dec 16, 2023
1 parent b3a6052 commit 34df56a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,8 @@ navctrl:
display: '' # 默认文字+图标; txt 仅文字; icon 仅图标
dark: '显示模式 || fas fa-adjust'
random: '随便逛逛 || fas fa-paper-plane'
link: # 添加链接,支持多个
# - '我的博客 || fas fa-blog || https://weizwz.com/'
# - '关注我 || fas fa-brands fa-github || https://github.com/weizwz'
```
重启生效
38 changes: 27 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@ hexo.extend.filter.register(
// 如果配置开启
if (!(config && config.enable)) return;

// 获取菜单
const getMenu = function (str) {
if (!str) return false;
const strArr = str.split('||');
if (strArr.length < 2) return false;
return {
title: strArr[0].trim(),
icon: strArr[1].trim()
}
}

// 获取所有文章路径
const posts_list = hexo.locals.get('posts').data;
let posts_path = [];
Expand All @@ -52,6 +41,7 @@ hexo.extend.filter.register(
menu_display: config.menu.display || '',
menu_dark: getMenu(config.menu.dark),
menu_random: getMenu(config.menu.random),
menu_link: getLink(config.menu.link)
}

// 渲染页面
Expand Down Expand Up @@ -143,3 +133,29 @@ hexo.extend.filter.register(
(hexo.config.recommend || hexo.config.theme_config.recommend)['priority'] || 10
)


// 获取菜单
function getMenu(str) {
if (!str) return false;
const strArr = str.split('||');
if (strArr.length < 2) return false;
return {
title: strArr[0].trim(),
icon: strArr[1].trim()
}
}

// 获取链接
function getLink(links) {
if (!links || !Array.isArray(links)) return false;
const _links = [];
for (const item of links) {
const linkArr = item.split('||');
_links.push({
title: linkArr[0].trim(),
icon: linkArr[1].trim(),
href: linkArr[2].trim(),
})
}
return _links;
}
11 changes: 10 additions & 1 deletion lib/navCtrl.pug
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@
if (menu_display !== 'txt')
i(class=`fa-fw ${menu_random.icon}`)
if (menu_display !== 'icon')
span=`${menu_random.title}`
span=`${menu_random.title}`
if menu_link
- var values = menu_link;
each val in values
a(class=`navctrl-item ${menu_display}` title=`${val.title}` href=`${val.href}` target="_blank")
if (menu_display !== 'txt')
i(class=`fa-fw ${val.icon}`)
if (menu_display !== 'icon')
span=`${val.title}`

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hexo-butterfly-navctrl",
"version": "1.0.0",
"version": "1.0.1",
"description": "Extension to the hexo-theme-butterfly, Navigation bar control center",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 34df56a

Please sign in to comment.