Skip to content

Commit

Permalink
Merge branch 'master' into re/_test
Browse files Browse the repository at this point in the history
  • Loading branch information
D-Sketon committed Feb 22, 2024
2 parents c1badde + 7ef26ad commit a5ad976
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Also, we welcome PR or issue to [official-plugins](https://github.com/hexojs).

## Sponsors

<a href="https://linktr.ee/rss3"><img src="https://d1fdloi71mui9q.cloudfront.net/8xxahBqRTnecXgXKObeo_L8ks2KjC31fmM5Nd" alt="RSS3" width="200"/></a>
[![Sponsors](https://opencollective.com/hexo/tiers/sponsors.svg?width=600)](https://opencollective.com/hexo)

## License

Expand Down
8 changes: 7 additions & 1 deletion lib/plugins/tag/post_link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ export = (ctx: Hexo) => {
const attrTitle = escapeHTML(post.title || post.slug);
if (escape === 'true') title = escapeHTML(title);

const url = new URL(post.path, ctx.config.url).pathname + (hash ? `#${hash}` : '');
// guarantee the base url ends with a slash. (case of using a subdirectory in the url of the site)
let baseUrl = ctx.config.url;
if (!baseUrl.endsWith('/')) {
baseUrl += '/';
}

const url = new URL(post.path, baseUrl).pathname + (hash ? `#${hash}` : '');
const link = encodeURL(url);

return `<a href="${link}" title="${attrTitle}">${title}</a>`;
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/helpers/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('css', () => {
assertResult(css({href: '/script.css', foo: 'bar'}), {href: '/script.css', foo: 'bar'});
});

it('mulitple objects', () => {
it('multiple objects', () => {
assertResult(css({href: '/foo.css'}, {href: '/bar.css'}), [{href: '/foo.css'}, {href: '/bar.css'}]);
assertResult(css({href: '/aaa.css', bbb: 'ccc'}, {href: '/ddd.css', eee: 'fff'}),
[{href: '/aaa.css', bbb: 'ccc'}, {href: '/ddd.css', eee: 'fff'}]);
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/helpers/full_url_for.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('full_url_for', () => {
fullUrlFor('/index.html').should.eql(ctx.config.url + '/index.html');
});

it('internel url (pretty_urls.trailing_index disabled)', () => {
it('internal url (pretty_urls.trailing_index disabled)', () => {
ctx.config.pretty_urls = { trailing_index: false };
fullUrlFor('index.html').should.eql(ctx.config.url + '/');
fullUrlFor('/index.html').should.eql(ctx.config.url + '/');
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/helpers/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('js', () => {
assertResult(js({src: '/script.js', foo: 'bar'}), {src: '/script.js', foo: 'bar'});
});

it('mulitple objects', () => {
it('multiple objects', () => {
assertResult(js({src: '/foo.js'}, {src: '/bar.js'}), [{src: '/foo.js'}, {src: '/bar.js'}]);
assertResult(js({src: '/aaa.js', bbb: 'ccc'}, {src: '/ddd.js', eee: 'fff'}),
[{src: '/aaa.js', bbb: 'ccc'}, {src: '/ddd.js', eee: 'fff'}]);
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/helpers/url_for.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('url_for', () => {
ctx.config.relative_link = false;
});

it('internel url (pretty_urls.trailing_index disabled)', () => {
it('internal url (pretty_urls.trailing_index disabled)', () => {
ctx.config.pretty_urls = { trailing_index: false };
ctx.path = '';
ctx.config.root = '/';
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/hexo/hexo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('Hexo', () => {
hexo.config_path.should.eql(join(__dirname, '_config.yml'));
});

it('constructs mutli-config', () => {
it('constructs multi-config', () => {
const configs = ['../../../fixtures/_config.json', '../../../fixtures/_config.json'];
const args = { _: [], config: configs.join(',') };
const hexo = new Hexo(base_dir, args);
Expand Down
6 changes: 3 additions & 3 deletions test/scripts/hexo/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ describe('Post', () => {
});

// https://github.com/hexojs/hexo/issues/5301
it('render() - dont escape uncomplete tags', async () => {
it('render() - dont escape incomplete tags', async () => {
const content = 'dont drop `{% }` 11111 `{# }` 22222 `{{ }` 33333';

const data = await post.render('', {
Expand All @@ -1386,8 +1386,8 @@ describe('Post', () => {
data.content.should.not.contains('&#96;'); // `
});

it('render() - uncomplete tags throw error', async () => {
const content = 'nunjucks should thorw {# } error';
it('render() - incomplete tags throw error', async () => {
const content = 'nunjucks should throw {# } error';

try {
await post.render('', {
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/processors/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('asset', () => {
]);
});

it('asset - type: create (when source path is configed to parent directory)', async () => {
it('asset - type: create (when source path is configured to parent directory)', async () => {
const file = newFile({
path: '../../source/foo.jpg',
type: 'create',
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/tags/full_url_for.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('full_url_for', () => {
$('a').html()!.should.eql('index');
});

it('internel url (pretty_urls.trailing_index disabled)', () => {
it('internal url (pretty_urls.trailing_index disabled)', () => {
ctx.config.pretty_urls = { trailing_index: false };
let $ = cheerio.load(fullUrlFor('index index.html'));
$('a').attr('href')!.should.eql(ctx.config.url + '/');
Expand Down
5 changes: 5 additions & 0 deletions test/scripts/tags/post_link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ describe('post_link', () => {
it('should keep hash', () => {
postLink(['foo#bar']).should.eql('<a href="/foo/#bar" title="Hello world">Hello world</a>');
});

it('should keep subdir', () => {
hexo.config.url = 'http://example.com/subdir';
postLink(['foo']).should.eql('<a href="/subdir/foo/" title="Hello world">Hello world</a>');
});
});
2 changes: 1 addition & 1 deletion test/scripts/tags/url_for.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('url_for', () => {
ctx.config.relative_link = false;
});

it('internel url (pretty_urls.trailing_index disabled)', () => {
it('internal url (pretty_urls.trailing_index disabled)', () => {
ctx.config.pretty_urls = { trailing_index: false };
ctx.path = '';
ctx.config.root = '/';
Expand Down

0 comments on commit a5ad976

Please sign in to comment.