Detect orphan pages and calculate PageRank-style link equity in TypeScript

1 week ago 17
ARTICLE AD BOX

I'm building an SEO audit tool where I need to analyze the internal link structure of a website. I have three specific problems:

I need to find orphan pages — pages that no other page links to, making them invisible to crawlers

I want to calculate link equity scores (PageRank-style) to understand which pages accumulate the most authority

I need contextual link suggestions based on topic overlap between pages that aren't currently linking to each other

What I've tried:

// Manual orphan detection — O(n²) and hard to maintain

const allLinks = pages.flatMap(p => p.links);

const orphans = pages.filter(p => !allLinks.includes(p.url));

// No link equity scoring, no suggestions, no graph structure

Problems with this approach:

URL normalization issues — trailing slashes cause missed matches

No inbound/outbound link counts per page

No way to calculate relative link authority across the site

No topic-based link suggestions

What I need:

// Build directed link graph const graph = buildLinkGraph([ { url: 'https://example.com/', links: ['https://example.com/blog', 'https://example.com/about'] }, { url: 'https://example.com/blog', links: ['https://example.com/'] }, { url: 'https://example.com/about', links: ['https://example.com/'] }, { url: 'https://example.com/orphan', links: [] }, ]); // Find orphan pages const orphans = findOrphanPages(graph); // [{ url: 'https://example.com/orphan', outboundCount: 0 }] // Inspect graph nodes const blogNode = graph.nodes.get('https://example.com/blog'); console.log(blogNode.inboundCount); // 1 console.log(blogNode.outboundCount); // 1 // PageRank-style equity scores const equity = analyzeLinkEquity(graph, { damping: 0.85, iterations: 20 }); // [ // { url: 'https://example.com/', score: 0.48, inboundCount: 2 }, // { url: 'https://example.com/blog', score: 0.18, inboundCount: 1 }, // ] // Keyword-overlap link suggestions const suggestions = suggestLinks([ { url: '/guide/react-seo', title: 'React SEO Guide', content: '...' }, { url: '/guide/meta-tags', title: 'HTML Meta Tags Explained', content: '...' }, ], { minRelevance: 0.15, maxSuggestions: 3 });
Read Entire Article