2020-10-25 14:02:03 +00:00
|
|
|
import { Feed, IFeedOptions } from './smartfeed.classes.feed';
|
2020-10-25 00:09:33 +00:00
|
|
|
import * as plugins from './smartfeed.plugins';
|
|
|
|
|
2020-10-25 14:02:03 +00:00
|
|
|
export class Smartfeed {
|
|
|
|
public createFeed(optionsArg: IFeedOptions) {
|
|
|
|
const feedVersion = new Feed(optionsArg);
|
|
|
|
return feedVersion;
|
|
|
|
}
|
2020-10-25 22:11:00 +00:00
|
|
|
|
2020-10-31 11:38:41 +00:00
|
|
|
/**
|
|
|
|
* creates a feed from a standardized article object (@tsclass/tsclass).content.IArticle
|
|
|
|
*/
|
|
|
|
public async createFeedFromArticleArray(optionsArg: IFeedOptions, articleArray: plugins.tsclass.content.IArticle[]): Promise<string> {
|
|
|
|
const feed = this.createFeed(optionsArg);
|
|
|
|
for (const article of articleArray) {
|
|
|
|
feed.addItem({
|
|
|
|
authorName: `${article.author.firstName} ${article.author.surName}`,
|
|
|
|
timestamp: article.timestamp,
|
|
|
|
imageUrl: article.featuredImageUrl,
|
|
|
|
title: article.title,
|
|
|
|
url: article.url
|
|
|
|
});
|
|
|
|
}
|
|
|
|
const feedXmlString = feed.exportRssFeedString();
|
|
|
|
return feedXmlString;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* allows the parsing of a rss feed string
|
|
|
|
* @param rssFeedString
|
|
|
|
*/
|
2020-10-25 22:11:00 +00:00
|
|
|
public async parseFeedFromString(rssFeedString: string) {
|
|
|
|
const parser = new plugins.rssParser();
|
|
|
|
const resultingFeed = await parser.parseString(rssFeedString);
|
|
|
|
return resultingFeed;
|
|
|
|
}
|
|
|
|
|
2020-10-31 11:38:41 +00:00
|
|
|
/**
|
|
|
|
* allows the parsing of a feed from urls
|
|
|
|
* @param urlArg
|
|
|
|
*/
|
2020-10-25 22:11:00 +00:00
|
|
|
public async parseFeedFromUrl(urlArg: string) {
|
|
|
|
const parser = new plugins.rssParser();
|
|
|
|
const resultingFeed = await parser.parseURL(urlArg);
|
|
|
|
return resultingFeed;
|
|
|
|
}
|
2020-10-25 14:02:03 +00:00
|
|
|
}
|