Skip to content

Commit

Permalink
add perf to shortcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
nickreese committed May 11, 2022
1 parent 01ec0aa commit 3dd174e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ const hooks: Array<HookOptions> = [
layoutHtml,
shortcodes,
allRequests,
perf,
}) => {
const ShortcodeParser = prepareShortcodeParser({
perf,
shortcodes,
helpers,
data,
Expand Down Expand Up @@ -215,7 +217,7 @@ const hooks: Array<HookOptions> = [
console.log(`${Math.round(timings.slice(-1)[0].duration * 10) / 10}ms: \t ${request.permalink}`);
displayPerfTimings([...timings]);
} else {
console.log(request.permalink);
console.log(request.req.path);
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions src/utils/__tests__/prepareShortcodeParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ jest.mock('@elderjs/shortcodes', () => (opts) => new ShortcodeParser(opts));
jest.mock('../createReadOnlyProxy');

const args = {
perf: {
start: () => '',
end: () => '',
},
helpers: {},
data: {},
request: {},
Expand Down
7 changes: 7 additions & 0 deletions src/utils/prepareShortcodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function prepareShortcodeParser({
cssStack,
headStack,
customJsStack,
perf,
}) {
const { openPattern, closePattern } = settings.shortcodes;
const shortcodeParser = ShortcodeParser({ openPattern, closePattern });
Expand All @@ -26,7 +27,11 @@ function prepareShortcodeParser({
);

shortcodeParser.add(shortcode.shortcode, async (props, content) => {
perf.start(shortcode.shortcode);
console.log('hit', shortcode, perf);

const shortcodeResponse = await shortcode.run({
perf,
props,
content,
plugin: shortcode.plugin,
Expand Down Expand Up @@ -86,9 +91,11 @@ function prepareShortcodeParser({
string: head,
});
}
perf.end(shortcode.shortcode);
return html || '';
}

perf.end(shortcode.shortcode);
return shortcodeResponse || '';
});
});
Expand Down

0 comments on commit 3dd174e

Please sign in to comment.