Skip to content

Commit

Permalink
[fix] icon #376
Browse files Browse the repository at this point in the history
  • Loading branch information
xaoxuu committed Jan 30, 2024
1 parent a2f429a commit 48afb63
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
2 changes: 1 addition & 1 deletion layout/_partial/sidebar/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function layoutFooterDiv() {
el += ' onclick="' + item.onclick + '"';
}
el += '>';
el += item.icon;
el += icon(item.icon, 'no-lazy')
el += '</a>';
}
}
Expand Down
8 changes: 1 addition & 7 deletions layout/_partial/sidebar/menu.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ function layoutDiv() {
}
el += `>`
if (item.icon?.length > 0) {
if (item.icon.startsWith('<')) {
el += item.icon
} else if (theme.icons[item.icon]) {
el += theme.icons[item.icon]
} else {
el += `<img no-lazy src="${item.icon}">`
}
el += icon(item.icon, 'no-lazy')
} else {
el += `<span>${__(item.title)}</span>`
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/helpers/icon.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

hexo.extend.helper.register('icon', function(key) {
hexo.extend.helper.register('icon', function(key, args) {
const { icons } = hexo.theme.config
var result = ''
if (icons[key]) {
Expand All @@ -9,7 +9,7 @@ hexo.extend.helper.register('icon', function(key) {
result = key
}
if (result.startsWith('/') || result.startsWith('https://') || result.startsWith('http://')) {
return `<img src="${result}" />`
return `<img ${args?.length > 0 ? args : ''} src="${result}" />`
} else {
return result
}
Expand Down

0 comments on commit 48afb63

Please sign in to comment.