smartsitemap/ts/smartsitemap.classes.sitemapnews.ts
2020-10-26 12:18:33 +00:00

53 lines
1.5 KiB
TypeScript

import * as plugins from './smartsitemap.plugins';
export class SitemapNews {
public items: any[] = [];
constructor(optionsArg: {}) {}
public async readAndAddFromRssFeed(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;
}
}