Read config as file
This commit is contained in:
parent
4ce788e750
commit
7e059b42c7
|
@ -1,14 +1,19 @@
|
|||
import fs from 'fs'
|
||||
import jsonfile from 'jsonfile'
|
||||
import path from 'path'
|
||||
import config from '../../config/config.json'
|
||||
|
||||
export function getData (reqPath = '') {
|
||||
if (reqPath === '') {
|
||||
return readData(config.dataPath)
|
||||
return Promise.all([
|
||||
readJson(path.join(process.cwd(), 'data.json')),
|
||||
readJson(path.join(process.cwd(), 'config/config.json'))
|
||||
])
|
||||
} else {
|
||||
const fileName = path.join(process.cwd(), config.contentPath, reqPath + '.md')
|
||||
return readFile(fileName, 'utf8')
|
||||
const fileName = path.join(process.cwd(), 'content', reqPath + '.md')
|
||||
return Promise.all([
|
||||
readFile(fileName, 'utf8'),
|
||||
readJson(path.join(process.cwd(), 'config/config.json'))
|
||||
])
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -20,7 +25,7 @@ function readFile (fileName, options) {
|
|||
})
|
||||
}
|
||||
|
||||
function readData (dataPath) {
|
||||
function readJson (dataPath) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
jsonfile.readFile(dataPath, (err, data) => {
|
||||
err ? reject(err) : resolve(data)
|
||||
|
|
|
@ -27,7 +27,7 @@ export class Scanner {
|
|||
}
|
||||
|
||||
readfile (filename) {
|
||||
const filePath = path.join(process.cwd(), config.contentPath, filename)
|
||||
const filePath = path.join(process.cwd(), 'content', filename)
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readFile(filePath, 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
|
@ -41,7 +41,7 @@ export class Scanner {
|
|||
|
||||
copyImage (filename) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const inputPath = path.join(process.cwd(), config.contentPath, filename)
|
||||
const inputPath = path.join(process.cwd(), 'content', filename)
|
||||
const outputPath = path.join(process.cwd(), 'public/static', filename)
|
||||
fs.copyFile(inputPath, outputPath, (err) => {
|
||||
if (err) {
|
||||
|
@ -73,7 +73,7 @@ export class Scanner {
|
|||
}
|
||||
|
||||
processFile (file, data) {
|
||||
const filePath = path.join(process.cwd(), config.contentPath, file)
|
||||
const filePath = path.join(process.cwd(), 'content', file)
|
||||
const metadata = this.fileMetadata(filePath)
|
||||
|
||||
if (config['non-content-files'].indexOf(file) === -1) {
|
||||
|
@ -108,7 +108,7 @@ export class Scanner {
|
|||
|
||||
writeData (callback) {
|
||||
return new Promise((resolve, reject) => {
|
||||
jsonfile.writeFile(config.dataPath, this.data, (err, data) => {
|
||||
jsonfile.writeFile(path.join(process.cwd(), 'data.json'), this.data, (err, data) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
|
@ -133,12 +133,12 @@ export class Scanner {
|
|||
}
|
||||
|
||||
scan () {
|
||||
this.readdir(config.contentPath)
|
||||
this.readdir(path.join(process.cwd(), 'content'))
|
||||
.then(
|
||||
(files) => {
|
||||
const filtered = files.filter(
|
||||
(file) => (
|
||||
fs.statSync(path.join(process.cwd(), config.contentPath, file)).isFile()
|
||||
fs.statSync(path.join(process.cwd(), 'content', file)).isFile()
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import { App } from '../components'
|
|||
import routes from './routes'
|
||||
import serialize from 'serialize-javascript'
|
||||
import manifest from '../../public/static/manifest.json'
|
||||
import config from '../../config/config.json'
|
||||
|
||||
export class ServerRenderer {
|
||||
|
||||
|
@ -23,6 +22,7 @@ export class ServerRenderer {
|
|||
: Promise.resolve()
|
||||
|
||||
promise.then((data) => {
|
||||
console.log(data)
|
||||
const markup = renderToString(
|
||||
<Router location={req.url} context={{ data }}>
|
||||
<App/>
|
||||
|
@ -39,7 +39,7 @@ function renderFullPage (html, head, data) {
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>${config.title}</title>
|
||||
<title>${data[1].title}</title>
|
||||
<!-- Google Fonts -->
|
||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans|Open+Sans+Condensed:700&subset=latin-ext" rel="stylesheet" rel="preload">
|
||||
<!-- Font Awesome -->
|
||||
|
|
Loading…
Reference in New Issue