mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-17 18:22:33 +00:00
Add exturl icon option (#192)
This commit is contained in:
parent
3a1b30afee
commit
7821062db1
@ -461,6 +461,8 @@ index_with_subtitle: false
|
|||||||
|
|
||||||
# Automatically add external URL with Base64 encrypt & decrypt.
|
# Automatically add external URL with Base64 encrypt & decrypt.
|
||||||
exturl: false
|
exturl: false
|
||||||
|
# If true, an icon will be attached to each external URL
|
||||||
|
exturl_icon: true
|
||||||
|
|
||||||
# Google Webmaster tools verification.
|
# Google Webmaster tools verification.
|
||||||
# See: https://developers.google.com/search
|
# See: https://developers.google.com/search
|
||||||
|
|||||||
@ -13,6 +13,8 @@ hexo.extend.filter.register('after_post_render', data => {
|
|||||||
}
|
}
|
||||||
if (theme.exturl) {
|
if (theme.exturl) {
|
||||||
const siteHost = parse(config.url).hostname || config.url;
|
const siteHost = parse(config.url).hostname || config.url;
|
||||||
|
// External URL icon
|
||||||
|
const exturlIcon = theme.exturl_icon ? '<i class="fa fa-external-link-alt"></i>' : '';
|
||||||
data.content = data.content.replace(/<a[^>]* href="([^"]+)"[^>]*>([^<]+)<\/a>/img, (match, href, html) => {
|
data.content = data.content.replace(/<a[^>]* href="([^"]+)"[^>]*>([^<]+)<\/a>/img, (match, href, html) => {
|
||||||
// Exit if the href attribute doesn't exists.
|
// Exit if the href attribute doesn't exists.
|
||||||
if (!href) return match;
|
if (!href) return match;
|
||||||
@ -23,9 +25,9 @@ hexo.extend.filter.register('after_post_render', data => {
|
|||||||
|
|
||||||
// Return encrypted URL with title.
|
// Return encrypted URL with title.
|
||||||
const title = match.match(/title="([^"]+)"/);
|
const title = match.match(/title="([^"]+)"/);
|
||||||
if (title) return `<span class="exturl" data-url="${Buffer.from(href).toString('base64')}" title="${title[1]}">${html}<i class="fa fa-external-link-alt"></i></span>`;
|
if (title) return `<span class="exturl" data-url="${Buffer.from(href).toString('base64')}" title="${title[1]}">${html}${exturlIcon}</span>`;
|
||||||
|
|
||||||
return `<span class="exturl" data-url="${Buffer.from(href).toString('base64')}">${html}<i class="fa fa-external-link-alt"></i></span>`;
|
return `<span class="exturl" data-url="${Buffer.from(href).toString('base64')}">${html}${exturlIcon}</span>`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user