2020-11-28 15:45:01 +00:00
|
|
|
import path from 'path'
|
|
|
|
import fs from "fs"
|
|
|
|
|
|
|
|
|
|
|
|
export const Node = {
|
|
|
|
isFile:function(filename){
|
2022-04-17 13:04:58 +00:00
|
|
|
try {
|
|
|
|
return fs.lstatSync(filename).isFile()
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-11-28 15:45:01 +00:00
|
|
|
},
|
|
|
|
getFullPath:function(folderPath){
|
|
|
|
return fs.readdirSync(folderPath).map(fn => path.join(folderPath, fn))
|
|
|
|
},
|
|
|
|
getFiles: function(dir) {
|
|
|
|
var results = [];
|
|
|
|
var list = fs.readdirSync(dir);
|
|
|
|
list.forEach(function(file) {
|
|
|
|
file = dir + '/' + file;
|
|
|
|
var stat = fs.statSync(file);
|
|
|
|
if (stat && stat.isDirectory()) {
|
|
|
|
/* Recurse into a subdirectory */
|
|
|
|
results = results.concat(Node.getFiles(file));
|
|
|
|
} else {
|
|
|
|
/* Is a file */
|
|
|
|
results.push(file);
|
|
|
|
}
|
|
|
|
});
|
2022-04-16 15:55:20 +00:00
|
|
|
return results.filter(f => f.endsWith(".md"))
|
2020-11-28 15:45:01 +00:00
|
|
|
},
|
|
|
|
readFileSync:function(fullPath){
|
|
|
|
return fs.readFileSync(fullPath, "utf8")
|
2020-11-30 11:29:34 +00:00
|
|
|
},
|
|
|
|
|
2022-04-18 01:58:37 +00:00
|
|
|
getMarkdownFolder: function () {
|
|
|
|
return path.join(process.cwd(), 'posts')
|
|
|
|
}
|
2020-11-28 15:45:01 +00:00
|
|
|
}
|