前言
hexo博客,在不使用右键在新标签页打开的情况下,使用单击打开主域名的子路径。
快速修改
打开E:\BlogRoot\themes\butterfly\layout\includes\header\menu_item.pug
修改menu_item.pug
,全部替换成如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| if theme.menu //- for mobile sidebar - let sidebarChildHide = theme.hide_sidebar_menu_child ? 'hide' : '' - let newTabPaths = [`/tags/`, `/about/`]
.menus_items each value, label in theme.menu if typeof value !== 'object' .menus_item - let hrefValue = url_for(trim(value.split('||')[0])) a.site-page.faa-parent.animated-hover(href=hrefValue, target=(newTabPaths.includes(hrefValue) ? '_blank' : '_self') ) if value.split('||')[1] - var icon_value = trim(value.split('||')[1]) - var anima_value = value.split('||')[2] ? trim(value.split('||')[2]) : 'faa-tada' if icon_value.substring(0,2)=="fa" i.fa-fw(class=icon_value + ' ' + anima_value) else if icon_value.substring(0,4)=="icon" svg.icon(aria-hidden="true" class=anima_value) use(xlink:href=`#`+ icon_value) span=' '+label else .menus_item a.site-page.faa-parent.animated-hover(href='javascript:void(0);') if label.split('||')[1] - var icon_label = trim(label.split('||')[1]) - var anima_label = label.split('||')[2] ? trim(label.split('||')[2]) : 'faa-tada' if icon_label.substring(0,2)=="fa" i.fa-fw(class=icon_label + ' ' + anima_label) else if icon_label.substring(0,4)=="icon" svg.icon(aria-hidden="true" class=anima_label) use(xlink:href=`#`+ icon_label) span=' '+ trim(label.split('||')[0]) i.fas.fa-chevron-down.expand(class=sidebarChildHide) ul.menus_item_child(style=`right:`+ (-55 * Object.keys(value).length + 65) + `px;`) each val, lab in value li - let hrefVal = url_for(trim(val.split('||')[0])) a.site-page.child.faa-parent.animated-hover(href=hrefVal, target=(newTabPaths.includes(hrefVal) ? '_blank' : '_self') ) if val.split('||')[1] - var icon_val = trim(val.split('||')[1]) - var anima_val = val.split('||')[2] ? trim(val.split('||')[2]) : 'faa-tada' if icon_val.substring(0,2)=="fa" i.fa-fw(class=icon_val + ' ' + anima_val) else if icon_val.substring(0,4)=="icon" svg.icon(aria-hidden="true" class=anima_val) use(xlink:href=`#`+ icon_val) span=' '+ lab
|
然后修改let newTabPaths = [/tags/
, /about/
],这句中的/tags/
和/about/
替换成想要在新标签打开的页面。修改的内容需要和_config.butterfly.yml
定义的菜单页面一致。
1 2 3 4 5 6 7 8 9 10 11
| menu: 主页: / || fas fa-home 文章 || fas fa-file-alt: 归档: /archives/ || fas fa-file-archive 标签: /tags/ || fas fa-tag 分类: /categories/ || fas fa-folder-open 导航: /nav/ || fas fa-location-arrow 留言板: /comment/ || fas fa-comment-dots 服务监控: https://uptime.yilancn.top/status/1/ || fas fa-compass 壁纸: /wallpaper/ || fas fa-image 关于: /about/ || fas fa-film
|
修改说明
具体修改部分如下
主菜单部分:原代码:
1
| a.site-page.faa-parent.animated-hover(href=url_for(trim(value.split('||')[0])))
|
修改为:
1 2 3 4
| - let hrefValue = url_for(trim(value.split('||')[0])) a.site-page.faa-parent.animated-hover(href=hrefValue, target=(newTabPaths.includes(hrefValue) ? '_blank' : '_self') )
|
子菜单部分: 原代码:
1
| a.site-page.child.faa-parent.animated-hover(href=url_for(trim(val.split('||')[0])))
|
修改为:
1 2 3 4
| - let hrefVal = url_for(trim(value.split('||')[0])) a.site-page.faa-parent.animated-hover(href=hrefValue, target=(newTabPaths.includes(hrefVal) ? '_blank' : '_self') )
|