docsy icon indicating copy to clipboard operation
docsy copied to clipboard

Improve version_menu_pagelinks feature to avoid 404s

Open chalin opened this issue 2 years ago • 1 comments

For context, see:

  • #1054

Linking to pages that exist between versions is the easy part. Avoiding 404s is essential for most projects I work with.

chalin avatar Aug 09 '22 19:08 chalin

To be honest, I can't think of a way to detect 404s with Hugo, because the different versions of the docs are often separate Hugo sites, so often its not possible to check the existence of the link within the site, because they are just external links. That leads to using some tool or script external to Hugo that scrapes the built html files and checks whether the canonical links point to a valid url (here again, define valid: must it be status 200, or do you accept 301 as well, how do you handle password-protected sites, and so on).

So I'd say that validating these links is outside the scope of Hugo/Docsy. One improvement I can think of would be to add an optional parameter to the frontmatter of the page to override the canonical url manually. That way, if you have two versions of a page (say, v1/oldpage and v2/newpage), you can add the something like this to the v1/oldpage frontmatter:

override-canonical-url: "v2/newpage" 

fekete-robert avatar Aug 10 '22 08:08 fekete-robert