Skip to content

Commit 642ab4f

Browse files
jshasyphar
authored andcommitted
Add canonical link for crate pages
1 parent 6208c4a commit 642ab4f

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/web/crate_details.rs

+18
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,24 @@ mod tests {
575575
});
576576
}
577577

578+
#[test]
579+
fn test_canonical_url() {
580+
wrapper(|env| {
581+
env.fake_release().name("foo").version("0.0.1").create()?;
582+
env.fake_release().name("foo").version("0.0.2").create()?;
583+
584+
let web = env.frontend();
585+
586+
assert!(web
587+
.get("/crate/foo/0.0.1")
588+
.send()?
589+
.text()?
590+
.contains("rel=\"canonical\" href=\"https://docs.rs/crate/foo/latest"));
591+
592+
Ok(())
593+
})
594+
}
595+
578596
#[test]
579597
fn test_latest_version() {
580598
wrapper(|env| {

templates/crate/details.html

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
{{ macros::doc_title(name=details.name, version=details.version) }}
66
{%- endblock title -%}
77

8+
{%- block meta -%}
9+
<link rel="canonical" href="https://docs.rs/crate/{{ details.name }}/latest" />
10+
{%- endblock meta -%}
11+
812
{%- block topbar -%}
913
{%- set metadata = details.metadata -%}
1014
{%- set latest_version = "" -%}

0 commit comments

Comments
 (0)