Skip to content

Commit

Permalink
feat(@galactiks/rss): bootstrap rss package
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelgautier committed Sep 24, 2023
1 parent 43b0ddb commit a6c53a6
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 52 deletions.
28 changes: 28 additions & 0 deletions packages/rss/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# @galactiks/rss

This package get articles from [Galactiks](https://www.galactiks.com) content and generate RSS/Atom feeds from this content.

## Installation

Install the `@galactiks/rss` package using your preferred package manager:

```sh
# npm
npm i @galactiks/rss

# yarn
yarn add @galactiks/rss

# pnpm
pnpm i @galactiks/rss
```

If you run into any issues, [feel free to report them to us on GitHub](https://github.com/thegalactiks/explorer/issues).

## Getting started

Coming soon

## License

MIT © [Galactiks](https://www.galactiks.com)
41 changes: 41 additions & 0 deletions packages/rss/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@galactiks/rss",
"version": "0.2.1",
"description": "Generate RSS and Atom feeds from Galactiks content",
"author": "thegalactiks",
"types": "./dist/index.d.mts",
"license": "MIT",
"engines": {
"node": ">=18.0.0"
},
"bugs": "https://github.com/thegalactiks/explorer/issues",
"homepage": "https://www.galactiks.com",
"repository": {
"type": "git",
"url": "https://github.com/thegalactiks/explorer.git",
"directory": "packages/rss"
},
"main": "dist/index.mjs",
"scripts": {
"build": "tsc -p ./tsconfig.json",
"build:ci": "tsc -p ./tsconfig.json"
},
"exports": {
"./package.json": "./package.json",
".": "./dist/index.mjs"
},
"files": [
"dist"
],
"keywords": [
"galactiks",
"rss",
"atom",
"feed"
],
"dependencies": {
"@galactiks/config": "workspace:^",
"@galactiks/explorer": "workspace:^",
"feed": "4.2.2"
}
}
39 changes: 39 additions & 0 deletions packages/rss/src/index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { getConfig, getDefaultLanguage } from '@galactiks/config';
import { getWebPageDocumentsByType } from '@galactiks/explorer';
import { Feed } from 'feed';

const galactiksConfig = getConfig();

export async function getRSS() {
const articles = await getWebPageDocumentsByType('Article');

const feed = new Feed({
title: galactiksConfig.webManifest.name,
description: galactiksConfig.webManifest.description,
id: galactiksConfig.name || galactiksConfig.webManifest.name,
link: galactiksConfig.webManifest.start_url,
language: getDefaultLanguage(),
copyright: '',
generator: 'Galactiks',
});

articles.forEach((article) => {
feed.addItem({
title: article.name,
id: article.url,
link: article.url,
date: article.datePublished,
image: article.image?.contentUrl,
description: article.description,
author: article.author && [
{
name: article.author.name,
email: article.author.email,
link: article.author.url,
},
],
});
});

return feed;
}
10 changes: 10 additions & 0 deletions packages/rss/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src"],
"compilerOptions": {
"allowJs": true,
"target": "ES2021",
"module": "ES2022",
"outDir": "./dist"
}
}
Loading

0 comments on commit a6c53a6

Please sign in to comment.