Skip to content

Commit

Permalink
fix(website): 🐛 fixed absolute path links in website
Browse files Browse the repository at this point in the history
Namely the docs toc and the version picker.
  • Loading branch information
arctic-hen7 committed Oct 7, 2021
1 parent caa67a6 commit 221fa24
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion website/website/src/templates/docs/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ fn docs_version_switcher(props: DocsVersionSwitcherProps) -> SycamoreTemplate<G>
let target: web_sys::HtmlInputElement = event.target().unwrap().unchecked_into();
let new_version = target.value();
// This isn't a reactive scope, so we can't use `link!` here
let link = format!("/{}/docs/{}/intro", *locale_2.get(), new_version);
// The base path will be included by HTML automatically
let link = format!("{}/docs/{}/intro", *locale_2.get(), new_version);
navigate(&link);
}
) {
Expand Down
6 changes: 3 additions & 3 deletions website/website/src/templates/docs/generation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::templates::docs::icons::{ERROR_ICON, WARNING_ICON};
use crate::templates::docs::template::DocsPageProps;
use lazy_static::lazy_static;
use perseus::{link, t, RenderFnResult, RenderFnResultWithCause};
use perseus::{link, t, RenderFnResult, RenderFnResultWithCause, path_prefix::get_path_prefix_server};
use pulldown_cmark::{html, Options, Parser};
use serde::{Deserialize, Serialize};
use std::fs;
Expand Down Expand Up @@ -220,10 +220,10 @@ pub async fn get_build_state(path: String, locale: String) -> RenderFnResultWith
// Get the sidebar from `SUMMARY.md`
let sidebar_fs_path = format!("../../../docs/{}/{}/SUMMARY.md", &version, &locale);
let sidebar_contents = fs::read_to_string(&sidebar_fs_path)?;
// Replace all links in that file with localized equivalents with versions as well
// Replace all links in that file with localized equivalents with versions as well (with the base path added)
// That means unversioned paths will redirect to the appropriate stable version
let sidebar_contents =
sidebar_contents.replace("/docs", &format!("/{}/docs/{}", &locale, &version));
sidebar_contents.replace("/docs", &format!("{}/{}/docs/{}", get_path_prefix_server(), &locale, &version));
let sidebar_html_contents = parse_md_to_html(&sidebar_contents);

// Work out the status of this page
Expand Down

0 comments on commit 221fa24

Please sign in to comment.