Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94424e6
commit 4f9aa79
Showing
2 changed files
with
38 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const fs = require("fs-extra"); | ||
const helper = require("dashboard/routes/importer/helper"); | ||
const marked = require("marked"); | ||
|
||
const input_directory = process.argv[2]; | ||
const output_directory = input_directory + "-output"; | ||
|
||
const posts = fs | ||
.readdirSync(input_directory) | ||
.filter( | ||
(filename) => | ||
fs.statSync(input_directory + "/" + filename).isFile() && | ||
filename[0] !== "." | ||
) | ||
.map((filename) => { | ||
let file = fs | ||
.readFileSync(input_directory + "/" + filename, "utf-8") | ||
.trim(); | ||
let post = {}; | ||
|
||
post.title = file.split("\n")[0].slice(2); | ||
post.html = marked(file.split("\n").slice(1).join("\n")); | ||
post.slug = filename.slice(0, filename.indexOf("_")); | ||
post.id = filename.slice(filename.indexOf("_") + 1); | ||
post.permalink = "/" + post.slug; | ||
post.dateStamp = post.created = post.updated = fs | ||
.statSync(input_directory + "/" + filename) | ||
.ctime.valueOf(); | ||
post.draft = post.page = false; | ||
|
||
return post; | ||
}); | ||
|
||
console.log(posts); | ||
|
||
// Writes each post in the post array, | ||
// downloads any images, pdfs | ||
helper.process(output_directory, posts); |
This file contains 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