26 lines
		
	
	
		
			625 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			26 lines
		
	
	
		
			625 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 [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 }; |