Skip to content

Commit

Permalink
Improve highlighting a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
stereobooster committed Feb 17, 2019
1 parent c50c048 commit b1b132d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions site/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ const IndexPage = () => {
<Hook key={`${hook.repositoryUrl}-${hook.name}`}>
<RepositoryLink href={hook.repositoryUrl}>
<Highlighter
searchWords={[term]}
searchWords={[githubName(search)]}
autoEscape={true}
textToHighlight={githubName(hook.repositoryUrl)}
/>
</RepositoryLink>
<Name>
<Highlighter
searchWords={[term]}
searchWords={[search]}
autoEscape={true}
textToHighlight={hook.name}
/>
Expand Down
12 changes: 6 additions & 6 deletions site/src/utils.js
Original file line number Diff line number Diff line change
@@ -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);
};
};

Expand All @@ -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());
Expand All @@ -36,14 +36,14 @@ 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))
);
}
return arr.filter(
hook =>
lower(hook.name).includes(lower(term)) ||
lower(githubName(hook.repositoryUrl)).includes(lower(term))
lower(hook.repositoryUrl).includes(lower(term))
);
});

0 comments on commit b1b132d

Please sign in to comment.