# eleventy-plugin-mastoarchive

> Expose your Mastodon posts to 11ty as a global data object

Latest version **0.2.0** (published 2023-06-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install eleventy-plugin-mastoarchive
pnpm add eleventy-plugin-mastoarchive
yarn add eleventy-plugin-mastoarchive
bun add eleventy-plugin-mastoarchive
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2023-06-10 |
| First published | 2023-02-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Declan Byrd |
| Maintainers | declanbyrd |
| Keywords | 11ty, eleventy, eleventy-plugin, 11ty-plugin |

## Links

- npm: https://www.npmjs.com/package/eleventy-plugin-mastoarchive
- Repository: https://github.com/declanbyrd/eleventy-plugin-mastoarchive
- Homepage: https://github.com/declanbyrd/eleventy-plugin-mastoarchive#readme
- Issues: https://github.com/declanbyrd/eleventy-plugin-mastoarchive/issues
- npm.io page: https://npm.io/package/eleventy-plugin-mastoarchive

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [node-fetch](https://npm.io/package/node-fetch.md) ^2.6.9

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 0.2.0 (latest) — 2023-06-10
- 0.3.0-alpha.2 (alpha) — 2024-07-06
- 0.3.0-alpha.1 — 2024-07-06
- 0.1.5 — 2023-04-20
- 0.1.4 — 2023-02-25
- 0.1.2 — 2023-02-25
- 0.1.1 — 2023-02-24

## README

# eleventy-plugin-mastoarchive

> Fetch your own public posts from Mastodon so you can display them on your personal website.

## Getting Started

First install the plugin in your project:

```shell
npm i eleventy-plugin-mastoarchive
```

Then include it in your Eleventy project file

```js
const mastoArchive = require('eleventy-plugin-mastoarchive');

module.exports = (eleventyConfig) => {
  eleventyConfig.addPlugin(mastoArchive, {
    host: MASTODON_SERVER,
    userId: MASTODON_USER_ID,
    removeSyndicates: ['example.com'],
  });
```

This will expose a global data object called `mastodon` which you can use in your Eleventy project.

On the first run, the plugin will fetch _all_ your public posts and then cache them to the location specified in `cacheLocation`. Each time posts are fetched after, only the posts made after the last cached post will be fetched.

If you used versions < 0.2.0 you will need to clear your site's cache to get all your posts and not the most recent 40.

## Getting your Mastodon User ID

I was able to retrieve my Mastodon user ID by monitoring the network requests made by the Mastodon server I belong to. On a device that is able to open developer tools, the steps I took were to:

- With the developer tools open and the Network traffic visible, enter your username in the search box and trigger the network request by pressing enter on your keyboard.
- Find the request that looks like `https://{mastodon_server}/api/v2/search?q=@{your_mastodon_username}` and open the response for that request. The response object should look like the one below.
- Your account should be the first one that appears under `accounts`. The id of that account is your Mastodon user ID.

```json
{
    "accounts":[
        {
            "id": {your user ID},
            "username": {your Mastodon username},
            ...
        }
    ],
    "statuses":[],
    "hashtags":[]
}
```

## Config Options

| Option           | Type     | Default                |
| ---------------- | -------- | ---------------------- |
| host             | string   |                        |
| userId           | string   |                        |
| removeSyndicates | string[] | []                     |
| cacheLocation    | string   | ".cache/mastodon.json" |
| isProduction     | boolean  | true                   |

The `host` and `userId` are required for the plugin to work. The plugin will error if these are not provided.

## mastodon global data object

The `mastodon` object has the following properties:

| Property    | Description                                                   |
| ----------- | ------------------------------------------------------------- |
| lastFetched | an ISO string indicating the last time the posts were fetched |
| posts       | an array of posts                                             |

### Mastodon posts

Each Mastodon post has the following properties:

| Property   | Description                                                                                                               |
| ---------- | ------------------------------------------------------------------------------------------------------------------------- |
| date       | The timestamp of the published post.                                                                                      |
| id         | The internal ID of the post on the Mastodon server.                                                                       |
| content    | The HTML of the post as it is displayed in the Mastodon UI.                                                               |
| source_url | The original URL of the post.                                                                                             |
| site       | Hard coded to "Mastodon".                                                                                                 |
| media      | An object if a single image or no image is attached to the post, or an array if multiple images are attached to the post. |
| emoji      | An array of custom emojis that were used in the post.                                                                     |

### Media objects

If the post contains a one or more images, the media property on the post will contain the following data:

| Property | Description                                  |
| -------- | -------------------------------------------- |
| image    | The URL of the image on the Mastodon server. |
| alt      | The ALT text of the image.                   |
| width    | The width of the image in pixels.            |
| height   | The height of the image in pixels.           |
| aspect   | The aspect ratio of the image.               |

### Custom emoji

If your post contains custom emoji, the emoji property will contain the following data:

| Property  | Description                                                  |
| --------- | ------------------------------------------------------------ |
| shortcode | The shortcode for the emoji. In the format `:<emoji name>:`. |
| url       | The static URL of the image on the Mastodon server.          |

---
_Source: https://npm.io/package/eleventy-plugin-mastoarchive · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
