on 16c28fa help sign in
urbit.org/scripts/date_to_string_upgrade.js
43 lines 997 B history raw
1const fs = require("fs");
2const matter = require("gray-matter");
3const toml = require("@iarna/toml");
4const path = require("path");
5const { DateTime } = require("luxon");
7const dir = path.join(process.cwd(), "../content/media");
9const options = {
10 engines: {
11 toml: {
12 parse: toml.parse.bind(toml),
13 stringify: toml.stringify.bind(toml),
14 },
15 },
16 language: "toml",
17 delimiters: "+++",
18};
20fs.readdirSync(dir, { withFileTypes: true })
21 .filter((f) => f.isFile() && f.name !== "_index.md")
22 .map((f, i) => {
23 const fileContents = matter(
24 fs.readFileSync(path.join(dir, f.name)),
25 options
26 );
28 const newDate = DateTime.fromJSDate(
29 new Date(fileContents.data.date)
30 ).toFormat("yyyy-MM-dd");
32 fileContents.data.date = newDate;
34 const data = matter.stringify(
35 fileContents.content,
36 fileContents.data,
37 options
38 );
40 // console.log(fileContents.data.date)
42 // fs.writeFileSync(path.join(dir, f.name), data);
43 });