Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
f2e96640fa | |||
72cd9f1a00 | |||
2e9394c330 | |||
f8241b49fb | |||
7adc7b9fb1 | |||
aabb8265cd | |||
b8befa85fa | |||
114cd1900b | |||
17d8cd6585 | |||
87cdc5bb5f | |||
d03b37690f | |||
35680b135d | |||
3170da0303 | |||
8a78cc6831 | |||
911c680452 | |||
0a3768a088 | |||
7ae31b4ee0 | |||
ac3d9aeb2d | |||
c312622fb1 |
22526
package-lock.json
generated
22526
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
22
package.json
22
package.json
@ -1,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartsitemap",
|
"name": "@pushrocks/smartsitemap",
|
||||||
"version": "1.0.6",
|
"version": "2.0.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a sitemap module",
|
"description": "a sitemap module",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -12,19 +13,20 @@
|
|||||||
"build": "(tsbuild --web)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.61",
|
||||||
"@gitzone/tsbundle": "^1.0.78",
|
"@gitzone/tsbundle": "^1.0.101",
|
||||||
"@gitzone/tstest": "^1.0.44",
|
"@gitzone/tstest": "^1.0.69",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@pushrocks/smartenv": "^5.0.0",
|
||||||
"@types/node": "^14.11.2",
|
"@pushrocks/tapbundle": "^5.0.3",
|
||||||
"tslint": "^6.1.3",
|
"@types/node": "^17.0.23"
|
||||||
"tslint-config-prettier": "^1.15.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartcache": "^1.0.13",
|
"@pushrocks/smartcache": "^1.0.13",
|
||||||
"@pushrocks/smartfeed": "^1.0.5",
|
"@pushrocks/smartfeed": "^1.0.11",
|
||||||
"@pushrocks/smartxml": "^1.0.6",
|
"@pushrocks/smartxml": "^1.0.6",
|
||||||
"@pushrocks/smartyaml": "^2.0.5"
|
"@pushrocks/smartyaml": "^2.0.5",
|
||||||
|
"@pushrocks/webrequest": "^3.0.3",
|
||||||
|
"@tsclass/tsclass": "^3.0.48"
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
|
11
test/test.ts
11
test/test.ts
@ -1,16 +1,21 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as smartsitemap from '../ts/index';
|
import * as smartsitemap from '../ts/index.js';
|
||||||
|
|
||||||
let testSmartsitemap: smartsitemap.SmartSitemap;
|
let testSmartsitemap: smartsitemap.SmartSitemap;
|
||||||
|
|
||||||
tap.test('should create an instance of Smartsitemap', async () => {
|
tap.test('should create an instance of Smartsitemap', async () => {
|
||||||
testSmartsitemap = new smartsitemap.SmartSitemap();
|
testSmartsitemap = new smartsitemap.SmartSitemap();
|
||||||
expect(testSmartsitemap).to.be.instanceOf(smartsitemap.SmartSitemap);
|
expect(testSmartsitemap).toBeInstanceOf(smartsitemap.SmartSitemap);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should create a sitemap from feed', async () => {
|
tap.test('should create a sitemap from feed', async () => {
|
||||||
const sitemapString = await testSmartsitemap.createSitemapNewsFromFeedUrl('https://www.theverge.com/rss/index.xml');
|
const sitemapString = await testSmartsitemap.createSitemapNewsFromFeedUrl('https://central.eu/feed');
|
||||||
console.log(sitemapString);
|
console.log(sitemapString);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should parse a sitemap', async () => {
|
||||||
|
const result = await testSmartsitemap.parseSitemapUrl('https://central.eu/sitemap-news');
|
||||||
|
console.log(result.urlset.url);
|
||||||
|
})
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
export * from './smartsitemap.classes.smartsitemap';
|
export * from './smartsitemap.classes.smartsitemap.js';
|
||||||
export * from './smartsitemap.classes.sitemapnews';
|
export * from './smartsitemap.classes.sitemapnews.js';
|
||||||
|
export * from './smartsitemap.classes.sitemapwebsite.js';
|
@ -1,3 +1,42 @@
|
|||||||
export interface ISitemapYaml {
|
export interface ISitemapYaml {
|
||||||
daily: string[];
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IParsedSiteMap {
|
||||||
|
urlset: {
|
||||||
|
url:
|
||||||
|
| {
|
||||||
|
loc: string;
|
||||||
|
lastmod: string;
|
||||||
|
changefreq: string;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
loc: string;
|
||||||
|
lastmod: string;
|
||||||
|
changefreq: string;
|
||||||
|
}[]
|
||||||
|
| {
|
||||||
|
loc: string;
|
||||||
|
'news:news': {
|
||||||
|
'news:publication': [];
|
||||||
|
'news:keywords': string;
|
||||||
|
'news:publication_date': string;
|
||||||
|
'news:title': string;
|
||||||
|
};
|
||||||
|
}[];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -1,14 +1,34 @@
|
|||||||
import * as plugins from './smartsitemap.plugins';
|
import * as plugins from './smartsitemap.plugins.js';
|
||||||
|
import * as interfaces from './interfaces/index.js';
|
||||||
|
|
||||||
export class SitemapNews {
|
export class SitemapNews {
|
||||||
public items: any[] = [];
|
public rssItems: interfaces.IRssItem[] = [];
|
||||||
|
|
||||||
constructor(optionsArg: {}) {}
|
constructor(optionsArg: {}) {}
|
||||||
|
|
||||||
public async readAndAddFromRssFeed(urlArg: string) {
|
public async readAndAddFromRssFeedString(feedStringArg: string) {
|
||||||
|
const smartfeedInstance = new plugins.smartfeed.Smartfeed();
|
||||||
|
const parsedFeed = await smartfeedInstance.parseFeedFromString(feedStringArg);
|
||||||
|
this.rssItems = this.rssItems.concat(parsedFeed.items);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async readAndAddFromRssFeedUrl(urlArg: string) {
|
||||||
const smartfeedInstance = new plugins.smartfeed.Smartfeed();
|
const smartfeedInstance = new plugins.smartfeed.Smartfeed();
|
||||||
const parsedFeed = await smartfeedInstance.parseFeedFromUrl(urlArg);
|
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(),
|
||||||
|
link: articleArg.url
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
this.rssItems = this.rssItems.concat(rssItemArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
public exportSitemapXml() {
|
public exportSitemapXml() {
|
||||||
@ -19,24 +39,25 @@ export class SitemapNews {
|
|||||||
'news:name': string;
|
'news:name': string;
|
||||||
'news:language': string;
|
'news:language': string;
|
||||||
};
|
};
|
||||||
"news:publication_date" : string;
|
'news:publication_date': string;
|
||||||
"news:keywords": string;
|
'news:keywords': string;
|
||||||
"news:title": string;
|
'news:title': string;
|
||||||
};
|
};
|
||||||
}[] = [];
|
}[] = [];
|
||||||
for (const itemArg of this.items) {
|
for (const itemArg of this.rssItems) {
|
||||||
|
console.log(itemArg);
|
||||||
urls.push({
|
urls.push({
|
||||||
loc: itemArg.link,
|
loc: itemArg.link,
|
||||||
"news:news": {
|
'news:news': {
|
||||||
"news:publication": {
|
'news:publication': {
|
||||||
"news:language": 'en',
|
'news:language': 'en',
|
||||||
"news:name": 'some name'
|
'news:name': 'some name',
|
||||||
},
|
},
|
||||||
"news:keywords": '',
|
'news:keywords': '',
|
||||||
"news:publication_date": itemArg.isoDate,
|
'news:publication_date': itemArg.isoDate,
|
||||||
"news:title": itemArg.title
|
'news:title': itemArg.title,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
const sitemapObject: any = {
|
const sitemapObject: any = {
|
||||||
urlset: {
|
urlset: {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './smartsitemap.plugins';
|
import * as plugins from './smartsitemap.plugins.js';
|
||||||
|
|
||||||
export type TUpdateFrequency = 'never' | 'daily' | 'weekly' | 'monthly' | 'yearly';
|
export type TUpdateFrequency = 'never' | 'daily' | 'weekly' | 'monthly' | 'yearly';
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import { SitemapNews } from './smartsitemap.classes.sitemapnews';
|
import { SitemapNews } from './smartsitemap.classes.sitemapnews.js';
|
||||||
import * as plugins from './smartsitemap.plugins';
|
import { IUrlInfo, SitemapWebsite } from './smartsitemap.classes.sitemapwebsite.js';
|
||||||
|
import * as plugins from './smartsitemap.plugins.js';
|
||||||
|
import * as interfaces from './interfaces/index.js';
|
||||||
|
|
||||||
export class SmartSitemap {
|
export class SmartSitemap {
|
||||||
constructor() {}
|
constructor() {}
|
||||||
@ -9,14 +11,71 @@ export class SmartSitemap {
|
|||||||
*/
|
*/
|
||||||
public async createSitemapNewsFromFeedUrl(feedUrlArg: string): Promise<string> {
|
public async createSitemapNewsFromFeedUrl(feedUrlArg: string): Promise<string> {
|
||||||
const sitemapNewsInstance = new SitemapNews({});
|
const sitemapNewsInstance = new SitemapNews({});
|
||||||
await sitemapNewsInstance.readAndAddFromRssFeed(feedUrlArg);
|
await sitemapNewsInstance.readAndAddFromRssFeedUrl(feedUrlArg);
|
||||||
|
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();
|
return sitemapNewsInstance.exportSitemapXml();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a normal sitemap from a list of urls
|
* creates a normal sitemap from a list of urls
|
||||||
*/
|
*/
|
||||||
public async createSitemapFromYmlString(yamlString: string) {
|
public async createSitemapFromYmlString(yamlString: string): Promise<string> {
|
||||||
const yamlObject = await plugins.smartyaml.yamlStringToObject(yamlString);
|
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'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* parses a sitemap url
|
||||||
|
*/
|
||||||
|
public async parseSitemapUrl(urlArg: string) {
|
||||||
|
const sitemapXml = await (await (new plugins.webrequest.WebRequest()).request(urlArg, {
|
||||||
|
method: 'GET'
|
||||||
|
})).text();
|
||||||
|
|
||||||
|
const parsedSitemap = await this.parseSitemap(sitemapXml);
|
||||||
|
return parsedSitemap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* parses a sitemap
|
||||||
|
*/
|
||||||
|
public async parseSitemap(sitemapXmlArg: string): Promise<interfaces.IParsedSiteMap> {
|
||||||
|
return (new plugins.smartxml.SmartXml()).parseXmlToObject(sitemapXmlArg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,19 @@ import * as smartcache from '@pushrocks/smartcache';
|
|||||||
import * as smartfeed from '@pushrocks/smartfeed';
|
import * as smartfeed from '@pushrocks/smartfeed';
|
||||||
import * as smartxml from '@pushrocks/smartxml';
|
import * as smartxml from '@pushrocks/smartxml';
|
||||||
import * as smartyaml from '@pushrocks/smartyaml';
|
import * as smartyaml from '@pushrocks/smartyaml';
|
||||||
|
import * as webrequest from '@pushrocks/webrequest';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
smartcache,
|
smartcache,
|
||||||
smartfeed,
|
smartfeed,
|
||||||
smartxml,
|
smartxml,
|
||||||
smartyaml
|
smartyaml,
|
||||||
|
webrequest
|
||||||
|
};
|
||||||
|
|
||||||
|
// tsclass
|
||||||
|
import * as tsclass from '@tsclass/tsclass';
|
||||||
|
|
||||||
|
export {
|
||||||
|
tsclass
|
||||||
};
|
};
|
||||||
|
9
tsconfig.json
Normal file
9
tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext"
|
||||||
|
}
|
||||||
|
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
Reference in New Issue
Block a user