Skip to content

Commit 63d7508

Browse files
jshajyn514
authored andcommitted
Fix latest_path vs permalink_path
1 parent 5ca7f46 commit 63d7508

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

src/web/rustdoc.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
195195
#[derive(Debug, Clone, PartialEq, Serialize)]
196196
struct RustdocPage {
197197
latest_path: String,
198+
permalink_path: String,
198199
latest_version: String,
199200
target: String,
200201
inner_path: String,
@@ -474,11 +475,13 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
474475
"".to_string()
475476
};
476477

477-
let latest_path = format!(
478+
let permalink_path = format!(
478479
"/crate/{}/{}{}{}",
479480
name, latest_version, target_redirect, query_string
480481
);
481482

483+
let latest_path = format!("/crate/{}/latest{}{}", name, target_redirect, query_string);
484+
482485
metrics
483486
.recently_accessed_releases
484487
.record(krate.crate_id, krate.release_id, target);
@@ -492,6 +495,7 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
492495
rendering_time.step("rewrite html");
493496
RustdocPage {
494497
latest_path,
498+
permalink_path,
495499
latest_version,
496500
target,
497501
inner_path,
@@ -861,25 +865,25 @@ mod test {
861865
let redirect = latest_version_redirect("/dummy/0.1.0/dummy/", web)?;
862866
assert_eq!(
863867
redirect,
864-
"/crate/dummy/0.2.0/target-redirect/x86_64-unknown-linux-gnu/dummy/index.html"
868+
"/crate/dummy/latest/target-redirect/x86_64-unknown-linux-gnu/dummy/index.html"
865869
);
866870

867871
// check it keeps the subpage
868872
let redirect = latest_version_redirect("/dummy/0.1.0/dummy/blah/", web)?;
869873
assert_eq!(
870874
redirect,
871-
"/crate/dummy/0.2.0/target-redirect/x86_64-unknown-linux-gnu/dummy/blah/index.html"
875+
"/crate/dummy/latest/target-redirect/x86_64-unknown-linux-gnu/dummy/blah/index.html"
872876
);
873877
let redirect = latest_version_redirect("/dummy/0.1.0/dummy/blah/blah.html", web)?;
874878
assert_eq!(
875879
redirect,
876-
"/crate/dummy/0.2.0/target-redirect/x86_64-unknown-linux-gnu/dummy/blah/blah.html"
880+
"/crate/dummy/latest/target-redirect/x86_64-unknown-linux-gnu/dummy/blah/blah.html"
877881
);
878882

879883
// check it also works for deleted pages
880884
let redirect =
881885
latest_version_redirect("/dummy/0.1.0/dummy/struct.will-be-deleted.html", web)?;
882-
assert_eq!(redirect, "/crate/dummy/0.2.0/target-redirect/x86_64-unknown-linux-gnu/dummy/struct.will-be-deleted.html");
886+
assert_eq!(redirect, "/crate/dummy/latest/target-redirect/x86_64-unknown-linux-gnu/dummy/struct.will-be-deleted.html");
883887

884888
Ok(())
885889
})
@@ -909,14 +913,14 @@ mod test {
909913
latest_version_redirect("/dummy/0.1.0/x86_64-pc-windows-msvc/dummy", web)?;
910914
assert_eq!(
911915
redirect,
912-
"/crate/dummy/0.2.0/target-redirect/x86_64-pc-windows-msvc/dummy/index.html"
916+
"/crate/dummy/latest/target-redirect/x86_64-pc-windows-msvc/dummy/index.html"
913917
);
914918

915919
let redirect =
916920
latest_version_redirect("/dummy/0.1.0/x86_64-pc-windows-msvc/dummy/", web)?;
917921
assert_eq!(
918922
redirect,
919-
"/crate/dummy/0.2.0/target-redirect/x86_64-pc-windows-msvc/dummy/index.html"
923+
"/crate/dummy/latest/target-redirect/x86_64-pc-windows-msvc/dummy/index.html"
920924
);
921925

922926
let redirect = latest_version_redirect(
@@ -925,7 +929,7 @@ mod test {
925929
)?;
926930
assert_eq!(
927931
redirect,
928-
"/crate/dummy/0.2.0/target-redirect/x86_64-pc-windows-msvc/dummy/struct.Blah.html"
932+
"/crate/dummy/latest/target-redirect/x86_64-pc-windows-msvc/dummy/struct.Blah.html"
929933
);
930934

931935
Ok(())
@@ -951,7 +955,7 @@ mod test {
951955

952956
let web = env.frontend();
953957
let redirect = latest_version_redirect("/dummy/0.1.0/dummy/", web)?;
954-
assert_eq!(redirect, "/crate/dummy/0.2.0");
958+
assert_eq!(redirect, "/crate/dummy/latest");
955959

956960
Ok(())
957961
})
@@ -985,13 +989,13 @@ mod test {
985989
let redirect = latest_version_redirect("/dummy/0.1.0/dummy/", web)?;
986990
assert_eq!(
987991
redirect,
988-
"/crate/dummy/0.2.0/target-redirect/x86_64-unknown-linux-gnu/dummy/index.html"
992+
"/crate/dummy/latest/target-redirect/x86_64-unknown-linux-gnu/dummy/index.html"
989993
);
990994

991995
let redirect = latest_version_redirect("/dummy/0.2.1/dummy/", web)?;
992996
assert_eq!(
993997
redirect,
994-
"/crate/dummy/0.2.0/target-redirect/x86_64-unknown-linux-gnu/dummy/index.html"
998+
"/crate/dummy/latest/target-redirect/x86_64-unknown-linux-gnu/dummy/index.html"
995999
);
9961000

9971001
Ok(())
@@ -1028,13 +1032,13 @@ mod test {
10281032
let redirect = latest_version_redirect("/dummy/0.1.0/dummy/", web)?;
10291033
assert_eq!(
10301034
redirect,
1031-
"/crate/dummy/0.2.1/target-redirect/x86_64-unknown-linux-gnu/dummy/index.html"
1035+
"/crate/dummy/latest/target-redirect/x86_64-unknown-linux-gnu/dummy/index.html"
10321036
);
10331037

10341038
let redirect = latest_version_redirect("/dummy/0.2.0/dummy/", web)?;
10351039
assert_eq!(
10361040
redirect,
1037-
"/crate/dummy/0.2.1/target-redirect/x86_64-unknown-linux-gnu/dummy/index.html"
1041+
"/crate/dummy/latest/target-redirect/x86_64-unknown-linux-gnu/dummy/index.html"
10381042
);
10391043

10401044
Ok(())
@@ -1848,14 +1852,14 @@ mod test {
18481852
let target_redirect = "/crate/pyo3/0.13.2/target-redirect/x86_64-unknown-linux-gnu/src/pyo3/objects/exc.rs.html";
18491853
assert_eq!(
18501854
latest_version_redirect(
1851-
"/pyo3/0.2.7/src/pyo3/objects/exc.rs.html",
1855+
"/pyo3/latest/src/pyo3/objects/exc.rs.html",
18521856
env.frontend()
18531857
)?,
18541858
target_redirect
18551859
);
18561860
assert_redirect(
18571861
target_redirect,
1858-
"/pyo3/0.13.2/pyo3/?search=exc",
1862+
"/pyo3/latest/pyo3/?search=exc",
18591863
env.frontend(),
18601864
)?;
18611865
Ok(())

templates/rustdoc/topbar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
{%- if metadata.version_or_latest == "latest" -%}
2626
<li class="pure-menu-item">
27-
<a href="{{latest_path | safe}}" class="pure-menu-link description" title="Get a link to this specific version">
27+
<a href="{{permalink_path | safe}}" class="pure-menu-link description" title="Get a link to this specific version">
2828
{{ "link" | fas }} Permalink
2929
</a>
3030
</li>

0 commit comments

Comments
 (0)