Skip to content

boeckMt/metalsmith-json-insteadof-md

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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