generated from pascal-giguere/starter-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51bc7ea
commit 869fa11
Showing
2 changed files
with
99 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,5 @@ indent_style = space | |
indent_size = 2 | ||
max_line_length = 120 | ||
|
||
[*.{js,ts}] | ||
[*.{js,ts,md}] | ||
quote_type = single |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
``` |