DailyJS

DailyJS

The JavaScript blog.


Tagepub
Featured

libraries node modules markdown epub npm cms

Node Roundup: npm Scopes, AkashaEPUB, mdjson

Posted on .

npm Scopes

Since npm got private modules, it has supported scopes, because private modules are resolved based on your username. However, one thing that I didn't realise was scopes are available to everyone -- you don't have to use them for private modules. That means you can reuse an existing package name, which makes sense if the package name is generic enough.

This was mentioned in this week's npm weekly post, under "solving npm’s hard problem: naming packages":

As part of the private modules rollout last week, we introduced a new free feature: scopes for packages. If you’re a registered npm user then you already have a scope, so check out the post if you want to learn how to use it.

This will be handy if you want to distribute your own fork for existing modules through npm.

AkashaEPUB

David Herron sent in AkashaEPUB (GitHub: akashacms/akashacms-epub, License: Apache 2.0, npm: akashacms-epub), a toolchain for constructing EPUB version 3 books. It allows you to write books using Markdown, and helps manage the asset files (CSS, images, fonts), and builds a correct EPUB3 file.

AkashaEPUB is built using AkashaCMS, which is a static site generator:

The goal for AkashaCMS is to provide most of the flexibility of a full scale CMS, incorporate modern JavaScript/CSS UI frameworks, while producing static HTML files, and skipping the administrative overhead of running a full CMS.

To use AkashaEPUB, you'll need Grunt and an EPUB to generate. There's a sample project and a skeleton. The following example will build the EPUB Guidebook that David Herron created:

npm install -g akashacms  
npm install -g grunt-cli  
git clone https://github.com/akashacms/epub-guide.git  
cd epub-guide  
npm install  
grunt doepub  

mdjson

mdjson (GitHub: yoshuawuyts/mdjson, License: MIT, npm: mdjson) by Yoshua Wuyts is a module for generating JSON from Markdown. The properties in the JSON are based on the headings, which means you can use it to write JavaScript objects in a more friendly manner. This works particularly well with template strings:

mdjson(`  
  This part (before any headers) is ignored. Feel free
  to use this section for commentary on the file's purpose,
  if you wish.

  ## my heading
  oh wow, amazing

  ## another heading
  gorgeous copy, stunning
`)

The output contains the original input and HTML:

{
  'my heading': {
    raw: 'oh wow, amazing',
    html: '<p>oh wow, amazing</p>'
  },

  'another heading': {
    raw: 'gorgeous copy, stunning',
    html: '<p>gorgeous copy, stunning</p>'
  }
}

I think this might be a cool way of converting Markdown to something more structured to store in a database for a CMS or static site generator.