Skip to content

Commit

Permalink
Add RSS feed function
Browse files Browse the repository at this point in the history
  • Loading branch information
Soleone committed Apr 6, 2021
1 parent 3601dcb commit fce77fe
Show file tree
Hide file tree
Showing 4 changed files with 1,686 additions and 0 deletions.
1 change: 1 addition & 0 deletions functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
36 changes: 36 additions & 0 deletions functions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const RSS = require('rss');
const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp();

exports.feed = functions.https.onRequest(async (req, res) => {
const rssFeed = new RSS({
title: 'Gunchained videos',
description: 'Gods Unchained videos feed',
feed_url: 'https://gunchained.app/feed.xml',
site_url: 'https://gunchained.app',
image_url: 'https://gunchained.app/img/gods-unchained-logo-256.f286f7ea.png',
language: 'en',
ttl: '60'
});

const querySnapshot = await admin.firestore().collection('videos').orderBy('publishedAt', 'desc').limit(50).get();
querySnapshot.forEach(doc => {
let id = doc.id;
let video = doc.data();
let url = `https://gunchained.app/videos/${id}`;

let item = {
title: video.title,
description: video.description.substring(0, 300) + '...',
url: url,
author: video.author,
date: video.publishedAt.toDate()
}
rssFeed.item(item);
});

res.type('application/xml');
res.send(rssFeed.xml());
});
Loading

0 comments on commit fce77fe

Please sign in to comment.