fix(core): update
This commit is contained in:
24
ts/index.ts
Normal file
24
ts/index.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import * as plugins from './smartrobots.plugins';
|
||||
|
||||
export class Smartrobots {
|
||||
private webrequestInstance = new plugins.webrequest.WebRequest();
|
||||
|
||||
public async parseRobotsTxtFromUrl(urlArg: string) {
|
||||
const robotsTxtString = await (
|
||||
await this.webrequestInstance.request(urlArg, {
|
||||
method: 'GET',
|
||||
})
|
||||
).text();
|
||||
const parsedResult = this.parseRobotsTxt(robotsTxtString);
|
||||
return parsedResult;
|
||||
}
|
||||
|
||||
public async parseRobotsTxt(robotsTxt: string) {
|
||||
const lineArray = robotsTxt.split('\n');
|
||||
return {
|
||||
sitemaps: lineArray
|
||||
.filter((lineArg) => lineArg.startsWith('Sitemap: '))
|
||||
.map((lineArg) => lineArg.replace('Sitemap: ', '')),
|
||||
};
|
||||
}
|
||||
}
|
6
ts/smartrobots.plugins.ts
Normal file
6
ts/smartrobots.plugins.ts
Normal file
@ -0,0 +1,6 @@
|
||||
// @pushrocks scope
|
||||
import * as webrequest from '@pushrocks/webrequest';
|
||||
|
||||
export {
|
||||
webrequest
|
||||
}
|
Reference in New Issue
Block a user