Add exturl icon option (#192)

This commit is contained in:
小柚子 2021-02-17 11:56:05 +08:00 committed by GitHub
parent 3a1b30afee
commit 7821062db1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -461,6 +461,8 @@ index_with_subtitle: false
# Automatically add external URL with Base64 encrypt & decrypt.
exturl: false
# If true, an icon will be attached to each external URL
exturl_icon: true
# Google Webmaster tools verification.
# See: https://developers.google.com/search

View File

@ -13,6 +13,8 @@ hexo.extend.filter.register('after_post_render', data => {
}
if (theme.exturl) {
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) => {
// Exit if the href attribute doesn't exists.
if (!href) return match;
@ -23,9 +25,9 @@ hexo.extend.filter.register('after_post_render', data => {
// Return encrypted URL with 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>`;
});
}