An open API service indexing awesome lists of open source software.

https://github.com/daviddarnes/bluesky-post

A Web Component to display Bluesky posts and their metadata
https://github.com/daviddarnes/bluesky-post

components customelement customelements webcomponent webcomponents

Last synced: 4 months ago
JSON representation

A Web Component to display Bluesky posts and their metadata

Awesome Lists containing this project

README

          

# `bluesky-post`

A Web Component to display Bluesky posts and their metadata.

**[Demo](https://daviddarnes.github.io/bluesky-post/demo.html)** | **[Custom template demo](https://daviddarnes.github.io/bluesky-post/demo-custom-template.html)** | **[Further reading](https://darn.es/bluesky-post-web-component/)**

## Examples

General usage example:

```html


Discuss on Bluesky

```

Example using a custom template:

```html


Discuss on Bluesky

```

Example using a more complex custom template:

```html


Reposts


Replies


Likes




View original post from on


Discuss on Bluesky

```

## 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="record.text"`

## Installation

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

1. Install via [npm](https://www.npmjs.com/package/@daviddarnes/bluesky-post): `npm install @daviddarnes/bluesky-post`
1. [Download the source manually from GitHub](https://github.com/daviddarnes/bluesky-post/releases) into your project.
1. Skip this step and use the script directly via a 3rd party CDN (not recommended for production use)

### Usage

Make sure you include the `` in your project (choose one of these):

```html
<!-- Host yourself -->
<script type="module" src="bluesky-post.js">
```

```html

```

```html

```

### Using a custom template

The default template for the component looks like this:

```html




@


Reposts


Replies


Likes



```

However you can customise the template by using a `` 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 `

`:

```html


Reposts


Replies


Likes


```

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

```html


Discuss on Bluesky

```

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](https://docs.bsky.app/docs/api/app-bsky-feed-get-posts). The official Bluesky documentation has [an example of a status response here](https://docs.bsky.app/docs/api/app-bsky-feed-get-posts#responses).

_Note that for `` and `` 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](https://daviddarnes.github.io/bluesky-post/demo-custom-template.html) as well as [the source code](https://github.com/daviddarnes/bluesky-post/blob/main/demo-custom-template.html) for reference.

## Credit

With thanks to the following people:

- [Zach Leatherman](https://zachleat.com) for inspiring this [Web Component repo template](https://github.com/daviddarnes/component-template)