@@ -45,21 +45,42 @@ export const getFileContributorInfo = async (
45
45
return { contributors, lastUpdatedDate }
46
46
}
47
47
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
+
48
72
export const getPageContributorInfo = async (
49
73
pagePath : string ,
50
74
locale : Lang ,
51
75
cache : CommitHistory
52
76
) => {
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
+ )
63
84
64
85
const uniqueGitContributors = gitContributors . filter (
65
86
( contributor , index , self ) =>
0 commit comments