2022-03-24 23:14:34 +00:00
|
|
|
import * as plugins from './smartsitemap.plugins.js';
|
|
|
|
import * as interfaces from './interfaces/index.js';
|
2020-10-25 22:12:38 +00:00
|
|
|
|
|
|
|
export class SitemapNews {
|
2020-10-28 17:43:58 +00:00
|
|
|
public rssItems: interfaces.IRssItem[] = [];
|
2020-10-26 00:52:04 +00:00
|
|
|
|
|
|
|
constructor(optionsArg: {}) {}
|
|
|
|
|
2020-10-28 15:54:39 +00:00
|
|
|
public async readAndAddFromRssFeedString(feedStringArg: string) {
|
|
|
|
const smartfeedInstance = new plugins.smartfeed.Smartfeed();
|
|
|
|
const parsedFeed = await smartfeedInstance.parseFeedFromString(feedStringArg);
|
2020-10-28 17:43:58 +00:00
|
|
|
this.rssItems = this.rssItems.concat(parsedFeed.items);
|
2020-10-28 15:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public async readAndAddFromRssFeedUrl(urlArg: string) {
|
2020-10-26 00:52:04 +00:00
|
|
|
const smartfeedInstance = new plugins.smartfeed.Smartfeed();
|
|
|
|
const parsedFeed = await smartfeedInstance.parseFeedFromUrl(urlArg);
|
2020-10-28 17:43:58 +00:00
|
|
|
this.rssItems = this.rssItems.concat(parsedFeed.items);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async readAndParseArticles(articleArrayArg: plugins.tsclass.content.IArticle[]) {
|
|
|
|
const rssItemArray = articleArrayArg.map((articleArg): interfaces.IRssItem => {
|
|
|
|
return {
|
|
|
|
title: articleArg.title,
|
|
|
|
content: articleArg.content,
|
2021-01-03 14:28:29 +00:00
|
|
|
isoDate: new Date(/* TODO: put article timestamp here */).toISOString(),
|
2023-07-27 14:16:37 +00:00
|
|
|
link: articleArg.url,
|
2020-10-28 17:43:58 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
this.rssItems = this.rssItems.concat(rssItemArray);
|
2020-10-26 00:52:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public exportSitemapXml() {
|
|
|
|
const urls: {
|
|
|
|
loc: string;
|
|
|
|
'news:news': {
|
|
|
|
'news:publication': {
|
|
|
|
'news:name': string;
|
|
|
|
'news:language': string;
|
|
|
|
};
|
2020-10-28 17:43:58 +00:00
|
|
|
'news:publication_date': string;
|
|
|
|
'news:keywords': string;
|
|
|
|
'news:title': string;
|
2020-10-26 00:52:04 +00:00
|
|
|
};
|
|
|
|
}[] = [];
|
2020-10-28 17:43:58 +00:00
|
|
|
for (const itemArg of this.rssItems) {
|
2021-01-03 02:48:45 +00:00
|
|
|
console.log(itemArg);
|
2020-10-26 00:52:04 +00:00
|
|
|
urls.push({
|
|
|
|
loc: itemArg.link,
|
2020-10-28 17:43:58 +00:00
|
|
|
'news:news': {
|
|
|
|
'news:publication': {
|
|
|
|
'news:language': 'en',
|
|
|
|
'news:name': 'some name',
|
2020-10-26 00:52:04 +00:00
|
|
|
},
|
2020-10-28 17:43:58 +00:00
|
|
|
'news:keywords': '',
|
|
|
|
'news:publication_date': itemArg.isoDate,
|
|
|
|
'news:title': itemArg.title,
|
|
|
|
},
|
|
|
|
});
|
2020-10-26 00:52:04 +00:00
|
|
|
}
|
|
|
|
const sitemapObject: any = {
|
|
|
|
urlset: {
|
|
|
|
'@_xmlns': 'http://www.sitemaps.org/schemas/sitemap/0.9',
|
|
|
|
'@_xmlns:news': 'http://www.google.com/schemas/sitemap-news/0.9',
|
|
|
|
url: urls,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const smartxmlInstance = new plugins.smartxml.SmartXml();
|
|
|
|
const sitemapString = smartxmlInstance.createXmlFromObject(sitemapObject);
|
|
|
|
return sitemapString;
|
2020-10-25 22:12:38 +00:00
|
|
|
}
|
|
|
|
}
|