Skip to content

Commit 9d2f7f9

Browse files
committed
feat: initial commit
0 parents  commit 9d2f7f9

21 files changed

+584
-0
lines changed

.eslintrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
plugins: ['node'],
3+
extends: ['eslint:recommended', 'plugin:node/recommended'],
4+
rules: {
5+
'node/no-deprecated-api': 0,
6+
'no-console': 0,
7+
},
8+
};

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
generated/*
3+
.vscode

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8

data/bad-hosts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
http://pipes.yahoo.com
2+
http://andreaarbogast.org

data/known-hosts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
https://jkphl.is https://jkphl.is/webmention.php
2+
http://aaronparecki.com https://webmention.io/aaronpk/webmention
3+
https://indiewebcamp.com https://webmention.io/indiewebcamp/webmention
4+
http://indiewebcamp.com https://webmention.io/indiewebcamp/webmention
5+
http://webmention.io https://webmention.io/pingback/webmention
6+
https://quill.p3k.io https://webmention.io/aaronpk/webmention
7+
https://ben.thatmustbe.me https://ben.thatmustbe.me/api/webmention
8+
https://ownyourgram.com http://ownyourgram.com/webmention
9+
http://xtof.withknown.com https://xtof.withknown.com/webmention/
10+
https://adactio.com https://adactio.com/webmention

data/unknown-hosts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
https://border-none.net
2+
https://gist.github.com
3+
http://microformats.org
4+
https://wordpress.org
5+
https://www.brid.gy
6+
https://ifttt.com
7+
https://www.flickr.com
8+
http://instagram.com
9+
https://indieauth.com
10+
http://www.wired.com
11+
http://davidmead.withknown.com
12+
https://twitter.com
13+
http://ind.ie
14+
https://ind.ie
15+
http://nourel.net
16+
http://bit.ly

generated/.keep

Whitespace-only changes.

lib/dom.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const cheerio = require('cheerio');
2+
3+
function main(html) {
4+
const base = cheerio.load(html.toString());
5+
6+
// FIXME: this doesn't handle multiple entries
7+
let $ = base('.h-entry');
8+
9+
if ($.length === 0) {
10+
$ = base;
11+
} else {
12+
$ = $.find.bind($);
13+
}
14+
15+
return $;
16+
}
17+
18+
module.exports = main;

lib/generate-data.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const readFileSync = require('fs').readFileSync;
2+
const writeFileSync = require('fs').writeFileSync;
3+
4+
function parse(type) {
5+
const data = readFileSync(__dirname + `/../data/${type}-hosts`, 'utf8');
6+
return data
7+
.split('\n')
8+
.filter(Boolean)
9+
.map(_ => {
10+
const [source, endpoint = null] = _.split(' ').filter(Boolean);
11+
return { source, endpoint };
12+
});
13+
}
14+
15+
const hosts = []
16+
.concat(parse('known'), parse('unknown'), parse('bad'))
17+
.reduce(
18+
(acc, curr) => Object.assign(acc, { [curr.source]: curr.endpoint }),
19+
{}
20+
);
21+
22+
writeFileSync(
23+
__dirname + '/../generated/hosts.json',
24+
JSON.stringify(hosts),
25+
'utf8'
26+
);

lib/get-links-from-url.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const html = require('../lib/html');
2+
const dom = require('../lib/dom');
3+
const links = require('../lib/links');
4+
const getEndpoints = require('./get-wm-endpoints');
5+
const parse = require('url').parse;
6+
7+
async function main(url) {
8+
const host = parse(url).hostname;
9+
10+
const ignoreOwn = url => {
11+
if (url.includes(`/${host}/`) || url.endsWith(`/${host}`)) {
12+
return false;
13+
}
14+
15+
return true;
16+
};
17+
18+
const urls = links(dom(await html(url))).filter(ignoreOwn);
19+
const endpoints = await getEndpoints(urls);
20+
21+
// this is a bit confusing…maybe refactor?
22+
return endpoints.map(({ url: target, endpoint }) => {
23+
return {
24+
endpoint,
25+
source: url,
26+
target,
27+
};
28+
});
29+
}
30+
31+
module.exports = main;

0 commit comments

Comments
 (0)