Filter files during scan

This commit is contained in:
LordMathis 2019-10-13 12:53:21 +02:00
parent 92bbcec4d0
commit e017e22582
No known key found for this signature in database
GPG Key ID: 575849FD91CE470C
2 changed files with 8 additions and 16 deletions

View File

@ -22,7 +22,7 @@ export default class Blog extends Component {
</div>
)
}
let posts = this.props.posts.sort((a, b) => {
return new Date(b.published) - new Date(a.published)
})

View File

@ -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]) }
)