feedfind 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -2
- package/index.js +88 -0
- package/package.json +21 -4
package/README.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
-
#
|
|
1
|
+
# feedfind
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Find RSS/Atom feeds for one or more URLs.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install [`feedfind`](https://npmjs.com/package/feedfind/) from npm:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g feedfind
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or use with `npx` without installing:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx feedfind
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Send URLs as operands or point the `--input` (or `-i`) option to a list of newline-separated URLs:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
feedfind https://example.com https://another.com
|
|
25
|
+
feedfind --input=list-of-urls.txt
|
|
26
|
+
```
|
package/index.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { parseArgs } from 'node:util';
|
|
4
|
+
|
|
5
|
+
import { JSDOM, VirtualConsole } from 'jsdom';
|
|
6
|
+
|
|
7
|
+
const { positionals: operands, values: options } = parseArgs({
|
|
8
|
+
options: {
|
|
9
|
+
help: {
|
|
10
|
+
type: 'boolean',
|
|
11
|
+
short: 'h'
|
|
12
|
+
},
|
|
13
|
+
version: {
|
|
14
|
+
type: 'boolean',
|
|
15
|
+
short: 'v'
|
|
16
|
+
},
|
|
17
|
+
input: {
|
|
18
|
+
type: 'string',
|
|
19
|
+
short: 'i'
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
allowPositionals: true
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if (options.help) {
|
|
26
|
+
printHelp();
|
|
27
|
+
process.exit(0);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (options.version) {
|
|
31
|
+
const pkg = await JSON.parse(
|
|
32
|
+
await readFile(new URL('./package.json', import.meta.url))
|
|
33
|
+
);
|
|
34
|
+
process.stdout.write(`${pkg.version}\n`);
|
|
35
|
+
process.exit(0);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let urls = operands ?? [];
|
|
39
|
+
|
|
40
|
+
if (options.inputfile) {
|
|
41
|
+
const content = await readFile(options.inputfile, 'utf8');
|
|
42
|
+
urls = urls.concat(
|
|
43
|
+
content
|
|
44
|
+
.split('\n')
|
|
45
|
+
.map(line => line.trim())
|
|
46
|
+
.filter(line => line && line.indexOf('#') !== 0)
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let feeds = [];
|
|
51
|
+
|
|
52
|
+
for (let url of urls.filter(it => URL.canParse(it))) {
|
|
53
|
+
try {
|
|
54
|
+
const res = await fetch(url, {
|
|
55
|
+
signal: AbortSignal.timeout(5000)
|
|
56
|
+
});
|
|
57
|
+
if (!res.ok) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const dom = new JSDOM(await res.text(), {
|
|
61
|
+
url,
|
|
62
|
+
virtualConsole: new VirtualConsole()
|
|
63
|
+
});
|
|
64
|
+
feeds = feeds.concat(
|
|
65
|
+
Array.from(
|
|
66
|
+
dom.window.document.querySelectorAll(`
|
|
67
|
+
link[rel~=alternate][type="application/atom+xml"],
|
|
68
|
+
link[rel~=alternate][type="application/rss+xml"]
|
|
69
|
+
`)
|
|
70
|
+
).map(el => {
|
|
71
|
+
try {
|
|
72
|
+
process.stdout.write(`${url} → ${new URL(el.href, url)}\n`);
|
|
73
|
+
} catch (err) {}
|
|
74
|
+
}).filter(Boolean)
|
|
75
|
+
);
|
|
76
|
+
} catch (err) {}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function printHelp() {
|
|
80
|
+
process.stdout.write(`feedfind:
|
|
81
|
+
find RSS/Atom feeds for URLs.
|
|
82
|
+
|
|
83
|
+
Usage:
|
|
84
|
+
|
|
85
|
+
feedfind https://example.com https://another.com …
|
|
86
|
+
feedfind --input=list-of-urls.txt
|
|
87
|
+
`);
|
|
88
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "feedfind",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Find feeds",
|
|
5
|
+
"homepage": "https://github.com/danburzo/feedfind#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/danburzo/feedfind/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/danburzo/feedfind.git"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "index.js",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"jsdom": "^31.0.1"
|
|
22
|
+
}
|
|
23
|
+
}
|