-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
26 lines (23 loc) · 770 Bytes
/
Copy pathutils.js
File metadata and controls
26 lines (23 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const path = require('path')
const { promisify } = require('util')
const frontMatter = require('front-matter')
const fs = require('fs')
const readdir = promisify(fs.readdir)
const readFile = promisify(fs.readFile)
const deserialize = parsed => ({
title: parsed.attributes.title,
summary: parsed.attributes.summary,
url: parsed.attributes.url,
date: parsed.attributes.date,
body: parsed.body
})
async function fetch(markdown_name) {
const postsDir = path.join(__dirname, 'posts');
this.markdown_name = markdown_name;
return Promise.resolve((async () => {
const markdown = await readFile(path.join(postsDir, this.markdown_name + '.md'), 'utf-8')
const parsed = frontMatter(markdown)
return deserialize(parsed)
})())
}
exports.fetch = fetch