fix(core): update
This commit is contained in:
3
ts/interfaces/index.ts
Normal file
3
ts/interfaces/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export interface ISitemapYaml {
|
||||
daily: string[];
|
||||
}
|
@ -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);
|
||||
|
42
ts/smartsitemap.classes.sitemapwebsite.ts
Normal file
42
ts/smartsitemap.classes.sitemapwebsite.ts
Normal 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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
};
|
||||
|
Reference in New Issue
Block a user