Skip to content

Commit f24d9a3

Browse files
committed
fix: use github history for last app page edit
make date required for last commit from github data; 0 date fallback from crowdin contributor data
1 parent 8a6cc65 commit f24d9a3

File tree

6 files changed

+34
-25
lines changed

6 files changed

+34
-25
lines changed

app/[locale]/get-eth/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { CommitHistory, Lang } from "@/lib/types"
1010
import I18nProvider from "@/components/I18nProvider"
1111

1212
import { getAppPageContributorInfo } from "@/lib/utils/contributors"
13-
import { getLastModifiedDateByPath } from "@/lib/utils/gh"
13+
import { getLastGitCommitDateByPath } from "@/lib/utils/gh"
1414
import { getMetadata } from "@/lib/utils/metadata"
1515
import { getRequiredNamespacesForPage } from "@/lib/utils/translations"
1616

@@ -27,7 +27,7 @@ export default async function Page({
2727

2828
setRequestLocale(locale)
2929

30-
const lastDataUpdateDate = getLastModifiedDateByPath(
30+
const lastDataUpdateDate = getLastGitCommitDateByPath(
3131
"src/data/exchangesByCountry.ts"
3232
)
3333

src/layouts/stories/ContentLayout.stories.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,18 @@ export const ContentLayout: StoryObj<typeof meta> = {
6363
},
6464
maxDepth: 2,
6565
contributors: [
66-
{ login: "github", avatar_url: "/", html_url: "https://github.com" },
67-
{ login: "crowdin", avatar_url: "/", html_url: "https://crowdin.com" },
66+
{
67+
login: "github",
68+
avatar_url: "/",
69+
html_url: "https://github.com",
70+
date: "2025-04-20T12:00:00.000Z",
71+
},
72+
{
73+
login: "crowdin",
74+
avatar_url: "/",
75+
html_url: "https://crowdin.com",
76+
date: "2025-04-20T12:00:00.000Z",
77+
},
6878
],
6979
lastEditLocaleTimestamp: "MM DD, YY",
7080
heroSection: (

src/lib/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ export type FileContributor = {
395395
login: string
396396
avatar_url: string
397397
html_url: string
398-
date?: string
398+
date: string
399399
}
400400

401401
type FilePath = string

src/lib/utils/contributors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export const getAppPageContributorInfo = async (
8989
index === self.findIndex((t) => t.login === contributor.login)
9090
)
9191

92-
const latestCommitDate = getAppPageLastCommitDate(pagePath)
92+
const latestCommitDate = getAppPageLastCommitDate(gitHubContributors)
9393
const lastEditLocaleTimestamp = getLocaleTimestamp(locale, latestCommitDate)
9494

9595
if (!uniqueGitHubContributors.length || !lastEditLocaleTimestamp) {

src/lib/utils/crowdin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ export const convertToFileContributorFromCrowdin = (
3030
login: username,
3131
avatar_url: avatarUrl,
3232
html_url: `https://crowdin.com/profile/${username}`,
33+
date: new Date(0).toString(),
3334
}))

src/lib/utils/gh.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { join } from "path"
44

55
import { CONTENT_DIR, DEFAULT_LOCALE, TRANSLATIONS_DIR } from "@/lib/constants"
66

7+
import { FileContributor } from "../types"
8+
79
const getGitLogFromPath = (path: string): string => {
810
// git command to show file last commit info
911
const gitCommand = `git log -1 -- ${path}`
@@ -25,17 +27,20 @@ const extractDateFromGitLogInfo = (logInfo: string): string => {
2527
}
2628
}
2729

28-
export const getAppPageLastCommitDate = (slug: string): string => {
29-
const appPagePaths = [
30-
join("app/[locale]", slug, "page.tsx"),
31-
join("app/[locale]", slug, "_components", `${slug.split("/").pop()}.tsx`),
32-
]
33-
const logs = appPagePaths.map(getGitLogFromPath)
34-
const dates = logs.map(extractDateFromGitLogInfo)
35-
const latestCommitDate = dates.reduce((a, b) =>
36-
new Date(a) > new Date(b) ? a : b
37-
)
38-
return latestCommitDate
30+
export const getAppPageLastCommitDate = (
31+
gitHubContributors: FileContributor[]
32+
) =>
33+
gitHubContributors
34+
.reduce((latest, contributor) => {
35+
const commitDate = new Date(contributor.date)
36+
return commitDate > latest ? commitDate : latest
37+
}, new Date(0))
38+
.toString()
39+
40+
export const getLastGitCommitDateByPath = (path: string): string => {
41+
if (!fs.existsSync(path)) throw new Error(`File not found: ${path}`)
42+
const logInfo = getGitLogFromPath(path)
43+
return extractDateFromGitLogInfo(logInfo)
3944
}
4045

4146
// This util filters the git log to get the file last commit info, and then the commit date (last update)
@@ -55,14 +60,7 @@ export const getMarkdownLastCommitDate = (
5560
filePath = join(TRANSLATIONS_DIR, locale, slug, "index.md")
5661
}
5762

58-
const logInfo = getGitLogFromPath(filePath)
59-
return extractDateFromGitLogInfo(logInfo)
60-
}
61-
62-
export const getLastModifiedDateByPath = (path: string): string => {
63-
if (!fs.existsSync(path)) throw new Error(`File not found: ${path}`)
64-
const logInfo = getGitLogFromPath(path)
65-
return extractDateFromGitLogInfo(logInfo)
63+
return getLastGitCommitDateByPath(filePath)
6664
}
6765

6866
const LABELS_TO_SEARCH = [

0 commit comments

Comments
 (0)