Skip to content

Commit 8fd912f

Browse files
committed
Allow start date to be set
1 parent 1442e40 commit 8fd912f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const quit = (message) => {
1212

1313
const cliOptions = [
1414
{name: 'input', defaultOption: true},
15-
{name: 'format', defaultValue: 'markdown'}
15+
{name: 'format', defaultValue: 'markdown'},
16+
{name: 'start', defaultValue: '1970-1-1'},
1617
]
1718

1819
const cli = commandLineArgs(cliOptions)
@@ -27,6 +28,10 @@ try {
2728
const links = {}
2829
const headers = ['Name', 'Category', 'Created', 'Summary', 'Tags', 'URL']
2930

31+
// Configure minimum date
32+
const start = Date.parse(cli.start)
33+
if (isNaN(start)) quit(`We couldn't parse ${cli.start} as a date.`)
34+
3035
// Open and parse CSV
3136
fs.createReadStream(cli.input)
3237
.pipe(csv({headers, skipLines: 1}))
@@ -35,6 +40,8 @@ try {
3540
Object.keys(data).forEach((row) => {
3641
item[row] = data[row]
3742
})
43+
let parsedCreatedDate = Date.parse(item['Created'])
44+
if (isNaN(parsedCreatedDate) || parsedCreatedDate < start) return
3845

3946
if (typeof links[data['Category']] === 'undefined') links[data['Category']] = {}
4047
if (!Array.isArray(links[data['Category']][data['Tags']])) links[data['Category']][data['Tags']] = []

0 commit comments

Comments
 (0)