rss-url-finder
Advanced tools
Comparing version
@@ -8,1 +8,2 @@ import { RssSource } from "./types"; | ||
export declare function getDomainName(html: HTMLElement): string | undefined; | ||
export declare function analyzeSitemap(url: string): Promise<RssSource | undefined>; |
@@ -12,4 +12,13 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getDomainName = exports.guessRSSfromUrl = exports.generateGuesses = exports.getHtmlBody = exports.newRssSource = void 0; | ||
exports.analyzeSitemap = exports.getDomainName = exports.guessRSSfromUrl = exports.generateGuesses = exports.getHtmlBody = exports.newRssSource = void 0; | ||
const types_1 = require("./types"); | ||
function getBaseUrl(url) { | ||
try { | ||
const { protocol, hostname } = new URL(url); | ||
return `${protocol}//${hostname}`; | ||
} | ||
catch (error) { | ||
return undefined; | ||
} | ||
} | ||
function newRssSource({ name, url }) { | ||
@@ -32,5 +41,5 @@ return { | ||
const commonUrls = ['/feed', '/rss', '/rss.xml', '/feed.xml']; | ||
const { hostname, protocol } = new URL(url); | ||
const baseUrl = getBaseUrl(url); | ||
for (const url of commonUrls) { | ||
urls.push(`${protocol}//${hostname}${url}`); | ||
urls.push(`${baseUrl}${url}`); | ||
} | ||
@@ -64,16 +73,27 @@ return urls; | ||
function getDomainName(html) { | ||
var _a; | ||
let domain = (_a = html.querySelector(`link[rel="canonical"]`)) === null || _a === void 0 ? void 0 : _a.attrs.href; | ||
if (domain) { | ||
try { | ||
const { hostname, protocol } = new URL(domain); | ||
domain = `${protocol}//${hostname}`; | ||
return domain; | ||
} | ||
catch (error) { | ||
return undefined; | ||
} | ||
} | ||
var _a, _b; | ||
let baseUrl = (_a = html.querySelector(`link[rel="canonical"]`)) === null || _a === void 0 ? void 0 : _a.attrs.href; | ||
if (baseUrl) | ||
return getBaseUrl(baseUrl); | ||
baseUrl = (_b = html.querySelector(`meta[property="og:url"]`)) === null || _b === void 0 ? void 0 : _b.attrs.content; | ||
if (baseUrl) | ||
return getBaseUrl(baseUrl); | ||
return undefined; | ||
} | ||
exports.getDomainName = getDomainName; | ||
function analyzeSitemap(url) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const baseUrl = getBaseUrl(url); | ||
const robotsUrl = (new URL('robots.txt', baseUrl)).toString(); | ||
const text = yield getHtmlBody(robotsUrl); | ||
const existsSitemap = /^Sitemap: (.+)$/s.exec(text); | ||
if (existsSitemap) { | ||
return { | ||
name: 'Sitemap', | ||
url: existsSitemap[1].trim(), | ||
}; | ||
} | ||
return undefined; | ||
}); | ||
} | ||
exports.analyzeSitemap = analyzeSitemap; |
{ | ||
"name": "rss-url-finder", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": " A javascript/typescript library to search RSS feed via URL or HTML body ", | ||
@@ -10,3 +10,4 @@ "main": "dist/index.js", | ||
"build": "tsc", | ||
"test": "jest" | ||
"test": "jest", | ||
"publish": "npm run build && npm publish" | ||
}, | ||
@@ -13,0 +14,0 @@ "repository": { |
@@ -41,2 +41,3 @@ # RSS URL Finder | ||
<link rel="alternate" href="/rss2.xml" title="Dev-Academy.com - Web security | Testing & automation | Application architecture" type="application/rss+xml"> | ||
<link rel="canonical" href="https://dev-academy.com/"> | ||
</head> | ||
@@ -51,3 +52,3 @@ </figure> | ||
...... AND EXAMPLE OF HTML ........... | ||
<script src="https://my.asdasdasd23123.com/2323323asdasdasdasdd.js" data-cookieconsent="ignore" charset="utf-8" async="async"></script> | ||
<script src="https://my.hellobar.com/3211232132.js" data-cookieconsent="ignore" charset="utf-8" async="async"></script> | ||
</body> | ||
@@ -62,7 +63,7 @@ </html> | ||
// name: 'Dev-Academy.com - Web security | Testing & automation | Application architecture', | ||
// url: '/rss2.xml' | ||
// url: 'https://dev-academy.com/rss2.xml' | ||
// }, | ||
// { | ||
// name: 'Dev-Academy.com - Web security | Testing & automation | Application architecture', | ||
// url: '/atom.xml' | ||
// url: 'https://dev-academy.com/atom.xml' | ||
// } | ||
@@ -69,0 +70,0 @@ // ] |
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
238147
0.46%13
8.33%1551
1.64%77
1.32%