Urgent.News

What's breaking now, across hundreds of outlets.

Tech

I wrote a script to stop my internal links from rotting

A site with 286 pages has a link problem. Every new page is an orphan until something points at it, and every redesigned URL silently breaks old links. I stopped doing this by hand a while ago. The problem with manual internal links I started by adding a "related reading" section to each page as I wrote it. That worked for the first twenty pages. By page eighty I was linking to the same six…

A website consisting of 286 pages faced an issue with broken internal links. New pages were initially orphans, and outdated URLs ceased to function when URLs were modified. To tackle this problem, a script was created. Initially, each page included a "related reading" section as it was being written. However, after page eighty, the same six popular articles were being linked repeatedly, and many older pages had no incoming connections.

The framework was straightforward: when crafting a new page, links could only point back to existing pages. Forward links were only added by editing older pages, which was not a desirable task. The script's functionality is as follows: it scans all content files, categorizes them by topic, and for each page, selects a few other pages within the same topic group.

It then inserts the related-reading links into the page during the build process. Since it only operates after all pages have been identified, it can establish both forward and backward links. Consequently, every page now has at least two incoming links, and no pages remain unlinked. Additionally, a verification process was implemented, which occurs after the build.

This process examines each generated page, extracts the internal hrefs, and confirms that each link is valid. This mechanism allowed the reporter to identify a previous error where the initial version was referencing the incorrect path segment, resulting in false positives. To prevent the script from feeling overly automated, minimal human input was retained.

Each topic group received a predefined label, and the links were rendered as concise "read next" statements instead of an extensive list of options. The result appeared purposeful to readers, while the maintenance tasks remained automated. Whenever a new page is added, the entire network is automatically updated. The script runs before deployment, providing three metrics: total pages, orphaned pages, and broken internal links.

If either of the last two numbers is not zero, the deployment is halted. This process takes just a second and has detected more issues than any manual review. For those managing a growing static site, it is recommended to consider internal links as generated data with an integrated validation step rather than static content.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

Sanity client misconfigured in Next.js? apiVersion, useCdn and perspective fixes

If you inherited a Next.js site and the Sanity content is stale, leaking drafts, or oddly expensive to fetch, look at the Sanity client configuration before you touch anything else.

  • apiVersion misconfiguration leads to stale content
  • Incorrect useCdn setting causes high request counts
  • Wrong perspective setting results in duplicate entries

Super Script Runner v1.1.2 — Clean, Ad-Free Userscript Manager (Native MV3)

Hey everyone! Quick update on Super Script Runner — a lightweight, ad-free userscript manager I built as a clean alternative to bloated tools like Ace Script.

  • Super Script Runner v1.1.2 released with ad-free, lightweight userscript manager
  • Chrome's native userScripts API enhances performance and security
  • Version 1.1.2 maintains essential features while removing background updates

WhatsApp Under Attack? CERT-In Flags High-Risk Flaws — Update Now

WhatsApp Under Attack? CERT-In Flags High-Risk Flaws — Update Now WhatsApp is the app nobody thinks about until it breaks.

  • Five high-risk vulnerabilities found in WhatsApp and WhatsApp Business
  • Flaws could enable attackers to execute code, steal data, bypass security
  • Meta released patches after discovery by external researchers and Bug Bounty

More from Sunday, 29 November 2026 →