Skip to content
Transform a directory of markdown files to JSON
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example
src Add travis build and node version badges to readme Feb 19, 2019
.gitignore Add travis & code coverage reporting Feb 13, 2019
.lintstagedrc Typescript refactor Jan 22, 2019
.prettierignore Typescript refactor Jan 22, 2019
.prettierrc Typescript refactor Jan 22, 2019
.travis.yml
coverage.lcov Add travis build and node version badges to readme Feb 19, 2019
license.md 🚀 Apr 12, 2018
npm-debug.log Add travis build and node version badges to readme Feb 19, 2019
package-lock.json
package.json Fix module not found error (closes #14) Feb 20, 2019
readme.md
tsconfig.json Move tests to typescript and add content transform unit tests Jan 25, 2019
tslint.json Typescript refactor Jan 22, 2019

readme.md

jdown

Build Status Node Version

If you're creating content in markdown or use a CMS like NetlifyCMS which outputs markdown files jdown can transform the content into JSON containing HTML at build time ready to be consumed within templates.

Install

$ npm install jdown --save-dev

Basic Usage

Content to JSON

const jdown = require('jdown');
jdown('path/to/content').then(content => console.log(content));

Call jdown with the path to your markdown content (relative to the project root) and it will convert your content to JSON.

Structuring Content

The structure of the JSON that jdown outputs depends on how files within the content folder are structured.

Top Level Files

Will be turned into a top level object.

Top Level Files

Folders

Files within folders will be turned into objects and grouped under a top level object that has the same name as the parent folder (don't go more than one level deep).

Folders

Collections

The collections folder should only contain sub folders, each sub folder will be turned into an array of objects. There will be an object for each file in the sub folder.

Collections

File Contents

YAML frontmatter can be included at the top of any files throughout and it will be added to the generated JSON as individual properties.

---
title: Example frontmatter
---

Example Markdown Content

API

jdown([path], [options])

path

Type: string
Required

Path to a folder containing markdown files with a folder structure that matches the guidelines above. The path should be relative to the project root so if your content was in /Users/username/project/src/content, you would use jdown('src/content').

options

Type: object

markdown

Type: object

Options to pass to marked, jdown supports all the available marked options which can be used to control how the markdown is parsed.

assets

Type: object

Asset parsing options. Using jdown to parse assets is completely optional, but comes with a few benefits including:

  • Ability to organise assets alongside markdown content
  • Auto minification of image files using imagemin
  • Cache busting, using the last modified time (mtime) of the asset to change it's file name and avoid the old version of the asset being served

All static assets must be placed within /assets folders. Assets folders can be placed in the top level content directory and/or it's sub directories. Within the markdown content assets can then be referenced using ![](./assets/my-asset.png) where my-asset.png is an asset placed within an /assets folder.

The assets options object can contain the following properties:

Property Type Default Description
output string ./public Directory jdown will output processed assets to
path string / Publically accessible path jdown will prepend to output file names
png object undefined Options to pass into imagemin-pngquant
jpg object undefined Options to pass into imagemin-jpegtran
svg object undefined Options to pass into imagemin-svgo
gif object undefined Options to pass into imagemin-svgo
parseMd

Type: boolean
Default: true

Set this to false to disable markdown parsing and just recieve structured JSON containing markdown instead of HTML.

fileInfo

Type: boolean
Default: false

Set this to true to include file info objects in the output JSON which contain the files path, name, created at date and modified at date.

Examples

The example directory of this repository contains use of jdown including asset parsing and custom marked render options.

In The Wild

Contributing

Any pull requests are welcome and will be reviewed.

License

MIT

You can’t perform that action at this time.