Skip to content

Commit 3dd174e

Browse files
committed
add perf to shortcodes
1 parent 01ec0aa commit 3dd174e

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/hooks/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ const hooks: Array<HookOptions> = [
5757
layoutHtml,
5858
shortcodes,
5959
allRequests,
60+
perf,
6061
}) => {
6162
const ShortcodeParser = prepareShortcodeParser({
63+
perf,
6264
shortcodes,
6365
helpers,
6466
data,
@@ -215,7 +217,7 @@ const hooks: Array<HookOptions> = [
215217
console.log(`${Math.round(timings.slice(-1)[0].duration * 10) / 10}ms: \t ${request.permalink}`);
216218
displayPerfTimings([...timings]);
217219
} else {
218-
console.log(request.permalink);
220+
console.log(request.req.path);
219221
}
220222
}
221223
},

src/utils/__tests__/prepareShortcodeParser.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ jest.mock('@elderjs/shortcodes', () => (opts) => new ShortcodeParser(opts));
2020
jest.mock('../createReadOnlyProxy');
2121

2222
const args = {
23+
perf: {
24+
start: () => '',
25+
end: () => '',
26+
},
2327
helpers: {},
2428
data: {},
2529
request: {},

src/utils/prepareShortcodeParser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function prepareShortcodeParser({
1313
cssStack,
1414
headStack,
1515
customJsStack,
16+
perf,
1617
}) {
1718
const { openPattern, closePattern } = settings.shortcodes;
1819
const shortcodeParser = ShortcodeParser({ openPattern, closePattern });
@@ -26,7 +27,11 @@ function prepareShortcodeParser({
2627
);
2728

2829
shortcodeParser.add(shortcode.shortcode, async (props, content) => {
30+
perf.start(shortcode.shortcode);
31+
console.log('hit', shortcode, perf);
32+
2933
const shortcodeResponse = await shortcode.run({
34+
perf,
3035
props,
3136
content,
3237
plugin: shortcode.plugin,
@@ -86,9 +91,11 @@ function prepareShortcodeParser({
8691
string: head,
8792
});
8893
}
94+
perf.end(shortcode.shortcode);
8995
return html || '';
9096
}
9197

98+
perf.end(shortcode.shortcode);
9299
return shortcodeResponse || '';
93100
});
94101
});

0 commit comments

Comments
 (0)