framework
framework copied to clipboard
Generate link rel=canonical
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).
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:
- 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
- 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
- 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.