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, +};