2024-09-24 10:56:04 -04:00
|
|
|
const { JSDOM } = require("jsdom");
|
|
|
|
const graphology = require("graphology");
|
|
|
|
const { circular } = require('graphology-layout');
|
|
|
|
|
|
|
|
function graphFromList(allTheStuff) {
|
|
|
|
const graph = new graphology.Graph();
|
2024-10-05 12:01:19 -04:00
|
|
|
for (const {number, html} of allTheStuff) {
|
2024-10-05 17:38:48 -04:00
|
|
|
if (!graph.hasNode(number)) graph.addNode(number);
|
2024-09-24 10:56:04 -04:00
|
|
|
}
|
|
|
|
|
2024-10-05 12:01:19 -04:00
|
|
|
for (const {number, html} of allTheStuff) {
|
2024-09-24 10:56:04 -04:00
|
|
|
const { document } = (new JSDOM(html)).window;
|
|
|
|
const links = document.querySelectorAll('a');
|
|
|
|
links.forEach((link) => {
|
|
|
|
const referent = link.href.replace("/","");
|
2024-10-05 12:01:19 -04:00
|
|
|
graph.mergeEdge(number, referent);
|
2024-09-24 10:56:04 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
circular.assign(graph);
|
|
|
|
|
|
|
|
return graph;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { graphFromList: graphFromList };
|