// assuming I've imported marked.js and psl
let linksByDomain = {};
markedJsRenderer.link = (href, title, text) => {
// Capture any relative links and note them as coming
// from my blog. Otherwise parse the link and get the hostname
let hostname;
if (href.startsWith(".") || href.startsWith("/")) {
hostname = "blog.jim-nielsen.com";
} else {
hostname = new URL(href).hostname;
}
// Turn the hostname into just the domain for even
// better grouping then add it to our collection of links.
let domain = psl.get(hostname);
if (linksByDomain[domain]) {
linksByDomain[domain].push(href);
} else {
linksByDomain[domain] = [href];
}
// Other code here
};
{
"github.com": [
"https://github.com/username/link/to/something",
"https://gist.github.com/another/link",
// more links here
],
"twitter.com": [
"https://twitter.com/username/019237029381",
"https://twitter.com/username/192370293812",
// more links here
],
"mozilla.org": [
"https://developer.mozilla.org/reference/article",
"https://developer.mozilla.org/docs/link",
// more links here
]
}