fix(core): update

This commit is contained in:
2020-10-28 17:43:58 +00:00
parent 35680b135d
commit d03b37690f
6 changed files with 97 additions and 43 deletions

View File

@ -1,3 +1,17 @@
export interface ISitemapYaml {
daily: string[];
}
export interface IRssItem {
[key: string]: any;
link?: string;
guid?: string;
title?: string;
pubDate?: string;
creator?: string;
content?: string;
isoDate?: string;
categories?: string[];
contentSnippet?: string;
enclosure?: any;
}

View File

@ -1,20 +1,33 @@
import * as plugins from './smartsitemap.plugins';
import * as interfaces from './interfaces';
export class SitemapNews {
public items: any[] = [];
public rssItems: interfaces.IRssItem[] = [];
constructor(optionsArg: {}) {}
public async readAndAddFromRssFeedString(feedStringArg: string) {
const smartfeedInstance = new plugins.smartfeed.Smartfeed();
const parsedFeed = await smartfeedInstance.parseFeedFromString(feedStringArg);
this.items = this.items.concat(parsedFeed.items);
this.rssItems = this.rssItems.concat(parsedFeed.items);
}
public async readAndAddFromRssFeedUrl(urlArg: string) {
const smartfeedInstance = new plugins.smartfeed.Smartfeed();
const parsedFeed = await smartfeedInstance.parseFeedFromUrl(urlArg);
this.items = this.items.concat(parsedFeed.items);
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,
isoDate: new Date(/* TODO: put article timestamp here */).toISOString()
};
});
this.rssItems = this.rssItems.concat(rssItemArray);
}
public exportSitemapXml() {
@ -25,24 +38,24 @@ export class SitemapNews {
'news:name': string;
'news:language': string;
};
"news:publication_date" : string;
"news:keywords": string;
"news:title": string;
'news:publication_date': string;
'news:keywords': string;
'news:title': string;
};
}[] = [];
for (const itemArg of this.items) {
for (const itemArg of this.rssItems) {
urls.push({
loc: itemArg.link,
"news:news": {
"news:publication": {
"news:language": 'en',
"news:name": 'some name'
'news:news': {
'news:publication': {
'news:language': 'en',
'news:name': 'some name',
},
"news:keywords": '',
"news:publication_date": itemArg.isoDate,
"news:title": itemArg.title
}
})
'news:keywords': '',
'news:publication_date': itemArg.isoDate,
'news:title': itemArg.title,
},
});
}
const sitemapObject: any = {
urlset: {

View File

@ -15,6 +15,24 @@ export class SmartSitemap {
return sitemapNewsInstance.exportSitemapXml();
}
/**
* creates a sitemap for news from feedxmlstring
*/
public async createSitemapNewsFromAFeedStringArg(feedStringArg: string): Promise<string> {
const sitemapNewsInstance = new SitemapNews({});
await sitemapNewsInstance.readAndAddFromRssFeedString(feedStringArg);
return sitemapNewsInstance.exportSitemapXml();
}
/**
* creates a sitemap for news from an array of articles
*/
public async createSitemapNewsFromArticleArray(articleArrayArg: plugins.tsclass.content.IArticle[]): Promise<string> {
const sitemapNewsInstance = new SitemapNews({});
await sitemapNewsInstance.readAndParseArticles(articleArrayArg);
return sitemapNewsInstance.exportSitemapXml();
}
/**
* creates a normal sitemap from a list of urls
*/

View File

@ -10,3 +10,10 @@ export {
smartxml,
smartyaml
};
// tsclass
import * as tsclass from '@tsclass/tsclass';
export {
tsclass
};