Skip to content

Commit

Permalink
refactor: reduce the plain object size
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Jun 27, 2020
1 parent f9f6265 commit 129b5e5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/plugins/filter/before_generate/render_post.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function renderPostFilter(data) {

return Promise.map(posts, post => {
return Promise.resolve(post._content).then(_content => {
return pool.run({ input: _content, siteCfg: this.config });
return pool.run({ input: _content, highlightCfg: this.config.highlight, prismjsCfg: this.config.prismjs });
}).then(content => {
post.content = content;
post.site = { data };
Expand Down
5 changes: 1 addition & 4 deletions lib/workers/backtick_codeblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ const rLangCaption = /([^\s]+)\s*(.+)?/;

const escapeSwigTag = str => str.replace(/{/g, '{').replace(/}/g, '}');

function backtickCodeBlock(input, siteCfg) {
function backtickCodeBlock(input, hljsCfg = {}, prismCfg = {}) {
if (!input.includes('```') && !input.includes('~~~')) return input;

const hljsCfg = siteCfg.highlight || {};
const prismCfg = siteCfg.prismjs || {};

return input.replace(rBacktick, ($0, start, $2, _args, _content, end) => {

let content = _content.replace(/\n$/, '');
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/backtick_codeblock_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const { isMainThread, parentPort } = require('worker_threads');

if (isMainThread) throw new Error('It is not a worker, it is now at Main Thread.');

parentPort.on('message', ({ input, siteCfg }) => {
const result = backtickCodeBlock(input, siteCfg);
parentPort.on('message', ({ input, highlightCfg, prismjsCfg }) => {
const result = backtickCodeBlock(input, highlightCfg, prismjsCfg);

parentPort.postMessage(result);
});

0 comments on commit 129b5e5

Please sign in to comment.