Skip to content

Commit

Permalink
add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-giguere committed Sep 11, 2023
1 parent 51bc7ea commit 869fa11
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ indent_style = space
indent_size = 2
max_line_length = 120

[*.{js,ts}]
[*.{js,ts,md}]
quote_type = single
107 changes: 98 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,100 @@
# @pascal-giguere/starter-node
# Mastofeed

Pascal's starter Node project using:
- Node 18
- TypeScript 4
- Yarn 3 (with PnP)
- Prettier 2
- ESLint 8
- Jest 29
Publish RSS feeds to Mastodon using bot accounts.

Original repository: https://github.com/pascal-giguere/starter-node
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

## Prerequisite

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

To generate an access token, log in to your Mastodon instance with your bot account, then go to Preferences >
Development and create a new application with the `write:media` and `write:statuses` scopes. Take note of the access
token that is generated for your application.

## Installation

```bash
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:

```js
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:

```js
import { Mastofeed, MapTransform, UppercaseTransform } 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', regex: '(?!.*\\|) *(.+)?' },
kicker: { path: 'title', regex: '^(.+) \\|', transforms: [new UppercaseTransform()] },
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' },
author: { path: 'dc:creator' },
imageUrl: { path: 'enclosure.url' },
linkUrl: { path: 'link' },
},
},
});
```

#### Publishing to Mastodon

Then, to publish all new RSS items to your Mastodon instance from your bot account:

```js
await feed.publish();
```

0 comments on commit 869fa11

Please sign in to comment.