Created
September 17, 2025 17:50
-
-
Save keif/faee0f369096fd74463a7c1fda05b13e to your computer and use it in GitHub Desktop.
Helper function to get the Last Updated date on a file when publishing.
This file contains hidden or 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
// eslint-disable-next-line @typescript-eslint/no-var-requires | |
const fs = require('fs'); | |
function getFileTimestamp(filePath) { | |
try { | |
const stats = fs.statSync(filePath); | |
const mtime = stats.mtime; | |
return mtime.toLocaleDateString('en-US', { | |
year: 'numeric', | |
month: 'long', | |
day: 'numeric', | |
}); | |
} catch (error) { | |
// eslint-disable-next-line no-console | |
console.error('Error getting file timestamp:', error); | |
return null; | |
} | |
} | |
module.exports = { getFileTimestamp }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment