Skip to content

Commit a036598

Browse files
jshasyphar
authored andcommitted
Add canonical URL for source pages
1 parent 471e4f0 commit a036598

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/web/source.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ struct SourcePage {
165165
show_parent_link: bool,
166166
file_content: Option<String>,
167167
is_rust_source: bool,
168+
canonical_url: String,
168169
}
169170

170171
impl_webpage! {
@@ -232,6 +233,11 @@ pub fn source_browser_handler(req: &mut Request) -> IronResult<Response> {
232233
(path, file_path)
233234
};
234235

236+
let canonical_url = format!(
237+
"https://docs.rs/crate/{}/latest/source/{}",
238+
crate_name, file_path
239+
);
240+
235241
let storage = extension!(req, Storage);
236242
let archive_storage: bool = {
237243
let rows = ctry!(
@@ -295,6 +301,7 @@ pub fn source_browser_handler(req: &mut Request) -> IronResult<Response> {
295301
show_parent_link: !req_path.is_empty(),
296302
file_content,
297303
is_rust_source,
304+
canonical_url,
298305
}
299306
.into_response(req)
300307
}

templates/crate/source.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
{{ macros::doc_title(name=file_list.metadata.name, version=file_list.metadata.version) }}
66
{%- endblock title -%}
77

8+
{%- block meta -%}
9+
<link rel="canonical" href="{{ canonical_url | safe }}" />
10+
{%- endblock -%}
11+
812
{%- block topbar -%}
913
{%- set metadata = file_list.metadata -%}
1014
{%- set latest_version = "" -%}

0 commit comments

Comments
 (0)