From e017e2258225eb50744da96748d8b3063625c978 Mon Sep 17 00:00:00 2001 From: LordMathis Date: Sun, 13 Oct 2019 12:53:21 +0200 Subject: [PATCH] Filter files during scan --- src/components/Blog.js | 2 +- src/utils/scanner.js | 22 +++++++--------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/components/Blog.js b/src/components/Blog.js index 58959af..8ee8e49 100644 --- a/src/components/Blog.js +++ b/src/components/Blog.js @@ -22,7 +22,7 @@ export default class Blog extends Component { ) } - + let posts = this.props.posts.sort((a, b) => { return new Date(b.published) - new Date(a.published) }) diff --git a/src/utils/scanner.js b/src/utils/scanner.js index 195f223..b473aab 100644 --- a/src/utils/scanner.js +++ b/src/utils/scanner.js @@ -72,19 +72,6 @@ export class Scanner { } } - // init () { - // return new Promise((resolve, reject) => { - // jsonfile.readFile(config.dataPath, (err, data) => { - // if (err) { - // reject(err) - // } else { - // this.data = data - // resolve(data) - // } - // }) - // }) - // } - writeData (callback) { return new Promise((resolve, reject) => { jsonfile.writeFile(config.dataPath, this.data, (err, data) => { @@ -114,9 +101,14 @@ export class Scanner { scan () { this.readdir(config.contentPath) .then( - (files) => { return Promise.all(files.map(this.readfile)) } - ).then( (files) => { + const filtered = files.filter( + (file) => fs.statSync(path.join(process.cwd(), config.contentPath, file)).isFile() + ) + return Promise.all(filtered.map(this.readfile)) + } + ).then( + (files) => { files.forEach( (item) => { this.processFile(item[0], item[1]) } )