framework icon indicating copy to clipboard operation
framework copied to clipboard

Generate link rel=canonical

Open Fil opened this issue 2 years ago • 1 comments

With the host and origin options provided (#180, #42), we can derive the page’s canonical URL (which is a good thing to have on static websites that might be served under different circumstances). Maybe a good idea in that case to automatically add the corresponding link[rel=canonical].

To determine this URL we also need to know the page’s path; this can be done if head is a function that receives the path as an argument (see #1161).

Fil avatar Nov 15 '23 16:11 Fil

Can you add more detail to the issue description, please? What does this mean? You can already add

<link rel="canonical" href="https://example.com/whatever/">

to any page.

I see three things possible interpretations here:

  1. Adding generic tags to the config.ts that are automatically added to every rendered page; VitePress does this with the head option; but if the value of the href value needs to vary for every page, then this won’t work
  2. Adding generic tags to the YAML front matter; VitePress does this with the head option (see Plot for example); but I don’t really see how this is preferable to just adding the link element to the page directly, as it’s just nonstandard equivalent to HTML
  3. Adding link rel=canonical tags specifically, dependent on providing a host in conjunction with base; VitePress uses sitemap.hostname for a sitemap, but they don’t automatically generate a link rel=canonical for every page

And an alternative or complement to (1) would be a more generic templating system.

mbostock avatar Nov 15 '23 18:11 mbostock