1.6.2 • Published 4 months ago

mastofeed v1.6.2

Weekly downloads
-
License
GPL-3.0-only
Repository
github
Last release
4 months ago

Mastofeed 📬

A Node.js library to post RSS feed items to Mastodon.

  • Syncs new RSS feed items and posts them from a Mastodon bot account.
  • Outputs rich, highly-customizable posts. Extract and transform any RSS item attribute.
  • Type-safe and entirely built with TypeScript.

License: GPL v3

Automated post from @lapresse@mastodon.quebec displayed in Ivory

Prerequisites

Mastofeed requires that you use a Mastodon bot account and generate an access token for it.

To do so, log into your Mastodon instance with your bot account, then go to Preferences > Development and create a new application with the read:accounts, read:statuses and write:statuses scopes. Take note of the access token generated for your application.

Installation

npm install mastofeed

Usage

Instantiate a Mastofeed client, providing your Mastodon and RSS configuration.

Use the rss.postDef property to define a mapping of RSS item attributes and customize the contents of your Mastodon posts.

Basic example

import { Mastofeed } from 'mastofeed';

const feed = new Mastofeed({
  mastodon: {
    instanceUrl: 'https://mastodon.quebec',
    accessToken: process.env.MASTODON_ACCESS_TOKEN,
  },
  rss: {
    feedUrl: 'https://www.lapresse.ca/manchettes/rss',
    postDef: {
      id: { path: 'guid' },
      title: { path: 'title' },
      linkUrl: { path: 'link' },
    },
  },
});

Advanced example

import {
  Mastofeed,
  UppercaseTransform,
  BoldTransform,
  MapTransform,
  QuotationMarksTransform,
  ItalicTransform,
} from 'mastofeed';

const feed = new Mastofeed({
  mastodon: {
    instanceUrl: 'https://mastodon.quebec',
    accessToken: process.env.MASTODON_ACCESS_TOKEN,
  },
  rss: {
    feedUrl: 'https://www.lapresse.ca/manchettes/rss',
    postDef: {
      id: { path: 'guid' },
      kicker: { path: 'title', regex: '^(.+) \\|', transforms: [new UppercaseTransform()] },
      title: { path: 'title', regex: '(?!.*\\|) *(.+)?', transforms: [new BoldTransform()] },
      category: {
        path: 'link',
        regex: '^https:\\/\\/www\\.lapresse\\.ca\\/(\\w+)\\/',
        transforms: [
          new MapTransform({
            actualites: 'Actualités',
            affaires: 'Affaires',
            auto: 'Auto',
            arts: 'Arts',
            cinema: 'Cinéma',
            contexte: 'Contexte',
            debats: 'Débats',
            gourmand: 'Gourmand',
            international: 'International',
            maison: 'Maison',
            societe: 'Société',
            sports: 'Sports',
            voyage: 'Voyage',
          }),
        ],
      },
      description: {
        path: 'contentSnippet',
        transforms: [new QuotationMarksTransform(), new ItalicTransform()],
      },
      author: { path: 'dc:creator' },
      linkUrl: { path: 'link' },
    },
    maxSyncedItems: 10,
  },
  logging: {
    level: 'DEBUG',
    prefix: 'La Presse',
  },
});

Publishing to Mastodon

Then, to post all new RSS feed items to Mastodon from your bot account:

await feed.sync();

Full project example

See Mastodon Québec Bots for a full example of a project using Mastofeed.

Privacy

Mastofeed does not collect any analytics or telemetry data.

The addition of the mfid query parameter in URLs is strictly used to prevent duplicate posts.

1.6.2

4 months ago

1.6.1

4 months ago

1.5.12

4 months ago

1.6.0

8 months ago

1.5.10

1 year ago

1.5.11

1 year ago

1.5.9

1 year ago

1.5.8

1 year ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

0.5.8

2 years ago

0.5.7

2 years ago

1.5.4

2 years ago

1.5.3

2 years ago

1.5.2

2 years ago

1.2.5

2 years ago

1.5.1

2 years ago

1.2.4

2 years ago

1.5.0

2 years ago

1.4.1

2 years ago

1.2.3

2 years ago

1.4.0

2 years ago

1.2.2

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.5.7

2 years ago

1.5.6

2 years ago

0.6.3

2 years ago

0.5.4

2 years ago

0.6.2

2 years ago

0.5.3

2 years ago

0.5.6

2 years ago

0.6.4

2 years ago

0.5.5

2 years ago

0.6.1

2 years ago

0.5.2

2 years ago

0.6.0

2 years ago

0.5.1

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago