From 507836e74f4c0eba4558ef47a7465dfbec99faca Mon Sep 17 00:00:00 2001 From: streakingman Date: Wed, 27 Jul 2022 17:16:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(jekyll-md):=20=E6=96=B9=E6=B3=95=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- actions/jekyll-md.js | 4 ++++ utils/file-generator.js | 9 +-------- utils/jekyllMarkdownName.js | 11 +++++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 utils/jekyllMarkdownName.js diff --git a/actions/jekyll-md.js b/actions/jekyll-md.js index aaa0fb3..51c2dca 100644 --- a/actions/jekyll-md.js +++ b/actions/jekyll-md.js @@ -1,5 +1,7 @@ const inquirer = require('inquirer'); const { fileGenerator } = require('../utils/file-generator'); +const { jekyllMarkdownName } = require('../utils/jekyllMarkdownName'); +const { execSync } = require('child_process'); const jekyllMD = async (title, category, tags) => { if (!(title && category && tags)) { const { inputTitle, inputCategory, inputTags } = await inquirer.prompt([ @@ -33,6 +35,8 @@ const jekyllMD = async (title, category, tags) => { option: { title, category, tags }, }); + execSync(`git add ${jekyllMarkdownName(title)}`); + console.log(`📚 markdown文件生成完毕`); }; diff --git a/utils/file-generator.js b/utils/file-generator.js index 85da90d..4f69a81 100644 --- a/utils/file-generator.js +++ b/utils/file-generator.js @@ -1,18 +1,11 @@ const { version } = require('../package.json'); const { execSync } = require('child_process'); +const { jekyllMarkdownName } = require('./jekyllMarkdownName'); const fs = require('fs'); const fse = require('fs-extra'); const path = require('path'); const ejs = require('ejs'); -const jekyllMarkdownName = (title) => { - const now = new Date(); - const year = now.getFullYear().toString(); - const month = (now.getMonth() + 1).toString().padStart(2, '0'); - const date = now.getDate().toString().padStart(2, '0'); - return `${year}-${month}-${date}-${title.toLowerCase()}.md`; -}; - const generatorTemplateFileMap = { commitlint: '.commitlintrc.js', editor: '.editorconfig', diff --git a/utils/jekyllMarkdownName.js b/utils/jekyllMarkdownName.js new file mode 100644 index 0000000..27faa14 --- /dev/null +++ b/utils/jekyllMarkdownName.js @@ -0,0 +1,11 @@ +const jekyllMarkdownName = (title) => { + const now = new Date(); + const year = now.getFullYear().toString(); + const month = (now.getMonth() + 1).toString().padStart(2, '0'); + const date = now.getDate().toString().padStart(2, '0'); + return `${year}-${month}-${date}-${title.toLowerCase()}.md`; +}; + +module.exports = { + jekyllMarkdownName, +};