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

@inframanufaktur/eleventy-plugin-embed-mastodon

v0.4.0

Published

Eleventy plugin to embed Mastodon posts

Downloads

8

Readme

@inframanufaktur/eleventy-plugin-embed-mastodon

Embed Mastodon posts in your Eleventy pages.

Supports two modes: full and quote (coming soon). Full mode is a «classic» emded, and quote renders a reduced blockquote.

The plugin parses all images through @11ty/eleventy-img.

Features

  • Completely static embed, no client side JS
  • Support for posts on remote instances through Mastodon’s search API
  • Post requests are cached
  • Images are parsed through 11ty’s image platform

Usage

The plugin can work with posts in the following formats:

dair-community.social/@KimCrayton1/109766923696372660

https://dair-community.social/@KimCrayton1/109766923696372660 # shortcode only

mastodon.dair-community.social/@KimCrayton1/109766923696372660

chaos.social/@[email protected]/109800699318730970

https://chaos.social/@[email protected]/109800699318730970 # shortcode only

109756523208056473

Note: ID only works only with posts from the instance which has been specified as host in the options, the token must be valid on this instance.

Using posts from other remotes

If you add a full instance link, the plugin will look up the status via search:

mastodon:dair-community.social/@KimCrayton1/109766923696372660

Shortcode

{% embedMastodon 'https://dair-community.social/@KimCrayton1/109766923696372660' %}

Note: Any of the formats from above works.

Transform

Caveat: If you want to use transforms, you must omit https://. The reason is that I don’t want to maintain a reg exp that parses the links.

Mark the paragraph you want to transform with mastodon:. This is needed because there’s no way to know if something link like might be a Mastodon instance.

Example:

mastodon:109756061321167818

mastodon:dair-community.social/@KimCrayton1/109766923696372660

Configuration

Configure the plugin by passing in an object with basic options and options for image processing:

baseOptions

type baseOptions = {
  host: string,
  token: string,
  mode?: 'full' | 'quote',
  cacheDir?: string,
  cacheDuration?: string,
}
  • host: Your instance. E.g. front-end.social or lgbtqia.space. Domain name plus TLD only.
  • token: Access token

Default values

  • mode: full, renders complete embed code. quote renders a reduced blockquote
  • cacheDir: .mastodon
  • cacheDuration: 1y (profile pictures are saved for 2 weeks)

imageOptions

type imageOptions = {
  outputDir?: string,
  urlPath?: string,
}

Default values

  • outputDir: './_site/img/'. You need to change this if your dist folder is not _site
  • urlPath: '/img/'.

Styling

You can import @inframanufaktur/eleventy-plugin-embed-mastodon/post.css for default styles which mirror the Mastodon design.

Federation Gotchas

The federated nature of Mastodon requires some things to keep in mind:

IDs

IDs are unique for each server. If you want to embed by ID, you need to copy the ID from your server. Otherwise use the full link so that the plugin can perform a search.

To Do

  • [ ] Finish image configuration
  • [ ] Quote mode
  • [ ] Overwrite config mode for single posts through shortcode/transform
  • [ ] Error handling
  • [x] Shortcode
  • [x] Post caching
  • [ ] Images
  • [ ] Content Warnings

FAQ

Obtain an access token

  • Open the web interface of your instance
  • Go to Preferences -> Development
  • Use the «New Application» button
  • Enter a name (redirect URI can stay on the default value)
  • Select read scope, we don’t need anything else
  • Activate «Submit» button
  • On the application overview select your application
  • Copy the value behind «Your access token»
  • Add this value to your .env. Never commit tokens to source control.