From 74b3bf204b929be0c6684fed8d3c52bc0a653a9b Mon Sep 17 00:00:00 2001 From: xhiroga <13391129+xhiroga@users.noreply.github.com> Date: Sun, 28 Aug 2022 09:27:56 +0900 Subject: [PATCH 1/3] feat: ignore github reserved paths --- src/main.ts | 4 ++-- src/utils.ts | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index 0842230..1a6be4b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import { isGitHubRepoUrl, getRepoPathFromUrl, isSameGitHubRepo } from './utils' +import { isGitHubRepoUrl, getRepoPathFromUrl, isSameGitHubRepo, isGitHubReservedName } from './utils' const timer = (ms: number) => new Promise((res) => setTimeout(res, ms)) @@ -24,7 +24,7 @@ const run = async () => { } const filtered = Array.from(anchors).filter( (a) => - isGitHubRepoUrl(a.href) && !isSameGitHubRepo(a.href, window.location.href) + isGitHubRepoUrl(a.href) && !isGitHubReservedName(a.href) && !isSameGitHubRepo(a.href, location.href) ) for (const a of filtered) { displayStarCount(a) diff --git a/src/utils.ts b/src/utils.ts index 9afe646..6126ced 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -5,6 +5,25 @@ const GITHUB_REPO_REGEX = new RegExp( export const isGitHubRepoUrl = (url: string): boolean => GITHUB_REPO_REGEX.test(url) +const GITHUB_RESERVE_PATHS = [ + 'about', + 'blog', + 'contact', + 'explore', + 'features', + 'marketplace', + 'pricing', + 'security', + 'site', + 'topics', + 'trending', +] + +export const isGitHubReservedName = (href: string): boolean => { + const path = href.split('/').slice(3) + return GITHUB_RESERVE_PATHS.includes(path[0]) +} + export const isSameGitHubRepo = (href: string, current: string): boolean => { const hrefRepoPath = href.match(GITHUB_REPO_REGEX) const currentRepoPath = current.match(GITHUB_REPO_REGEX) From c7c8137295a8e563262124823f19bdc07b1487e8 Mon Sep 17 00:00:00 2001 From: Hiroaki Ogasawara <13391129+xhiroga@users.noreply.github.com> Date: Wed, 18 Jan 2023 21:20:15 +0900 Subject: [PATCH 2/3] Update src/utils.ts --- src/utils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils.ts b/src/utils.ts index 6126ced..1965595 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -15,6 +15,7 @@ const GITHUB_RESERVE_PATHS = [ 'pricing', 'security', 'site', + 'sponsors', 'topics', 'trending', ] From a1f06ec1d419deda5785a91d8e09474b55988724 Mon Sep 17 00:00:00 2001 From: xhiroga <13391129+xhiroga@users.noreply.github.com> Date: Wed, 18 Jan 2023 21:21:53 +0900 Subject: [PATCH 3/3] refactor: rename var --- src/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 1965595..97b8192 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -5,7 +5,7 @@ const GITHUB_REPO_REGEX = new RegExp( export const isGitHubRepoUrl = (url: string): boolean => GITHUB_REPO_REGEX.test(url) -const GITHUB_RESERVE_PATHS = [ +const GITHUB_RESERVED_PATHS = [ 'about', 'blog', 'contact', @@ -22,7 +22,7 @@ const GITHUB_RESERVE_PATHS = [ export const isGitHubReservedName = (href: string): boolean => { const path = href.split('/').slice(3) - return GITHUB_RESERVE_PATHS.includes(path[0]) + return GITHUB_RESERVED_PATHS.includes(path[0]) } export const isSameGitHubRepo = (href: string, current: string): boolean => {