This commit is contained in:
xaoxuu 2021-07-08 22:23:55 +08:00
parent 3e94801bc5
commit a54ff9cfba
5 changed files with 70 additions and 23 deletions

View File

@ -23,7 +23,7 @@ function layoutDiv() {
} }
el += ' href="' + url_for(group.path) + '">' + group.title + '</a>'; el += ' href="' + url_for(group.path) + '">' + group.title + '</a>';
el += '</a>'; el += '</a>';
} }
} }
el += '</nav>'; el += '</nav>';
el += '</div>'; el += '</div>';

View File

@ -1,11 +1,11 @@
/** /**
* navbar.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/ * navbar.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来 * 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
* *
* {% navbar [markdown link] ... %} * {% navbar [markdown link] ... %}
* *
* example: * example:
* {% navbar [Home](/) [About](/about/) [Comments](#comments) %} * {% navbar active:1 [Home](/) [About](/about/) [Comments](#comments) %}
*/ */
'use strict'; 'use strict';
@ -14,24 +14,43 @@ hexo.extend.tag.register('navbar', function(args) {
if (args.length == 0) { if (args.length == 0) {
return; return;
} }
args = hexo.args.map(args, ['active'], ['links']);
if (args.links) {
args.links = args.links.split(' ');
}
var el = '<div class="tag-plugin navbar"><nav class="cap">'; var el = '<div class="tag-plugin navbar"><nav class="cap">';
function layoutItem(a) { function layoutItem(a, i) {
var text = '';
var href = '';
var el = '<a';
if ((i+1).toString() === args.active) {
el += ' class="active"';
}
if (a.includes('](')) { if (a.includes('](')) {
// markdown // markdown
let el = hexo.render.renderSync({text: a, engine: 'markdown'}).split('\n').join(''); let tmp = a.split('](');
if (el.length > 8) { if (tmp.length > 1) {
el = el.slice(3, el.length-4); text = tmp[0];
if (text.length > 1) {
text = text.substring(1, text.length);
}
href = tmp[1];
if (href.length > 1) {
href = href.substring(0, href.length-1);
}
el += ' href="' + href + '"';
} }
return el;
} else { } else {
var item = '<a href="#' + a + '">'; el += ' href="#' + a + '"';
item += a; text = a;
item += '</a>';
return item;
} }
el += '>';
el += text;
el += '</a>';
return el;
} }
args.forEach((item, i) => { args.links.forEach((item, i) => {
el += layoutItem(item); el += layoutItem(item, i);
}); });
el += '</nav></div>'; el += '</nav></div>';
return el; return el;

View File

@ -4,25 +4,49 @@
margin-top: 1.75rem margin-top: 1.75rem
top: -2px top: -2px
background: var(--site-bg) background: var(--site-bg)
padding: 0.5rem 1rem 0.38rem padding: 0 1rem
z-index: 1 z-index: 1
margin-bottom: 1px
&:after
content: ''
width: 'calc(100% - 2 * %s)' % 1rem
height: 2px
border-radius: 2px
position: absolute
bottom: 0
left: 1rem
background: var(--block-hover)
nav.cap nav.cap
display: flex display: flex
overflow: scroll overflow: scroll visible
scrollbar(0, 0) scrollbar(0, 0)
>p >p
margin: 0 margin: 0
a a
padding: 0.5rem 0.75rem padding: .25rem 1rem
margin-left: 0.25rem margin: 10px 0 8px 0
line-height: 2
color: var(--text-p3) color: var(--text-p3)
border-radius: 4px border-radius: 4px
font-weight: 500 font-weight: 500
white-space: nowrap white-space: nowrap
&.active, &:hover position: relative
z-index: 1
&:after
content: ''
width: 'calc(100% - 2 * %s)' % .5rem
height: 2px
position: absolute
bottom: -8px
left: .5rem
&:hover
background: var(--block-hover) background: var(--block-hover)
&.active, &:hover
color: var(--text-p1) color: var(--text-p1)
&.active:after
background: $color-theme
border-radius: 2px
@media screen and (max-width: $device-tablet) @media screen and (max-width: $device-tablet)

View File

@ -34,8 +34,9 @@
a a
margin: 0 margin: 0
padding: 0 padding: 0
color: var(--text-p1)
color: $color-link color: $color-link
&.active
background: none
&:hover &:hover
color: $color-hover color: $color-hover
background: none background: none

View File

@ -4,9 +4,12 @@
padding: 1px padding: 1px
background: var(--block) background: var(--block)
border-radius: 6px border-radius: 6px
display: inline-flex
a a
margin: 1px margin: 1px
padding: 0.5em 0.75rem padding: 0.25em 0.75rem
&:hover &:after
display: none
&:hover,&.active
background: var(--card) background: var(--card)
color: var(--text-p1) color: var(--text-p1)