summary refs log tree commit diff
path: root/lib/utils.ts
blob: f75c0e496306adf84d3e6475e0aa66b34eb46e6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import * as fs from "fs";
import { Date } from './interfaces';
import Post from './Post'

export function readDir(path: string): Array<string> {
  if (fs.existsSync(path)) {
    return fs.readdirSync(path);
  } else {
    throw `Path "${path}" doesn't exist`;
  }
}

export function sortPosts(posts: Array<Post>): Array<Post> {
    return posts;
}

export function dateToString({ year, month, day }: Date): string {
    return `${year}-${month}-${day}`
}

export function dateToPath({ year, month, day }: Date): string {
    return `${year}/${month}/${day}`
}