-
Notifications
You must be signed in to change notification settings - Fork 99
/
blog-post-generator.js
50 lines (46 loc) · 1.2 KB
/
blog-post-generator.js
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const fs = require('fs');
const {inputRequired} = require('./utils');
const authors = JSON.parse(fs.readFileSync('./data/author.json'));
module.exports = plop => {
plop.setGenerator('blog post', {
prompts: [
{
type: 'input',
name: 'title',
message: 'Blog post title?',
validate: inputRequired('title')
},
{
type: 'list',
name: 'author',
message: 'The author of blog post?',
choices: authors.map(author => ({name: author.id, value: author.id}))
},
{
type: 'input',
name: 'tags',
message: 'tags? (separate with coma)'
},
{
type: 'confirm',
name: 'draft',
message: 'It\'s a draft?'
}
],
actions: data => {
// Get current date
data.createdDate = new Date().toISOString().split('T')[0];
// Parse tags as yaml array
if (data.tags) {
data.tags = `\ntags:\n - ${data.tags.split(',').join('\n - ')}`;
}
return [
{
type: 'add',
path: '../data/blog/{{createdDate}}--{{dashCase title}}/index.md',
templateFile: 'templates/blog-post-md.template'
}
];
}
});
};