From 5424821458004e3201920d6a9c8f3361baee6898 Mon Sep 17 00:00:00 2001 From: Stefan Imhoff Date: Fri, 9 Jun 2023 20:17:26 +0200 Subject: [PATCH] chore: add Plop template and configuration --- plop/post/{{dashCase title}}.mdx.txt | 11 +++++ plopfile.cjs | 70 ++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 plop/post/{{dashCase title}}.mdx.txt create mode 100644 plopfile.cjs diff --git a/plop/post/{{dashCase title}}.mdx.txt b/plop/post/{{dashCase title}}.mdx.txt new file mode 100644 index 0000000..99d4ea1 --- /dev/null +++ b/plop/post/{{dashCase title}}.mdx.txt @@ -0,0 +1,11 @@ +--- +draft: true +title: {{titleCase title}} +slug: {{dashCase title}} +date: {{date}} +author: Stefan Imhoff +description: {{description}} +tags: [{{#each tags}}"{{.}}"{{#unless @last}}, {{/unless}}{{/each}}] +--- + +Hello World! diff --git a/plopfile.cjs b/plopfile.cjs new file mode 100644 index 0000000..26ed756 --- /dev/null +++ b/plopfile.cjs @@ -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, + }, + }, + ]; + }, + }); +};