25 lines
668 B
JavaScript
25 lines
668 B
JavaScript
const { JSDOM } = require("jsdom");
|
|
const graphology = require("graphology");
|
|
const { circular } = require('graphology-layout');
|
|
|
|
function graphFromList(allTheStuff) {
|
|
const graph = new graphology.Graph();
|
|
for (const {number, html} of allTheStuff) {
|
|
if (!graph.hasNode(number)) graph.addNode(number);
|
|
}
|
|
|
|
for (const {number, html} of allTheStuff) {
|
|
const { document } = (new JSDOM(html)).window;
|
|
const links = document.querySelectorAll('a');
|
|
links.forEach((link) => {
|
|
const referent = link.href.replace("/","");
|
|
graph.mergeEdge(number, referent);
|
|
});
|
|
}
|
|
|
|
circular.assign(graph);
|
|
|
|
return graph;
|
|
}
|
|
|
|
module.exports = { graphFromList: graphFromList }; |