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-bitly

v1.0.1

Published

A metalsmith plugin for bitly links

Downloads

8

Readme

metalsmith-bitly

npm version

A Metalsmith plugin that adds bitly links to the metadata of each file.

This plugin allows you to retrieve bit.ly short links and use them in your templates. For support questions please use stack overflow or the slack channel.

Installation

$ npm i metalsmith-bitly

Usage

You can use metalsmith-bitly with the with Metalsmith's Javascript API or CLI. You must also set the siteURL value on your site's metadata configuration.

Options

  • accessToken: your personal bitly access token (required)
  • baseURL: your production base URL (semi-required, either this or baseURLGlobalMetadataKey is needed)
  • baseURLGlobalMetadataKey: the global metaday key of your production base URL (semi-required, either this or baseURL is needed)
  • brandedShortDomain: an override for the default domain (optional, defaults to bit.ly)
  • pathMetadataKey: an override for the default file path (optional, defaults to path)

accessToken

In order to utilize this plugin you must request an access token at bit.ly's developer site. Please remember to exclude your bitly authorization key if your repository is public. You can use the below example and include your private configuration file in your repository's .gitignore file.

const bitly = require('metalsmith-bitly');
const configPrivate = require('../configPrivate');
const Metalsmith = require('metalsmith');

return Metalsmith(__dirname)
  .use(bitly({
    accessToken: configPrivate.bitlyToken,
    baseURL: 'http://welchcanavan.com/'
  }))
  .build(function(err) {
    if (err) throw err;
});

baseURL

A semi-required value, you must specify either this or baseURLGlobalMetadataKey. This is the base URL that will be combined with your file's path to sent to bit.ly.

const bitly = require('metalsmith-bitly');
const configPrivate = require('../configPrivate');
const Metalsmith = require('metalsmith');

return Metalsmith(__dirname)
  .use(bitly({
    accessToken: configPrivate.bitlyToken,
    baseURL: 'http://welchcanavan.com/'
  }))
  .build(function(err) {
    if (err) throw err;
});

baseURLGlobalMetadataKey

A semi-required value, you must specify either this or baseURL. Use this if you'd like to make sure this plugin stays in sync with a globally used or required metadate value for your site's production base URL.

const bitly = require('metalsmith-bitly');
const configPrivate = require('../configPrivate');
const Metalsmith = require('metalsmith');

return Metalsmith(__dirname)
  .metadata({
    siteURL: 'http://welchcanavan.com/',
  })
  .use(bitly({
    accessToken: configPrivate.bitlyToken,
    baseURLGlobalMetadataKey: siteURL
  }))
  .build(function(err) {
    if (err) throw err;
});

brandedShortDomain

Specify this value if you have set up a Branded Short Domain with bit.ly.

const bitly = require('metalsmith-bitly');
const configPrivate = require('../configPrivate');
const Metalsmith = require('metalsmith');

return Metalsmith(__dirname)
  .use(bitly({
    accessToken: configPrivate.bitlyToken,
    baseURL: 'http://welchcanavan.com/',
    brandedShortDomain: 'http://xiw.cx/'
  }))
  .build(function(err) {
    if (err) throw err;
});

pathMetadataKey

To be used in concert with the metalsmith-permalinks plugin. You can specify a file metadata key to match a pattern used in the permalinks plugin. Order is important here, you have to run metalsmith-bitly after metalsmith-permalinks or the paths won't match.

---
title: A Post About A Thing
slug: post-thing
---
const bitly = require('metalsmith-bitly');
const collections = require('metalsmith-collections');
const configPrivate = require('../configPrivate');
const Metalsmith = require('metalsmith');
const permalinks  = require('metalsmith-permalinks');

return Metalsmith(__dirname)
  .use(collections({
    posts: {
      pattern: 'posts/*.md',
      sortBy: 'date',
      reverse: true
    }
  }))
  .use(permalinks({
    linksets: [
      {
        match: { collection: 'posts' },
        pattern: ':slug'
      }
    ]})
  )
  .use(bitly({
    accessToken: configPrivate.bitlyToken,
    pathMetadataKey: 'slug'
  }))
  .build(function(err) {
    if (err) throw err;
});

Note: I've thought about including an option to focus this plugin on a collection or list of collections. If that would be of interest to you, feel free to leave a note or a pull request.

License

MIT