diff --git a/site/src/pages/index.js b/site/src/pages/index.js index d59fb9d..aee7183 100644 --- a/site/src/pages/index.js +++ b/site/src/pages/index.js @@ -84,14 +84,14 @@ const IndexPage = () => { diff --git a/site/src/utils.js b/site/src/utils.js index a4125bd..d5d7f59 100644 --- a/site/src/utils.js +++ b/site/src/utils.js @@ -1,10 +1,10 @@ import Cache from "tmp-cache"; const memoize = fn => { - const cache = {}; + const cache = new Cache(300); return arg => { - if (!(arg in cache)) cache[arg] = fn(arg); - return cache[arg]; + if (!cache.has(arg)) cache.set(arg, fn(arg)); + return cache.get(arg); }; }; @@ -24,7 +24,7 @@ const memoizeSearch = fn => { }; export const githubName = memoize(link => - link.replace("https://github.com/", "") + link.replace(/^https:\/\/github.com\//, "") ); const lower = memoize(str => str.toLowerCase()); @@ -36,7 +36,7 @@ export const findHooks = memoizeSearch((term, arr) => { if (term === "#") return arr.filter(hook => hook.tags && hook.tags.length > 0); if (term[0] === "#") { - const tagToSearch = lower(term.replace("#", "")); + const tagToSearch = lower(term.substring(1)); return arr.filter(hook => lowerArray(hook.tags).some(tag => tag.includes(tagToSearch)) ); @@ -44,6 +44,6 @@ export const findHooks = memoizeSearch((term, arr) => { return arr.filter( hook => lower(hook.name).includes(lower(term)) || - lower(githubName(hook.repositoryUrl)).includes(lower(term)) + lower(hook.repositoryUrl).includes(lower(term)) ); });