1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-06-25 18:56:25 +02:00

new post script

This commit is contained in:
Matthias Kretschmann 2018-09-29 23:05:14 +02:00
parent 0497764f2a
commit e4cc61b696
Signed by: m
GPG Key ID: 606EEEF3C479A91F
4 changed files with 13 additions and 12 deletions

View File

@ -110,7 +110,7 @@ npm run format:css
### 🎈 Add a new project ### 🎈 Add a new project
```bash ```bash
npm run new -- "Hello" npm run new "Hello"
``` ```
... ...

View File

@ -82,6 +82,7 @@
"eslint-plugin-react": "^7.11.1", "eslint-plugin-react": "^7.11.1",
"markdownlint": "^0.11.0", "markdownlint": "^0.11.0",
"markdownlint-cli": "^0.13.0", "markdownlint-cli": "^0.13.0",
"ora": "^3.0.0",
"prettier": "^1.14.3", "prettier": "^1.14.3",
"prettier-stylelint": "^0.4.2", "prettier-stylelint": "^0.4.2",
"stylelint": "^9.6.0", "stylelint": "^9.6.0",

View File

@ -1,6 +1,5 @@
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
import prepend from 'prepend'
import slugify from 'slugify' import slugify from 'slugify'
import ora from 'ora' import ora from 'ora'
@ -10,21 +9,24 @@ const template = fs.readFileSync(templatePath).toString()
const spinner = ora('Adding new project').start() const spinner = ora('Adding new project').start()
if (!process.argv[2]) { if (!process.argv[2]) {
spinner.fail('Use the format `npm run new -- Title of post`') spinner.fail('Use the format `npm run new "Title of post"`')
} }
const title = process.argv[2] const title = process.argv[2]
spinner.text = `Adding '${title}'.` spinner.text = `Adding '${title}'.`
const titleSlug = slugify(title, { lower: true }) const titleSlug = slugify(title, { lower: true })
const postsPath = path.join(__dirname, 'content', 'posts') const postsPath = path.join('.', 'content', 'posts')
const date = new Date().toISOString()
const newContents = template const newContents = template
.split('TITLE') .split('TITLE')
.join(title) .join(title)
.split('DATE') .split('DATE')
.join(Date.now()) .join(date)
// prepend(projects, newContents, error => { const datePath = date.slice(0, 10)
// if (error) spinner.fail(error)
// spinner.succeed(`Added '${title}' to top of projects.yml file.`) fs.appendFile(`${postsPath}/${datePath}-${titleSlug}.md`, newContents, err => {
// }) if (err) spinner.fail(`Error creating post: ${err}`)
spinner.succeed(`New post '${title}' created.`)
})

View File

@ -1,10 +1,8 @@
--- ---
type: post type: post
date: DATE
title: TITLE title: TITLE
author: Matthias Kretschmann
date: DATE
tags: tags:
- tag - tag