forked from appetizermonster/steempages
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformatter.js
More file actions
24 lines (19 loc) · 668 Bytes
/
formatter.js
File metadata and controls
24 lines (19 loc) · 668 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
'use strict';
const dateformat = require('dateformat');
function fixTitleTag(title) {
return title.replace('[', '(').replace(']', ')');
}
function fixImageLinks(body) {
// naive implementation
const re = /(!\[[^\]]*\]\()?(https?:\/\/.+\.(png|jpg|jpeg|gif))\)?/gm;
return body.replace(re, '<img src="$2" style="max-width:100%;">');
}
function makeMarkdown(title, body, created) {
const fixedTitle = fixTitleTag(title);
const fixedBody = fixImageLinks(body);
const _date = dateformat(created, 'yyyy-mm-dd hh:MM:ss +0000');
return `---\nlayout: post\ntitle: ${fixedTitle}\ndate: ${_date}\n---\n\n${fixedBody}`;
}
module.exports = {
makeMarkdown
};