You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
625 B
26 lines
625 B
const { JSDOM } = require("jsdom");
|
|
const graphology = require("graphology");
|
|
const { circular } = require('graphology-layout');
|
|
|
|
function graphFromList(allTheStuff) {
|
|
const graph = new graphology.Graph();
|
|
for (const {id, html} of allTheStuff) {
|
|
|
|
graph.addNode(id);
|
|
}
|
|
|
|
for (const {id, html} of allTheStuff) {
|
|
const { document } = (new JSDOM(html)).window;
|
|
const links = document.querySelectorAll('a');
|
|
links.forEach((link) => {
|
|
const referent = link.href.replace("/","");
|
|
graph.mergeEdge(id, referent);
|
|
});
|
|
}
|
|
|
|
circular.assign(graph);
|
|
|
|
return graph;
|
|
}
|
|
|
|
module.exports = { graphFromList: graphFromList }; |