Skip to content

Instantly share code, notes, and snippets.

@gucheen
Created January 21, 2021 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gucheen/d44fba1342092cd1881adac0b6e4981c to your computer and use it in GitHub Desktop.
Save gucheen/d44fba1342092cd1881adac0b6e4981c to your computer and use it in GitHub Desktop.
fix hugo md files' time by its created time
// 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