Skip to content

Commit

Permalink
perf(helper): memoize
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Oct 2, 2021
1 parent c570ef7 commit c4c86ca
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/plugins/helper/open_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

const { parse, resolve } = require('url');
const { isMoment, isDate } = require('moment');
const { encodeURL, prettyUrls, htmlTag, stripHTML, escapeHTML, Cache } = require('hexo-util');
const { encodeURL, prettyUrls, htmlTag, stripHTML, escapeHTML } = require('hexo-util');
const { default: moize } = require('moize');

const localeMap = {
'en': 'en_US',
Expand All @@ -20,8 +21,8 @@ const localeMap = {
'tr': 'tr_TR',
'vi': 'vi_VN'
};
const localeCache = new Cache();
const localeToTerritory = str => localeCache.apply(str, () => {

const localeToTerritory = moize.shallow(str => {
if (str.length === 2 && localeMap[str]) return localeMap[str];

if (str.length === 5) {
Expand Down

0 comments on commit c4c86ca

Please sign in to comment.