Skip to content

Commit c622521

Browse files
committed
fix: getLastModifiedDate for non-markdown pages
1 parent 2002005 commit c622521

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/lib/utils/contributors.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const getFileContributorInfo = async (
2727
cache
2828
)
2929

30-
const latestCommitDate = getLastModifiedDate(slug, locale!)
30+
const latestCommitDate = getLastModifiedDate(slug, locale!, true)
3131
const gitHubLastEdit = gitContributors[0]?.date
3232
const lastUpdatedDate = gitHubLastEdit || latestCommitDate
3333

@@ -90,10 +90,12 @@ export const getPageContributorInfo = async (
9090
const latestCommitDate = getLastModifiedDate(pagePath, locale!)
9191
const gitHubLastEdit = uniqueGitContributors[0]?.date
9292

93-
const lastEditLocaleTimestamp = getLocaleTimestamp(
94-
locale,
95-
gitHubLastEdit || latestCommitDate
96-
)
93+
let lastEditLocaleTimestamp = ""
94+
if (latestCommitDate) {
95+
lastEditLocaleTimestamp = getLocaleTimestamp(locale, latestCommitDate)
96+
} else if (gitHubLastEdit) {
97+
lastEditLocaleTimestamp = getLocaleTimestamp(locale, gitHubLastEdit)
98+
}
9799

98100
return { contributors: uniqueGitContributors, lastEditLocaleTimestamp }
99101
}

src/lib/utils/gh.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,24 @@ const extractDateFromGitLogInfo = (logInfo: string): string => {
2626
}
2727

2828
// This util filters the git log to get the file last commit info, and then the commit date (last update)
29-
export const getLastModifiedDate = (slug: string, locale: string): string => {
29+
export const getLastModifiedDate = (
30+
slug: string,
31+
locale: string,
32+
isMarkdown?: boolean
33+
): string => {
34+
if (!isMarkdown) {
35+
const appPagePaths = [
36+
join("app/[locale]", slug, "page.tsx"),
37+
join("app/[locale]", slug, "_components", `${slug.split("/").pop()}.tsx`),
38+
]
39+
const logs = appPagePaths.map(getGitLogFromPath)
40+
const dates = logs.map(extractDateFromGitLogInfo)
41+
const latestCommitDate = dates.reduce((a, b) =>
42+
new Date(a) > new Date(b) ? a : b
43+
)
44+
return latestCommitDate
45+
}
46+
3047
const translatedContentPath = join(TRANSLATIONS_DIR, locale, slug, "index.md")
3148
const contentIsNotTranslated = !fs.existsSync(translatedContentPath)
3249
let filePath = ""

0 commit comments

Comments
 (0)