Skip to content

Commit aba666a

Browse files
committed
Merge branch 'master' into feat/fence
2 parents b3b65f5 + fbb69c3 commit aba666a

File tree

4 files changed

+82
-5
lines changed

4 files changed

+82
-5
lines changed

lib/extend/injector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Injector {
4444
}
4545

4646
getSize(entry: Entry): number {
47-
return this.cache.apply(`${entry}-size`, Object.keys(this.store[entry]).length) as number;
47+
return this.cache.apply(`${entry}-size`, () => Object.keys(this.store[entry]).length) as number;
4848
}
4949

5050
register(entry: Entry, value: string | (() => string), to = 'default'): void {

lib/plugins/filter/before_post_render/backtick_code_block.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { HighlightOptions } from '../../../extend/syntax_highlight';
22
import type Hexo from '../../../hexo';
33
import type { RenderData } from '../../../types';
44

5-
const rBacktick = /^((?:[^\S\r\n]*>){0,3}[^\S\r\n]*)(`{3,}|~{3,})[^\S\r\n]*((?:.*?[^`\s])?)[^\S\r\n]*\n((?:[\s\S]*?\n)?)(?:(?:[^\S\r\n]*>){0,3}[^\S\r\n]*)\2[^\S\r\n]?(\n+|$)/gm;
5+
const rBacktick = /^((?:(?:[^\S\r\n]*>){0,3}|[-*+]|[0-9]+\.)[^\S\r\n]*)(`{3,}|~{3,})[^\S\r\n]*((?:.*?[^`\s])?)[^\S\r\n]*\n((?:[\s\S]*?\n)?)(?:(?:[^\S\r\n]*>){0,3}[^\S\r\n]*)\2[^\S\r\n]?(\n+|$)/gm;
66
const rAllOptions = /([^\s]+)\s+(.+?)\s+(https?:\/\/\S+|\/\S+)\s*(.+)?/;
77
const rLangCaption = /([^\s]+)\s*(.+)?/;
88
const rAdditionalOptions = /\s((?:line_number|line_threshold|first_line|wrap|mark|language_attr|highlight):\S+)/g;

lib/plugins/helper/list_archives.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import type { LocalsType } from '../../types';
1+
import type Query from 'warehouse/dist/query';
2+
import type { LocalsType, PostSchema } from '../../types';
23
import { toMomentLocale } from './date';
3-
import { url_for } from 'hexo-util';
4+
import { url_for, Cache } from 'hexo-util';
45

56
interface Options {
67
format?: string;
@@ -20,6 +21,8 @@ interface Data {
2021
count: number;
2122
}
2223

24+
const postsCache = new Cache();
25+
2326
function listArchivesHelper(this: LocalsType, options: Options = {}) {
2427
const { config } = this;
2528
const archiveDir = config.archive_dir;
@@ -41,7 +44,7 @@ function listArchivesHelper(this: LocalsType, options: Options = {}) {
4144
format = type === 'monthly' ? 'MMMM YYYY' : 'YYYY';
4245
}
4346

44-
const posts = this.site.posts.sort('date', order);
47+
const posts = config.relative_link ? postsCache.apply(`date-${order}`, () => this.site.posts.sort('date', order)) as Query<PostSchema> : this.site.posts.sort('date', order);
4548
if (!posts.length) return result;
4649

4750
const data: Data[] = [];

test/scripts/filters/backtick_code_block.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,80 @@ describe('Backtick code block', () => {
692692
codeBlock(data);
693693
data.content.should.eql('<hexoPostRenderCodeBlock>' + expected + '</hexoPostRenderCodeBlock>');
694694
});
695+
696+
// https://github.com/hexojs/hexo/issues/5423
697+
it('with ordered list', () => {
698+
const data = {
699+
content: [
700+
'1. ``` js',
701+
code,
702+
'```',
703+
'2. ``` js',
704+
code,
705+
'```'
706+
].join('\n')
707+
};
708+
709+
codeBlock(data);
710+
data.content.should.eql([
711+
'1. <hexoPostRenderCodeBlock>' + highlight(code, { lang: 'js' }) + '</hexoPostRenderCodeBlock>',
712+
'2. <hexoPostRenderCodeBlock>' + highlight(code, { lang: 'js' }) + '</hexoPostRenderCodeBlock>'
713+
].join('\n'));
714+
});
715+
716+
// https://github.com/hexojs/hexo/issues/5423
717+
it('with unordered list', () => {
718+
let data = {
719+
content: [
720+
'- ``` js',
721+
code,
722+
'```',
723+
'- ``` js',
724+
code,
725+
'```'
726+
].join('\n')
727+
};
728+
729+
codeBlock(data);
730+
data.content.should.eql([
731+
'- <hexoPostRenderCodeBlock>' + highlight(code, { lang: 'js' }) + '</hexoPostRenderCodeBlock>',
732+
'- <hexoPostRenderCodeBlock>' + highlight(code, { lang: 'js' }) + '</hexoPostRenderCodeBlock>'
733+
].join('\n'));
734+
735+
data = {
736+
content: [
737+
'* ``` js',
738+
code,
739+
'```',
740+
'* ``` js',
741+
code,
742+
'```'
743+
].join('\n')
744+
};
745+
746+
codeBlock(data);
747+
data.content.should.eql([
748+
'* <hexoPostRenderCodeBlock>' + highlight(code, { lang: 'js' }) + '</hexoPostRenderCodeBlock>',
749+
'* <hexoPostRenderCodeBlock>' + highlight(code, { lang: 'js' }) + '</hexoPostRenderCodeBlock>'
750+
].join('\n'));
751+
752+
data = {
753+
content: [
754+
'+ ``` js',
755+
code,
756+
'```',
757+
'+ ``` js',
758+
code,
759+
'```'
760+
].join('\n')
761+
};
762+
763+
codeBlock(data);
764+
data.content.should.eql([
765+
'+ <hexoPostRenderCodeBlock>' + highlight(code, { lang: 'js' }) + '</hexoPostRenderCodeBlock>',
766+
'+ <hexoPostRenderCodeBlock>' + highlight(code, { lang: 'js' }) + '</hexoPostRenderCodeBlock>'
767+
].join('\n'));
768+
});
695769
});
696770

697771
describe('prismjs', () => {

0 commit comments

Comments
 (0)