Fix next_url: add new option to decodeURI

This commit is contained in:
Mimi 2023-07-04 17:40:56 +08:00
parent d1b22042e5
commit b85201b9b8
3 changed files with 7 additions and 3 deletions

View File

@ -18,7 +18,7 @@
{{ next_url(page.post_link, page.post_link, {title: page.title}) }}
{%- else %}
<strong>{{ __('post.copyright.link') + __('symbol.colon') }}</strong>
{{ next_url(page.permalink, page.permalink, {title: page.title}) }}
{{ next_url(page.permalink, page.permalink, {title: page.title}, true) }}
{%- endif %}
</li>
<li class="post-copyright-license">

View File

@ -3,7 +3,7 @@
const { htmlTag } = require('hexo-util');
const { parse } = require('url');
module.exports = function(path, text, options = {}) {
module.exports = function(path, text, options = {}, decode = false) {
const { config, theme } = this;
const data = parse(path);
const siteHost = parse(config.url).hostname || config.url;
@ -50,5 +50,5 @@ module.exports = function(path, text, options = {}) {
}
}
return htmlTag(tag, attrs, decodeURI(text), false);
return htmlTag(tag, attrs, decode ? decodeURI(text) : text, false);
};

View File

@ -32,6 +32,10 @@ describe('next-url', () => {
nextUrl('https://theme-next.js.org', 'Text').should.eql('<a href="https://theme-next.js.org/" rel="noopener" target="_blank">Text</a>');
});
it('decodeURI', () => {
(() => nextUrl('https://theme-next.js.org', 'A % B')).should.not.throw();
});
it('exturl enabled', () => {
hexo.theme.exturl = true;
const encoded = btoa('https://theme-next.js.org');