-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplopfile.ts
More file actions
56 lines (54 loc) · 1.9 KB
/
plopfile.ts
File metadata and controls
56 lines (54 loc) · 1.9 KB
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
51
52
53
54
55
import type { NodePlopAPI } from 'plop';
export default function (plop: NodePlopAPI) {
plop.setHelper('current-date', () => new Date().toISOString());
plop.setHelper('current-year', () => new Date().getFullYear());
plop.setHelper('includes', (array, value) => array.includes(value));
plop.setGenerator('post', {
description: 'Create a new blog post',
prompts: [
{
type: 'input',
name: 'title',
message: 'Enter post title:',
validate: input => input ? true : 'This field is required'
},
{
type: 'input',
name: 'slug',
message: 'Enter slug (file path):',
default: (answers: { title: string }) => answers.title.toLowerCase().replace(/[^\w\s-]/g, '').replace(/\s+/g, '-')
},
{
type: 'input',
name: 'description',
message: 'Enter a short description:'
},
{
type: 'input',
name: 'tags',
message: 'Enter tags (comma-separated):',
validate: input => String(input).trim() ? true : 'This field is required',
filter: input =>
String(input)
.split(',')
.map(t => t.trim())
},
{
type: 'checkbox',
name: 'flags',
message: 'Any special visibility requirements?',
choices: [
{ name: 'Featured', value: 'featured' },
{ name: 'Draft', value: 'draft' }
]
},
],
actions: [
{
type: 'add',
path: 'src/data/blog/_{{current-year}}/{{slug}}.mdx',
templateFile: 'plop-templates/post.hbs'
}
]
});
}