fix(core): update

This commit is contained in:
2020-10-26 12:18:33 +00:00
parent 850f20fc38
commit b6abfd11d2
9 changed files with 132 additions and 64 deletions

3
ts/interfaces/index.ts Normal file
View File

@ -0,0 +1,3 @@
export interface ISitemapYaml {
daily: string[];
}

View File

@ -5,7 +5,7 @@ export class SitemapNews {
constructor(optionsArg: {}) {}
public async readFromRssFeed(urlArg: string) {
public async readAndAddFromRssFeed(urlArg: string) {
const smartfeedInstance = new plugins.smartfeed.Smartfeed();
const parsedFeed = await smartfeedInstance.parseFeedFromUrl(urlArg);
this.items = this.items.concat(parsedFeed.items);

View File

@ -0,0 +1,42 @@
import * as plugins from './smartsitemap.plugins';
export type TUpdateFrequency = 'never' | 'daily' | 'weekly' | 'monthly' | 'yearly';
export interface IUrlInfo {
url: string;
timestamp: number;
frequency?: TUpdateFrequency;
}
export class SitemapWebsite {
urlInfos: IUrlInfo[] = [];
constructor() {}
public addUrl(urlInfoArg: IUrlInfo) {
this.urlInfos.push(urlInfoArg);
}
public exportSitemapXml() {
const urls: {
loc: string;
lastmod: string;
changefreq: TUpdateFrequency;
}[] = [];
for (const urlInfoArg of this.urlInfos) {
urls.push({
loc: urlInfoArg.url,
lastmod: new Date(urlInfoArg.timestamp).toISOString(),
changefreq: urlInfoArg.frequency ? urlInfoArg.frequency : 'weekly'
});
}
const sitemapObject: any = {
urlset: {
'@_xmlns': 'http://www.sitemaps.org/schemas/sitemap/0.9',
url: urls,
},
};
const smartxmlInstance = new plugins.smartxml.SmartXml();
const sitemapString = smartxmlInstance.createXmlFromObject(sitemapObject);
return sitemapString;
}
}

View File

@ -5,10 +5,18 @@ export class SmartSitemap {
constructor() {}
/**
* creates a sitemap for news
* creates a sitemap for news from feedurl
*/
public createSmartsitemapNews(): SitemapNews {
public async createSitemapNewsFromFeedUrl(feedUrlArg: string): Promise<string> {
const sitemapNewsInstance = new SitemapNews({});
return sitemapNewsInstance;
await sitemapNewsInstance.readAndAddFromRssFeed(feedUrlArg);
return sitemapNewsInstance.exportSitemapXml();
}
/**
* creates a normal sitemap from a list of urls
*/
public async createSitemapFromYmlString(yamlString: string) {
const yamlObject = await plugins.smartyaml.yamlStringToObject(yamlString);
}
}

View File

@ -1,8 +1,12 @@
// pushrocks scope
import * as smartcache from '@pushrocks/smartcache';
import * as smartfeed from '@pushrocks/smartfeed';
import * as smartxml from '@pushrocks/smartxml';
import * as smartyaml from '@pushrocks/smartyaml';
export {
smartcache,
smartfeed,
smartxml
smartxml,
smartyaml
};