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-twitter-card

v1.0.9

Published

Twitter card meta tags for Metalsmith.

Downloads

22

Readme

metalsmith-twitter-card

npm version npm

A Metalsmith plugin that adds Twitter Card meta tags to enable Twitter share rich snippets. Plugin supports all twitter card types and validates file metadata to have all required properties.

Installation

$ npm install --save-dev metalsmith-twitter-card

Usage

Place metalsmith-twitter-card plugin after html files generation, for example after metalsmith-layouts.

const Metalsmith  = require('metalsmith');
const twitterCard = require('metalsmith-twitter-card');

Metalsmith(__dirname)
  .use(twitterCard({
    siteurl: 'my-site.com'
  }));

To enable twitter tags generation add twitter to frontmatter with required sub-properties. Or you can just set twitter: true to use default defined in plugin options. Properties cound be just a string value, css selector (only class and id supported), or metadata property name. Example:

---
title: Hello World
description: My pretty description.
twitter:
  card: summary            // Sets card type to `summary`
  site: '@myaccount'       // Sets twitter account to `@myaccount`
  title: '#page-title'     // Will look for element with id `page-title`
                           // and take its text content as twitter card title.
  description: description // Will look for a description property in file frontmatter,
                           // if nothing founded in it, will look for this property in plugin options.
---

To disable twitter tags generation for particular file just ommit twitter property in frontmatter.

Options

You can pass any twitter card properties to plugin to set default values. If file contain properties, it will use properties from file, override defaults. Example:

const Metalsmith  = require('metalsmith');
const twitterCard = require('metalsmith-twitter-card');

Metalsmith(__dirname)
  .use(twitterCard({
    siteurl: 'my-site.com',
    card: 'summary_large_image', // Sets default card type.
    site: '@myaccount',          // Sets default twitter username.
    title: 'title',              // By default will use title property from file metadata as twitter card title.
    description: 'description'   // By default will use description property
                                 // from file metadata as twitter card description.
  }));

In file you can override defaults, for example:

 ---
 title: Hello World
 description: My pretty description.
 twitter:
   card: summary            // Will override default card type `summary_large_image` with `summary`
   site: '@another-account' // Will override default twitter account `@myaccount` with `@another-account`
 ---

siteurl - Required

Type: String

Default: ''

Your site url, used to generate absolute path for images.

CLI

You can also use the plugin with the Metalsmith CLI by adding a key to your metalsmith.json file:

{
  "plugins": {
    "metalsmith-twitter-card": {
      "siteurl": "my-site.com"
    }
  }
}

License

MIT