smartsitemap/ts/smartsitemap.classes.sitemapnews.ts

53 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-10-25 22:12:38 +00:00
import * as plugins from './smartsitemap.plugins';
export class SitemapNews {
2020-10-26 00:52:04 +00:00
public items: any[] = [];
constructor(optionsArg: {}) {}
public async readFromRssFeed(urlArg: string) {
const smartfeedInstance = new plugins.smartfeed.Smartfeed();
const parsedFeed = await smartfeedInstance.parseFeedFromUrl(urlArg);
this.items = this.items.concat(parsedFeed.items);
}
public exportSitemapXml() {
const urls: {
loc: string;
'news:news': {
'news:publication': {
'news:name': string;
'news:language': string;
};
"news:publication_date" : string;
"news:keywords": string;
"news:title": string;
};
}[] = [];
for (const itemArg of this.items) {
urls.push({
loc: itemArg.link,
"news:news": {
"news:publication": {
"news:language": 'en',
"news:name": 'some name'
},
"news:keywords": '',
"news:publication_date": itemArg.isoDate,
"news:title": itemArg.title
}
})
}
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
}
}