Skip to content

A Metalsmith plugin to use JSON files in addition to or instead of markdown files

Notifications You must be signed in to change notification settings

boeckMt/metalsmith-json-insteadof-md

Repository files navigation

metalsmith-json-insteadof-md

metalsmith: plugin

A Metalsmith plugin to use JSON files in addition to markdown files.

This plugin is based on metalsmith-markdown

Installation

$ npm install --save @boeckmt/metalsmith-json-insteadof-md

Javascript Usage

Pass options if needed to the plugin and pass it to Metalsmith with the use method:

options:

  • fileExtnameFrom: //filter for all files with the extname - defaults '.json',
  • fileExtnameTo: //replaces the file in the files Objext with the extname - defaults '.html',
const Metalsmith = require('metalsmith');
const markdown = require('metalsmith-markdown');
const jsonContent = require('@boeckmt/metalsmith-json-insteadof-md'); // or import * as jsonContent from '@boeckmt/metalsmith-json-insteadof-md';

Metalsmith(__dirname)
    .source('./source/')
    .destination('./dist/build/')
    .use(jsonContent())
    .use(markdown())
    .build((err, files) => {
      console.log(`new Build completed!`);
      if (err) {
        console.log(err);
      }
    });

use the options whith fileExtnameTo: '.md' if you filter on the files later e.g.:

Metalsmith(__dirname)
    .source('./source/')
    .destination('./dist/build/')
    .use(jsonContent({
      fileExtnameTo: '.md'
    }))
    .use(markdown())
    .use(collections({
      items: {
        pattern: ['*/data/items/**/*.md']
      }
    }))
    .build((err, files) => {
      console.log(`new Build completed!`);
      if (err) {
        console.log(err);
      }
    });

Write the content

my-file.md

  ---
  title: A Catchy Title
  draft: false
  ---

  An unfinished article...

writen in json:

{
  "title": "A Catchy Title",
  "draft": false,
  "content": "<p></p>"
}

The intention for this plugin was to use it with a json schema file and write the content with a IDE which supports json schema validation.

License

MIT

About

A Metalsmith plugin to use JSON files in addition to or instead of markdown files

Resources

Stars

Watchers

Forks

Packages