1
0
Fork 0

switch to folder posts by default

This commit is contained in:
Matthias Kretschmann 2018-11-01 19:35:18 +01:00
parent 2476b1507c
commit 0daf09285a
Signed by: m
GPG Key ID: 606EEEF3C479A91F
4 changed files with 23 additions and 8 deletions

View File

@ -27,7 +27,7 @@
- [🍬 Typekit component](#-typekit-component)
- [✨ Development](#-development)
- [🔮 Linting](#-linting)
- [🎈 Add a new project](#-add-a-new-project)
- [🎈 Add a new post](#-add-a-new-post)
- [🚚 Deployment](#-deployment)
- [🏛 Licenses](#-licenses)
- [Posts](#-posts)
@ -163,13 +163,14 @@ npm run format
npm run format:css
```
### 🎈 Add a new project
### 🎈 Add a new post
```bash
npm run new "Hello"
npm run new "Hello World"
```
- [`scripts/new.js`](scripts/new.js)
- [`scripts/new.md`](scripts/new.md)
## 🚚 Deployment

View File

@ -87,6 +87,7 @@
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-react": "^7.11.1",
"fs-extra": "^7.0.0",
"markdownlint": "^0.11.0",
"markdownlint-cli": "^0.13.0",
"npm-run-all": "^4.1.3",

View File

@ -1,4 +1,4 @@
import fs from 'fs'
import fs from 'fs-extra'
import path from 'path'
import slugify from 'slugify'
import ora from 'ora'
@ -21,12 +21,24 @@ const date = new Date().toISOString()
const newContents = template
.split('TITLE')
.join(title)
.split('TITLE_SLUG')
.join(titleSlug)
.split('DATE')
.join(date)
const datePath = date.slice(0, 10)
const file = `${postsPath}/${datePath}-${titleSlug}/index.md`
fs.appendFile(`${postsPath}/${datePath}-${titleSlug}.md`, newContents, err => {
if (err) spinner.fail(`Error creating post: ${err}`)
spinner.succeed(`New post '${title}' created.`)
})
fs.outputFile(file, newContents)
.then(() => fs.readFile(file, 'utf8'))
.then(() => {
spinner.succeed(`New post '${title}' created.`)
})
.catch(err => {
spinner.fail(`Error creating post: ${err}`)
})
// fs.appendFile(`${postsPath}/${datePath}-${titleSlug}.md`, newContents, err => {
// if (err) spinner.fail(`Error creating post: ${err}`)
// spinner.succeed(`New post '${title}' created.`)
// })

View File

@ -3,6 +3,7 @@ type: post
date: DATE
title: TITLE
image: TITLE_SLUG-teaser.png
tags:
- tag