smartsitemap/ts/smartsitemap.classes.smartsitemap.ts

45 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-10-25 22:12:38 +00:00
import { SitemapNews } from './smartsitemap.classes.sitemapnews';
2020-10-28 15:14:54 +00:00
import { IUrlInfo, SitemapWebsite } from './smartsitemap.classes.sitemapwebsite';
2020-10-25 22:12:38 +00:00
import * as plugins from './smartsitemap.plugins';
2020-10-26 17:19:23 +00:00
import * as interfaces from './interfaces';
2020-10-25 22:12:38 +00:00
export class SmartSitemap {
constructor() {}
/**
2020-10-26 12:18:33 +00:00
* creates a sitemap for news from feedurl
2020-10-25 22:12:38 +00:00
*/
2020-10-26 12:18:33 +00:00
public async createSitemapNewsFromFeedUrl(feedUrlArg: string): Promise<string> {
2020-10-26 00:52:04 +00:00
const sitemapNewsInstance = new SitemapNews({});
2020-10-26 12:18:33 +00:00
await sitemapNewsInstance.readAndAddFromRssFeed(feedUrlArg);
return sitemapNewsInstance.exportSitemapXml();
}
/**
* creates a normal sitemap from a list of urls
*/
2020-10-28 15:14:54 +00:00
public async createSitemapFromYmlString(yamlString: string): Promise<string> {
2020-10-26 17:19:23 +00:00
const yamlObject: interfaces.ISitemapYaml = await plugins.smartyaml.yamlStringToObject(yamlString);
const sitemapWebsite = new SitemapWebsite();
for(const urlArg of yamlObject.daily) {
sitemapWebsite.addUrl({
url: urlArg,
timestamp: Date.now() - 10000,
frequency: 'daily'
});
}
2020-10-28 15:14:54 +00:00
return sitemapWebsite.exportSitemapXml();
}
/**
* creates a normal sitemap from a list of urls
*/
public async createSitemapFromUrlInfoArray(urlInfosArg: IUrlInfo[]) {
const sitemapWebsite = new SitemapWebsite();
for(const urlInfo of urlInfosArg) {
sitemapWebsite.addUrl(urlInfo);
}
return sitemapWebsite.exportSitemapXml();
2020-10-25 22:12:38 +00:00
}
2020-10-26 00:52:04 +00:00
}