Created
April 18, 2018 18:08
-
-
Save talves/3bc72cb35d4e633b1ef94a66a0f26493 to your computer and use it in GitHub Desktop.
Markdown pre-build script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
'use strict' | |
const fs = require('fs') | |
const path = require('path') | |
const matter = require('gray-matter') | |
const rootPath = path.resolve(__dirname, '../') | |
const dataPath = path.resolve(rootPath, './src/data/blog') | |
/* Documentation Data */ | |
const dirPath = path.resolve(rootPath, './posts') | |
const documentation = fs.readdirSync(dirPath) | |
.filter(file => fs.statSync(path.resolve(dirPath, file)).isFile()) | |
.map(file => { | |
const { data, content } = matter(fs.readFileSync(path.resolve(dirPath, file), 'utf8')) | |
console.log(file) | |
data.slug = (data.slug) ? data.slug : data.slug = file.split('.').slice(0, file.split('.').length - 1).join('.') | |
return { data, content } | |
}) | |
const postsFile = path.join(dataPath, './posts.json') | |
fs.writeFileSync(postsFile, JSON.stringify(documentation), { encoding: 'utf8', flag: 'w' }) | |
/* * * * * * * * * * */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment