Skip to content

Commit ca1e73a

Browse files
author
ppoffice
committed
fix(layout): no external links on anchor links
1 parent bdaab0f commit ca1e73a

File tree

7 files changed

+15
-12
lines changed

7 files changed

+15
-12
lines changed

layout/common/footer.ejs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
</a>
1212
<p class="is-size-7">
1313
&copy; <%= date(new Date(), 'YYYY') %> <%= author || title %>&nbsp;
14-
Powered by <a href="https://hexo.io/" target="_blank">Hexo</a> & <a
15-
href="https://github.com/ppoffice/hexo-theme-icarus" target="_blank">Icarus</a>
14+
Powered by <a href="https://hexo.io/" target="_blank" rel="noopener">Hexo</a> & <a
15+
href="https://github.com/ppoffice/hexo-theme-icarus" target="_blank" rel="noopener">Icarus</a>
1616
<% if (busuanzi) { %>
1717
<br>
1818
<span id="busuanzi_container_site_uv">
@@ -27,7 +27,7 @@
2727
<% for (let name in links) {
2828
let link = links[name]; %>
2929
<p class="control">
30-
<a class="button is-white <%= typeof(link) !== 'string' ? 'is-large' : '' %>" target="_blank" title="<%= name %>" href="<%= url_for(typeof(link) === 'string' ? link : link.url) %>">
30+
<a class="button is-white <%= typeof(link) !== 'string' ? 'is-large' : '' %>" target="_blank" rel="noopener" title="<%= name %>" href="<%= url_for(typeof(link) === 'string' ? link : link.url) %>">
3131
<% if (typeof(link) === 'string') { %>
3232
<%= name %>
3333
<% } else { %>

layout/common/navbar.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<% if (Object.keys(links).length) { %>
2323
<% for (let name in links) {
2424
let link = links[name]; %>
25-
<a class="navbar-item" target="_blank" title="<%= name %>" href="<%= url_for(typeof(link) === 'string' ? link : link.url) %>">
25+
<a class="navbar-item" target="_blank" rel="noopener" title="<%= name %>" href="<%= url_for(typeof(link) === 'string' ? link : link.url) %>">
2626
<% if (typeof(link) === 'string') { %>
2727
<%= name %>
2828
<% } else { %>

layout/donate/patreon.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<% const url = get_config_from_obj(service, 'url');
22
if (url) { %>
3-
<a class="button is-danger donate" href="<%= url_for(url) %>" target="_blank">
3+
<a class="button is-danger donate" href="<%= url_for(url) %>" target="_blank" rel="noopener">
44
<span class="icon is-small">
55
<i class="fab fa-patreon"></i>
66
</span>

layout/donate/paypal.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</span>
99
<span><%= __('donate.' + type) %></span>
1010
</a>
11-
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank" id="paypal-donate-form">
11+
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank" rel="noopener" id="paypal-donate-form">
1212
<input type="hidden" name="cmd" value="_donations" />
1313
<input type="hidden" name="business" value="<%= business %>" />
1414
<input type="hidden" name="currency_code" value="<%= currency_code %>" />

layout/widget/links.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<ul class="menu-list">
88
<% for (let i in links) { %>
99
<li>
10-
<a class="level is-mobile" href="<%- links[i] %>" target="_blank">
10+
<a class="level is-mobile" href="<%- links[i] %>" target="_blank" rel="noopener">
1111
<span class="level-left">
1212
<span class="level-item"><%= i %></span>
1313
</span>

layout/widget/profile.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
</nav>
7878
<% if (widget.follow_link) { %>
7979
<div class="level">
80-
<a class="level-item button is-link is-rounded" href="<%= url_for(widget.follow_link) %>" target="_blank">
80+
<a class="level-item button is-link is-rounded" href="<%= url_for(widget.follow_link) %>" target="_blank" rel="noopener">
8181
<%= __('widget.follow') %></a>
8282
</div>
8383
<% } %>
@@ -86,7 +86,7 @@
8686
<div class="level is-mobile">
8787
<% for (let name in socialLinks) {
8888
let link = socialLinks[name]; %>
89-
<a class="level-item button is-white is-marginless" target="_blank"
89+
<a class="level-item button is-white is-marginless" target="_blank" rel="noopener"
9090
title="<%= name %>" href="<%= url_for(typeof(link) === 'string' ? link : link.url) %>">
9191
<% if (typeof(link) === 'string') { %>
9292
<%= name %>

source/js/main.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,12 @@
140140
typeof (IcarusThemeSettings.site.external_link) !== 'undefined' &&
141141
IcarusThemeSettings.site.external_link.enable) {
142142
$('.article .content a').filter(function (i, link) {
143-
return link.href && link.classList.length === 0 && isExternalLink(link.href,
144-
IcarusThemeSettings.site.url,
145-
IcarusThemeSettings.site.external_link.exclude);
143+
return link.href &&
144+
!$(link).attr('href').startsWith('#') &&
145+
link.classList.length === 0 &&
146+
isExternalLink(link.href,
147+
IcarusThemeSettings.site.url,
148+
IcarusThemeSettings.site.external_link.exclude);
146149
}).each(function (i, link) {
147150
link.relList.add('noopener');
148151
link.target = '_blank';

0 commit comments

Comments
 (0)