chore: add Plop template and configuration

This commit is contained in:
Stefan Imhoff
2023-06-09 20:17:26 +02:00
parent af1a662bf0
commit 5424821458
2 changed files with 81 additions and 0 deletions

70
plopfile.cjs Normal file
View File

@@ -0,0 +1,70 @@
/* eslint-disable func-names */
const moment = require('moment');
const currentDir = process.cwd();
const templatePath = 'plop';
const date = moment().format();
const year = moment().format('YYYY');
module.exports = function (plop) {
const tags = [
'book',
'code',
'design',
'download',
'film',
'philosophy',
'poetry',
'politics',
'productivity',
'recommendation',
'self-improvement',
'software',
'technology',
'writing',
];
plop.setGenerator('Post', {
description: 'Create a new post',
prompts: [
{
type: 'input',
name: 'title',
message: 'Title',
validate(value) {
if (/.+/.test(value)) {
return true;
}
return 'Title is required';
},
},
{
type: 'input',
name: 'description',
message: 'Description',
},
{
type: 'checkbox',
name: 'tags',
message: 'Tags',
choices: tags,
},
],
actions() {
process.chdir(plop.getPlopfilePath());
return [
{
type: 'addMany',
destination: `${currentDir}/src/content/journal/${year}`,
base: `${templatePath}/post`,
templateFiles: '**/*.txt',
stripExtensions: ['txt'],
data: {
date,
},
},
];
},
});
};