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

@daviddarnes/bluesky-post

v1.0.0

Published

A Web Component to display Bluesky posts and their metadata

Downloads

72

Readme

bluesky-post

A Web Component to display Bluesky posts and their metadata.

Demo | Custom template demo | Further reading

Examples

General usage example:

<script type="module" src="bluesky-post.js"></script>

<bluesky-post>
  <a href="https://bsky.app/profile/darn.es/post/3l7m6ivb6ha2q">
    Discuss on Bluesky
  </a>
</bluesky-post>

Example using a custom template:

<script type="module" src="bluesky-post.js"></script>

<template id="bluesky-post-template">
  <blockquote data-key="content"></blockquote>
</template>

<bluesky-post>
  <a href="https://bsky.app/profile/darn.es/post/3l7m6ivb6ha2q">
    Discuss on Bluesky
  </a>
</bluesky-post>

Example using a more complex custom template:

<script type="module" src="bluesky-post.js"></script>

<template id="bluesky-post-template">
  <dl>
    <dt>Reposts</dt>
    <dd data-key="reblogs_count"></dd>
    <dt>Replies</dt>
    <dd data-key="replies_count"></dd>
    <dt>Favourites</dt>
    <dd data-key="favourites_count"></dd>
  </dl>
  <a data-key="url">
    View original post from <img alt="avatar" data-key="account.avatar" />
    <strong data-key="account.display_name"></strong> on
    <strong data-key="hostname"></strong>
  </a>
</template>

<bluesky-post>
  <a href="https://bsky.app/profile/darn.es/post/3l7m6ivb6ha2q">
    Discuss on Bluesky
  </a>
</bluesky-post>

Features

This Web Component allows you to:

  • Turn a regular Bluesky post link into a quoted Bluesky post
  • Surface the post metadata alongside the post, e.g. reply count, repost count, like count
  • Use a custom template for all instances of the component on the page using a data-key="name" data attributes
  • Use a custom template for specific instances using the template attribute
  • Retrieve nested data using the data-key attribute and typical JavaScript key referencing, e.g. data-key="reocrd.text"

Installation

You have a few options (choose one of these):

  1. Install via npm: npm install @daviddarnes/bluesky-post
  2. Download the source manually from GitHub into your project.
  3. Skip this step and use the script directly via a 3rd party CDN (not recommended for production use)

Usage

Make sure you include the <script> in your project (choose one of these):

<!-- Host yourself -->
<script type="module" src="bluesky-post.js"></script>
<!-- 3rd party CDN, not recommended for production use -->
<script
  type="module"
  src="https://www.unpkg.com/@daviddarnes/[email protected]/bluesky-post.js"
></script>
<!-- 3rd party CDN, not recommended for production use -->
<script
  type="module"
  src="https://esm.sh/@daviddarnes/[email protected]"
></script>

Using a custom template

The default template for the component looks like this:

<figure>
  <blockquote data-key="record.text"></blockquote>
  <figcaption>
    <cite>
      <a data-key="url">@<span data-key="username"></span></a>
    </cite>
    <dl>
      <dt>Reposts</dt>
      <dd data-key="repostCount"></dd>
      <dt>Replies</dt>
      <dd data-key="replyCount"></dd>
      <dt>Likes</dt>
      <dd data-key="likeCount"></dd>
    </dl>
  </figcaption>
</figure>

However you can customise the template by using a <template> element with an id of bluesky-post-template, which will be used for every instance of the component on the page. Here's an example which just exposes the vanity metrics of the Bluesky post as a <dl>:

<template id="bluesky-post-template">
  <dl>
    <dt>Reposts</dt>
    <dd data-key="repostCount"></dd>
    <dt>Replies</dt>
    <dd data-key="replyCount"></dd>
    <dt>Likes</dt>
    <dd data-key="likeCount"></dd>
  </dl>
</template>

You can also use different templates on the same page by using the template attribute to target <template> elements with a specific id:

<template id="custom-template">
  <a data-key="record.text, url"></a>
</template>

<bluesky-post template="custom-template">
  <a href="https://bsky.app/profile/darn.es/post/3l7m6ivb6ha2q">
    Discuss on Bluesky
  </a>
</bluesky-post>

Data is applied using a data-key data attribute. The value of this attribute should correspond to a data point within a Bluesky public post API response. The official Bluesky documentation has an example of a status response here.

Note that for <a> and <img> elements the value won't be applied to it's content if the string being returned starts with http and instead will be applied to the href and src attributes respectively.

Check out the custom template demo as well as the source code for reference.

Credit

With thanks to the following people: