npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gitbook-plugin-melchior

v1.1.0

Published

Multi-language code includes for Gitbook.

Downloads

1

Readme

gitbook-plugin-melchior

Multi-language code block includes for your Gitbook (or other Nunjucks-powered project)! Thanks much to SamyPesse and the Gitbook team for the idea, preview image and front-end code.

Preview

Installation

Adds the plugin to your book.json, then run gitbook install if you are building your book locally.

{
  "plugins": [ "[email protected]" ],
  "pluginsConfig": {
    "melchior": {
      "includes": "_includes"
    } 
  }
}

Usage

Three ways to use the plugin. Usage depends on how much you want to configure the order of languages / label, and if you're using GitBook or not.

  • create a folder for your includes that matches the folder in your plugins config (default: _includes)
  • put your includes somewhere in that folder
  • provide a name for your include, in any number of languages
  • pipe the name through melchior, and voila!
my-wonderful-book
├─ book.json
└─ _includes
   └─ hello
      ├─ world.html
      ├─ world.js
      └─ world.py

Lazy Mode

You can autofetch all files matching the given name…

This is a code block with tabs for each language:

{{ 'hello/world' | melchior }}

Less-Lazy Mode

…or you can order and filter tabs by passing in language names.

This is a code block with tabs for each language:

{{ 'hello/world' | melchior('Python', 'JavaScript', 'HTML') }}

Wild-West Mode

If you don't want to use Gitbook, an off-label use of this module includes its use (specifically, use of the melchior export of index.js) as a perfectly normal function, passing in the base directory for your includes.

When used as a standalone function, I happen to prefer an array for the second arg, so that's also an option. Either way you'll get the same output. You can also just not pass anything after the include name and it'll continue to work in Lazy Mode.

const gpm = require('gitbook-plugin-melchior');
const render = require('nunjucks').renderString;
const melchior = gpm.melchior(__dirname);

const str1 = `{{ melchior('hello/world', 'Python', 'JavaScript') }}`;
const str2 = `{{ melchior('hello/world', [ 'Python', 'JavaScript' ]) }}`;
const str3 = `{{ melchior('hello/world') }}`;

const res1 = render(str1, { melchior });
const res2 = render(str2, { melchior });
const res3 = render(str3, { melchior });

console.log(res1 === res2); // true, but no such guarantee for res3.

Issues

  • uses synchronous fs methods everywhere. Sorry, not sorry.
  • for modes other than Wild-West Mode, this wildly abuses the idea of a filter. I would've made a function, but you can't easily add things to the rendering ctx with Gitbook.
  • uses fancy ES6 features, won't work in <6.x versions of Node. May provide a transpiled version if this turns out to be an issue.

License

Apache 2.0.