Last active
February 1, 2021 13:55
-
-
Save DavidWells/a75045c89d6f3d453ef4ab68499550f4 to your computer and use it in GitHub Desktop.
Generate markdown files with faker.js
This file contains hidden or 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
var faker = require('faker') | |
var fs = require('fs') | |
var path = require('path') | |
for (var i = 0; i < 1000; i++) { | |
generateMD() | |
} | |
function generateMD () { | |
var fileName = faker.lorem.word() + '-' + faker.lorem.word() | |
var fileContents = `--- | |
title: "${faker.lorem.words()}" | |
layout: Page | |
--- | |
${faker.lorem.sentence()} | |
` | |
var outputPath = path.join(__dirname, '../content/md', `${fileName}.md`) | |
fs.writeFile(outputPath, fileContents, function (err) { | |
if (err) { | |
return console.log(err) | |
} | |
console.log(outputPath + ' file generated') | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment