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

metalsmith-index

v1.1.1

Published

A Metalsmith plugin to create directory indexes

Downloads

4

Readme

metalsmith-index

NPM version

This simple plugin for Metalsmith is aimed at creating directory indexes. It is different from metalsmith-collections in that it does not simply create metadata to link documents between them, but creates new entries in the list of files manipulated by Metalsmith. In other words, it is useful to create directory indexes ex-nihilo.

Usage

metalsmith-index requires a list of indexes to generate or it will do nothing. This list is provideed using an object. Each key of this object is the path of a directory to index. Each value associated to a key is a collection of options aimed at controling the index output.

If using the CLI for Metalsmith, metalsmith-index can be used like any other plugin by including it in metalsmith.json.

{
  "plugins": {
    "metalsmith-index": {
      "pub": {},
      "archives/2017": {}
    }
  }
}

In Metalscript's JavaScript API, metalsmith-index can be used like any other plugin by attaching it to the function invocation chain on the Metalscript object.

const index = require('metalsmith-index')

require('metalsmith')(__dirname)
  .use(index({
    'pub': {},
    'archives/2017': {}
  }))
  .build();

Behaviour

The examples provided above both add two new files (pub/index.list and archives/2017/index.list) to the list of files to be passed to subsequent plugins. Those files contain respectively the list of the filenames from the pub and archives/2017 directories.

More specifically, each entry produced by metalsmith-index contains two keys:

  • files is the list of the metadata about the indexed files. For each file, it contains an object with the name, the path and the last modification date. This can be used to easily handle the entry programmatically, or with a layout plugin for example.

  • contents is a buffer with the list of the indexed filenames. This is useful to handle the entry like any other source file.

Options

Each index to produce can be given an options object. Here are the options that can be used to alter the index content. Everything else is metadata that is added to the created index file.

  • filename provides the entry filename (default is index.list).

  • filter is a function to be used to test the files to be indexed. The function must take two arguments: the filename and the Metalsmith entry (with the file contents and stats). Are only indexed the files for which the function returns True.

  • format is a function to be applied on each index file so as to create its representation in the list. Default is the filename followed by a new line character. The function must take two arguments: the filename and the Metalsmith entry (with the file contents and stats), and return a string.

  • sort is a function which is called to sort the files read in the source directory before building the index. By default, the alphabetic order is used. The function is used to sort an array of strings and must behave like a compareFunction.

  • recursive is false by default: the plugin ignores sub-directories. When set to true, they are indexed recursively.