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-map-permalinks

v1.0.0

Published

Generate permalinks and a map of source file path to permalink

Downloads

3

Readme

metalsmith-map-permalinks :link:

Build Status

A Metalsmith plugin to generate permalinks and paths for files and store a mapping from input files to paths.

This plugin will generate a permalink for all files that match its pattern using a list of formats. The formats are mustache strings and are evaluated first to last, so order matters. The values for the permalink fields are taken from the file metadata. Here's an example using the JavaScript API:

import map_permalinks from 'metalsmith-map-permalinks'

Metalsmith(__dirname)
  .source('src')
  .destination('dst')
  .use(map_permalinks({
    formats: [
      {
        pattern: 'posts/*.md',
        format: '{{date}}/{{title}}',
        date_format: 'yyyy',
      },
      {
        pattern: 'pages/*.md',
        format: '{{title}}',
      },
    ],
  }))

Installation

From NPM:

$ npm install --save-dev metalsmith-map-permalinks
$ yarn add --dev metalsmith-map-permalinks

From GitHub:

$ npm install --save-dev https://github.com/ryanq/metalsmith-map-permalinks
$ yarn add --dev https://github.com/ryanq/metalsmith-map-permalinks

Options

Options for configuring metalsmith-map-permalinks can be passed as an argument to the plugin function for the JavaScript API or as the value of the metalsmith-map-permalinks key for the CLI. The options are:

  • pattern: Only process files that match the pattern. The default is '**'.
  • key: The key in the file metadata to use as the source string in the mapping. The default is undefined
  • formats: An array of format objects to use. The default is a default: true format with format: '{{title}}'. Formats have the following options:
    • pattern: Only apply the format to files that matche the pattern.
    • default: This is the default format and will match against any filename.
    • format: The format for the permalink.
    • date_format: The format to use when {{date}} is in the permalink.

Debugging

metalsmith-map-permalinks uses the debug package for logging during the build. Enable logging by setting DEBUG to include map-permalinks:

$ DEBUG=map-permalinks yarn build
yarn run v1.16.0
$ node build/index.mjs
  map-permalinks processing file pages/about.md +0ms
  map-permalinks using format {{title}} +1ms
  map-permalinks generated permalink about +1ms
  map-permalinks mapping about to /about/ +0ms
  map-permalinks replacing pages/about.md with about/index.html +0ms
  map-permalinks processing file posts/post-1.md +0ms
  map-permalinks using format {{date}}/{{title}} +1ms
  map-permalinks generated permalink 2018/post-1 +0ms
  map-permalinks mapping learning-go to /2018/post-1/ +0ms
  map-permalinks replacing posts/post-1.md with 2018/post-1/index.html +0ms
  map-permalinks processing file posts/post-2.md +0ms
  map-permalinks using format {{date}}/{{title}} +1ms
  map-permalinks generated permalink 2019/post-2 +0ms
  map-permalinks mapping post-2 to /2019/post-2/ +0ms
  map-permalinks replacing posts/post-2.md with 2019/post-2/index.html +0ms
✨  Done in 1.30s.