-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
982401c
commit feba1f0
Showing
2 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const REPOS = ['usenocturne/nocturne-ui', 'usenocturne/nocturne-image'] | ||
|
||
export async function getLatestCommitDate() { | ||
try { | ||
const dates = await Promise.all( | ||
REPOS.map(async (repo) => { | ||
const response = await fetch( | ||
`https://api.github.com/repos/${repo}/commits/main`, | ||
{ | ||
next: { revalidate: 3600 }, | ||
headers: { | ||
Accept: 'application/vnd.github.v3+json', | ||
...(process.env.GITHUB_TOKEN && { | ||
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`, | ||
}), | ||
}, | ||
}, | ||
) | ||
|
||
if (!response.ok) { | ||
console.error(`Failed to fetch ${repo}:`, response.statusText) | ||
return null | ||
} | ||
|
||
const data = await response.json() | ||
return new Date(data.commit.committer.date) | ||
}), | ||
) | ||
|
||
const validDates = dates.filter((date): date is Date => date !== null) | ||
if (validDates.length === 0) { | ||
return new Date().toISOString().split('T')[0] | ||
} | ||
|
||
const latestTimestamp = Math.max( | ||
...validDates.map((date) => date.getTime()), | ||
) | ||
const latestDate = new Date(latestTimestamp) | ||
|
||
const formattedDate = latestDate.toISOString().split('T')[0] | ||
console.log('Formatted date for Schema.org:', formattedDate) | ||
return formattedDate | ||
} catch (error) { | ||
console.error('Error fetching commit dates:', error) | ||
const today = new Date().toISOString().split('T')[0] | ||
return today | ||
} | ||
} |