mdBook icon indicating copy to clipboard operation
mdBook copied to clipboard

Add `canonical-site-url` setting

Open roberth opened this issue 8 months ago • 10 comments

Hi :wave:

This implements the suggestion by markhildreth to implement such a setting, based on the conversation in https://github.com/rust-lang/mdBook/issues/1238. <link rel="canonical"> plays an important role in avoiding an SEO penalty when users deploy multiple versions of their site.

I've additionally infixed -site- to highlight the relationship with the site-url, and to distinguish it from the canonical URL as it occurs in a page.

This is a more user-friendly alternative to #2415 as it's an "end to end" solution with documentation. (It may have usages beyond this use case though)

Let me know if there's anything I should improve. When this is done, I'd like to implement a setting for opting in to clean URLs without the .html suffix so that we can close the whole issue.

Changelog suggestion (not included due to repeated conflicts...)

- Added [`canonical-site-url`](https://rust-lang.github.io/mdBook/format/configuration/renderers.html?highlight=canonical-site-url#html-renderer-options) setting, to set `<link rel="canonical">` in the HTML output of each page.

roberth avatar May 15 '25 13:05 roberth