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

eleventy-plugin-webmentions

v2.1.0

Published

An eleventy plugin to fetch webmentions and helper methods to display them

Downloads

55

Readme

eleventy-plugin-webmentions

A plugin for eleventy to fetch and filter webmentions from Webmention.io.

Install

Available on npm.

npm install --save-dev eleventy-plugin-webmentions

Usage

In your Eleventy config file (probably .eleventy.js), load the plugin module and use .addPlugin to add it to Eleventy with an options object that defines the domain and the Webmention.io token. Like this:

const Webmentions = require("eleventy-plugin-webmentions");

module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(Webmentions, {
    domain: "lukeb.co.uk",
    token: "ABC123XYZ987",
  });
};

REMEMBER: You’re only allowed one module.exports in your configuration file, so make sure you only copy the require and the .addPlugin lines above! (Including the configuration options)

The plugin then adds 2 global data objects. One is called webmentionsLastFetched and is a Date object with the date that the plugin last fetched webmentions, and the other is called webmentions and is an array of webmention objects that look similar to this:

{
  type: 'entry',
  author: {
    type: 'card',
    name: 'Zach Leatherman',
    photo: 'https://webmention.io/avatar/pbs.twimg.com/d9711a9ad30ae05a761e4a728883bcbdd852cbf7d41437925b0afc47a8589795.jpg',
    url: 'https://twitter.com/zachleat'
  },
  url: 'https://twitter.com/zachleat/status/1524800520208142337',
  published: '2022-05-12T17:15:48+00:00',
  'wm-received': '2022-05-13T00:05:16Z',
  'wm-id': 1397424,
  'wm-source': 'https://brid.gy/comment/twitter/CodeFoodPixels/1524795680966991874/1524800520208142337',
  'wm-target': 'https://lukeb.co.uk/blog/2022/01/17/pixelated-rounded-corners-with-css-clip-path/',
  content: {
    html: 'The step-by-step here was/is incredible detailed!\n' +
      '<a class="u-mention" href="http://lukeb.co.uk/"></a>\n' +
      '<a class="u-mention" href="https://twitter.com/CodeFoodPixels"></a>',
    text: 'The step-by-step here was/is incredible detailed!',
    value: 'The step-by-step here was/is incredible detailed! <a></a> <a></a>'
  },
  'in-reply-to': 'https://lukeb.co.uk/blog/2022/01/17/pixelated-rounded-corners-with-css-clip-path/',
  'wm-property': 'in-reply-to',
  'wm-private': false
}

It also adds 2 filters:

  • webmentionsForPage will return the webmentions for that page, in the structure defined by the mentionTypes option.
  • webmentionCountForPage will return the number of webmentions for a page, filtered by the types used in the mentionTypes option.

Here is an example of using the filters in nunjucks:

{# Get the webmentions for the current page #}
{%- set currentPostMentions = webmentions | webmentionsForPage -%}

{# Get the webmentions for a specific page #}
{%- set postMentions = webmentions | webmentionsForPage(post.url) -%}

{# Get the webmention count for the current page #}
{%- set currentPostMentionCount = webmentions | webmentionCountForPage -%}

{# Get the webmention count for a page #}
{%- set postMentionCount = webmentions | webmentionCountForPage(post.url) -%}

Configuration

Below are all the options that can be passed to the plugin:

domain

Required

undefined

token

Required

undefined

cacheDirectory

./_webmentioncache

cacheTime

3600

truncate

true

maxContentLength

280

truncationMarker

&hellip;

htmlContent

true

useCanonicalTwitterUrls

true

Whether or not to convert Twitter URLs using tweetback-canonical

pageAliases

{}

An object keyed by page path, with the values either being a string of a page that is an alias of that page (e.g an old page that has been redirected) or an array of strings.

mentionTypes

{
  likes: ["like-of"],
  reposts: ["repost-of"],
  comments: [
    "mention-of",
    "in-reply-to"
  ]
}

A single layer object with groupings and types that should be returned for that grouping. The object can have any keys you wish (doesn't have to be likes, reposts and comments like the default) but each value should be an array of webmention types.You can find a list of possible types here

sanitizeOptions

{
  allowedTags: ["b", "i", "em", "strong", "a", "p"],
  allowedAttributes: {
    a: ["href"],
  },
}

A set of options passed to sanitize-html. You can find a full list of available options here You can find a full list of available options here

sortFunction

(a, b) => {
  new Date(a.published || a["wm-received"]) -
  new Date(b.published || b["wm-received"])

Defaults

All of the defaults are exposed on the defaults property of the module, so they can be used in your config if necessary.

Here is an example of extending the sanitizeOptions object:

const Webmentions = require("eleventy-plugin-webmentions");

module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(Webmentions, {
    domain: "lukeb.co.uk",
    token: "ABC123XYZ987",
    sanitizeOptions: {
      ...Webmentions.defaults.sanitizeOptions,
      allowedTags: [
        ...Webmentions.defaults.sanitizeOptions.allowedTags,
        "iframe",
        "marquee",
      ],
      disallowedTagsMode: "escape",
    },
  });
};