Coder Social home page Coder Social logo

json2html-cli's Introduction

@asamihsoy/json2html

Install and usage

npm i -D @asamihsoy/json2html
npx json2html ./path/to/data/json/ -t ./path/to/_template.pug -o ./path/to/output/directory/

Options

flag required description
-o Directory to output completed HTML files. You can set javascript file to customize output location by each HTML files. See "How to customize output location" section below.
-t Template pug file to bind data with.
-d Single JSON file or directory contains json files. Parsed objects can be accessed under "data" variable.

How to customize output location

By setting javascript file to -o option, you can customize HTML file output location.
Javascript file is something like this:

outputFunc.js

const fs = require('fs');
const mkdirp = require('mkdirp');

const cb = err => {
  if (err) console.log(err);
};

// export function for customize
// obj ... original data passed via json2html command
// html ... completed HTML string to save
module.exports = function outputFunc (obj,html) {

  // sample: get pid from original data
  const id = obj.pid

  // create output directory with id
  mkdirp.sync(`./path/to/output/directory/${id}/`)

  // write file to the directory
  fs.writeFileSync(
    `./path/to/output/directory/${id}/index.html`,
    html,
    cb
  )
}

then execute json2html command by setting outputFunc.js to -o option :

npx json2html ./path/to/data/json/ -t ./path/to/_template.pug -o ./path/to/outputFunc.js

json2html-cli's People

Contributors

ist-yoshimasayokoyama avatar

Watchers

yy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.