Skip to content

Commit 2002005

Browse files
committed
fix: use all historical page paths for contributions
1 parent b6448d1 commit 2002005

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

src/lib/utils/contributors.ts

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,42 @@ export const getFileContributorInfo = async (
4545
return { contributors, lastUpdatedDate }
4646
}
4747

48+
/**
49+
* Returns an array of possible historical file paths for a given page,
50+
* accounting for different directory structures and migrations over time.
51+
*
52+
* @param pagePath - The relative path of the page (without extension).
53+
* @returns An array of strings representing all historical file paths for the page.
54+
*
55+
* @remarks
56+
* This function is used to track all possible locations a page may have existed in the repository,
57+
* which is useful for aggregating git history and contributor information.
58+
*
59+
* @note
60+
* If a page is migrated or its location changes, ensure the new path is added to this list.
61+
* This maintains a complete historical record for accurate git history tracking.
62+
*/
63+
const getAllHistoricalPaths = (pagePath: string): string[] => [
64+
join("src/pages", `${pagePath}.tsx`),
65+
join("src/pages", pagePath, "index.tsx"),
66+
join("src/pages/[locale]", `${pagePath}.tsx`),
67+
join("src/pages/[locale]", pagePath, "index.tsx"),
68+
join("app/[locale]", pagePath, "page.tsx"),
69+
join("app/[locale]", pagePath, "_components", `${pagePath}.tsx`),
70+
]
71+
4872
export const getPageContributorInfo = async (
4973
pagePath: string,
5074
locale: Lang,
5175
cache: CommitHistory
5276
) => {
53-
const gitContributors = [
54-
...(await fetchAndCacheGitContributors(
55-
join("app/[locale]", pagePath, "page.tsx"),
56-
cache
57-
)),
58-
...(await fetchAndCacheGitContributors(
59-
join("app/[locale]", pagePath, "_components", `${pagePath}.tsx`),
60-
cache
61-
)),
62-
]
77+
const gitContributors = await getAllHistoricalPaths(pagePath).reduce(
78+
async (acc, path) => {
79+
const contributors = await fetchAndCacheGitContributors(path, cache)
80+
return [...(await acc), ...contributors]
81+
},
82+
Promise.resolve([] as FileContributor[])
83+
)
6384

6485
const uniqueGitContributors = gitContributors.filter(
6586
(contributor, index, self) =>

0 commit comments

Comments
 (0)