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,24 @@ 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 = url. strip_suffix ( '/' ) . unwrap_or ( url) . to_string ( ) ;
38+ Self { url }
39+ }
40+
41+ fn resolve ( & self , lang : & str ) -> String {
42+ if lang == ENGLISH {
43+ self . url . clone ( )
44+ } else {
45+ format ! ( "{}/{lang}" , self . url)
46+ }
3247 }
3348}
3449
@@ -52,6 +67,9 @@ fn setup_handlebars() -> anyhow::Result<Handlebars<'static>> {
5267
5368#[ tokio:: main]
5469async fn main ( ) -> anyhow:: Result < ( ) > {
70+ let base_url = std:: env:: var ( "BASE_URL" ) . unwrap_or_else ( |_| "" . to_string ( ) ) ;
71+ let base_url = BaseUrl :: new ( & base_url) ;
72+
5573 let rust_version = fetch_rust_version ( ) . await ?;
5674 let teams = load_rust_teams ( ) . await ?;
5775
@@ -72,6 +90,7 @@ async fn main() -> anyhow::Result<()> {
7290 teams,
7391 handlebars,
7492 output_dir,
93+ base_url,
7594 } ;
7695 ctx. copy_asset_dir ( "static" , "static" ) ?;
7796 ctx. copy_asset_file (
0 commit comments