Created
January 21, 2021 06:15
-
-
Save gucheen/d44fba1342092cd1881adac0b6e4981c to your computer and use it in GitHub Desktop.
fix hugo md files' time by its created time
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
// hugo list all > posts.csv | |
/* | |
When you export your markdown files from other application or system, | |
Files' created time will be incorrect. | |
This script fix these time by its date from hugo front matter. | |
works by `touch` command | |
*/ | |
const fs = require('fs') | |
const path = require('path') | |
const Papa = require('papaparse') | |
const dayjs = require('dayjs') | |
const execa = require('execa') | |
const csv = fs.readFileSync(path.resolve(__dirname, 'posts.csv')).toString() | |
const posts = Papa.parse(csv); | |
(async () => { | |
for (const post of posts.data.slice(1)) { | |
const date = post[3] | |
const datestr = dayjs(date).format('YYYYMMDDHHmm.ss') | |
const file = path.resolve(__dirname, post[0]) | |
const {stdout} = await execa('touch', ['-m', `-t${datestr}`, file]); | |
} | |
console.log('done'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment