Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Convert database copy data to markdown
const fs = require('fs')
// input format:
// 25 The Innovator’s Dilemma The simultaneous need and danger to reinvent oneself and one's business is the dilemma. Do we disrupt ourselves or do we double-down on core competencies? A dilemma indeed! 2014-08-20 2014-11-28 19:05:28.153598 2014-11-28 19:05:28.153598 Craig Christensen
const separateColumns = line => line.split('\t')
const nameColumns = line => ({
id: line[0],
title: line[1],
description: line[2],
coverUrl: line[3],
completionDate: line[4],
reviewUrl: line[5],
createdAt: line[6],
updatedAt: line[7],
author: line[8],
affiliateUrl: line[9]
const nonEmptyColumns = line => !== ''
const deriveColumns = line => Object.assign({}, line, {
descriptionSummary: line.description.substr(0, 150),
fileName: __dirname + '/books/' + line.title.split(' ').join('-').toLowerCase() + '.md',
reviewUrl: line.reviewUrl.replace('http', 'https')
const deriveFrontMatter = line => Object.assign({}, line, {
fileContents: `---
affiliateUrl: "${line.affiliateUrl}"
author: "${}"
date: "${line.completionDate}"
- "Book"
comments: true
description: "${line.descriptionSummary}"
draft: false
keywords: ""
layout: "book"
image: "${line.coverUrl}"
reviewUrl: "${line.reviewUrl}"
title: "${line.title}"
const writeFiles = line => fs.writeFileSync(line.fileName, line.fileContents)
const file = fs.readFileSync(__dirname + '/latest.sql', 'utf8')
const lines = file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment