1+ #![ allow( unused) ]
2+
13use crate :: assets:: compile_assets;
24use crate :: i18n:: { TeamHelper , create_loader} ;
35use crate :: redirect:: create_redirects;
46use crate :: render:: { RenderCtx , render_directory, render_governance, render_index} ;
5- use crate :: rust_version:: RustVersion ;
7+ use crate :: rust_version:: fetch_rust_version ;
68use crate :: teams:: { encode_zulip_stream, load_rust_teams} ;
79use anyhow:: Context ;
810use handlebars:: { DirectorySourceOptions , Handlebars } ;
@@ -24,11 +26,28 @@ const ZULIP_DOMAIN: &str = "https://rust-lang.zulipchat.com";
2426static LAYOUT : & str = "components/layout" ;
2527static ENGLISH : & str = "en-US" ;
2628
27- fn baseurl ( lang : & str ) -> String {
28- if lang == "en-US" {
29- String :: new ( )
30- } else {
31- format ! ( "/{lang}" )
29+ /// Relative base url from the root of the website
30+ /// `url` can be e.g. `/` or `/foo-bar/`.
31+ struct BaseUrl {
32+ url : String ,
33+ }
34+
35+ impl BaseUrl {
36+ fn new ( url : & str ) -> Self {
37+ let url = if url. ends_with ( "/" ) {
38+ url. to_string ( )
39+ } else {
40+ format ! ( "{url}/" )
41+ } ;
42+ Self { url }
43+ }
44+
45+ fn resolve ( & self , lang : & str ) -> String {
46+ if lang == ENGLISH {
47+ self . url . clone ( )
48+ } else {
49+ format ! ( "{}{lang}/" , self . url)
50+ }
3251 }
3352}
3453
@@ -52,6 +71,9 @@ fn setup_handlebars() -> anyhow::Result<Handlebars<'static>> {
5271
5372#[ tokio:: main]
5473async fn main ( ) -> anyhow:: Result < ( ) > {
74+ let base_url = std:: env:: var ( "BASE_URL" ) . unwrap_or_else ( |_| "/" . to_string ( ) ) ;
75+ let base_url = BaseUrl :: new ( & base_url) ;
76+
5577 let rust_version = fetch_rust_version ( ) . await ?;
5678 let teams = load_rust_teams ( ) . await ?;
5779
@@ -72,6 +94,7 @@ async fn main() -> anyhow::Result<()> {
7294 teams,
7395 handlebars,
7496 output_dir,
97+ base_url,
7598 } ;
7699 ctx. copy_asset_dir ( "static" , "static" ) ?;
77100 ctx. copy_asset_file (
0 commit comments