Skip to content

Commit 29fd7ab

Browse files
committed
WIP
1 parent c3c85fc commit 29fd7ab

File tree

5 files changed

+69
-15
lines changed

5 files changed

+69
-15
lines changed

.github/workflows/main.yml

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: CI
2-
on: [push, pull_request]
2+
on: [ push ]
33
env:
44
RUST_BACKTRACE: 1
55
jobs:
@@ -12,8 +12,7 @@ jobs:
1212
with:
1313
components: rustfmt
1414

15-
- name: Formatting
16-
run: cargo fmt --all -- --check
15+
- uses: Swatinem/rust-cache@v2
1716

1817
- name: Test
1918
run: |
@@ -22,3 +21,33 @@ jobs:
2221
cargo build --all --locked
2322
cargo clippy -- --deny warnings
2423
cargo test --all --locked
24+
25+
- name: Formatting
26+
run: cargo fmt --all -- --check
27+
28+
- name: Build website
29+
run: cargo run
30+
env:
31+
BASE_URL: "/www.rust-lang.org/"
32+
33+
- name: Configure GitHub Pages
34+
uses: actions/configure-pages@v5
35+
36+
- name: Upload website
37+
uses: actions/upload-pages-artifact@v3
38+
with:
39+
path: html
40+
41+
deploy:
42+
needs: [ build ]
43+
environment:
44+
name: github-pages
45+
url: ${{ steps.deployment.outputs.page_url }}
46+
permissions:
47+
contents: read
48+
pages: write
49+
id-token: write
50+
runs-on: ubuntu-latest
51+
steps:
52+
- name: Deploy to GitHub Pages
53+
uses: actions/deploy-pages@v4

src/assets.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn compile_sass(root_dir: &Path, out_dir: &Path, filename: &str) -> anyhow::Resu
4141
write_file(&out_css_path, &css.into_bytes())
4242
.with_context(|| anyhow::anyhow!("couldn't write css file: {}", out_css_path.display()))?;
4343

44-
Ok(relative_url(&out_css_path, &out_dir)?)
44+
relative_url(&out_css_path, out_dir)
4545
}
4646

4747
fn concat_files(
@@ -71,7 +71,7 @@ fn concat_files(
7171
write_file(Path::new(&out_file_path), concatted.as_bytes())
7272
.with_context(|| anyhow::anyhow!("couldn't write vendor {extension}"))?;
7373

74-
Ok(relative_url(&out_file_path, &out_dir)?)
74+
relative_url(&out_file_path, out_dir)
7575
}
7676

7777
fn concat_vendor_css(root_dir: &Path, out_dir: &Path, files: Vec<&str>) -> anyhow::Result<String> {

src/i18n.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use handlebars::{
55
use serde::Serialize;
66
use std::{collections::HashSet, sync::LazyLock};
77

8+
use crate::ENGLISH;
89
use handlebars_fluent::{
910
fluent_bundle::{FluentResource, FluentValue, concurrent::FluentBundle},
1011
loader::SimpleLoader,
@@ -215,7 +216,7 @@ impl HelperDef for TeamHelper {
215216
let team_name = team.as_json()["name"].as_str().unwrap();
216217

217218
// English uses the team data directly, so that it gets autoupdated
218-
if lang == "en-US" {
219+
if lang == ENGLISH {
219220
let english = param.english(team.as_json());
220221
out.write(english)
221222
.map_err(|e| RenderErrorReason::NestedError(Box::new(e)))?;

src/main.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
#![allow(unused)]
2+
13
use crate::assets::compile_assets;
24
use crate::i18n::{TeamHelper, create_loader};
35
use crate::redirect::create_redirects;
46
use crate::render::{RenderCtx, render_directory, render_governance, render_index};
5-
use crate::rust_version::RustVersion;
7+
use crate::rust_version::fetch_rust_version;
68
use crate::teams::{encode_zulip_stream, load_rust_teams};
79
use anyhow::Context;
810
use handlebars::{DirectorySourceOptions, Handlebars};
@@ -24,11 +26,28 @@ const ZULIP_DOMAIN: &str = "https://rust-lang.zulipchat.com";
2426
static LAYOUT: &str = "components/layout";
2527
static 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]
5473
async 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(

src/render.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::fs::{copy_dir_all, ensure_directory};
33
use crate::i18n::{EXPLICIT_LOCALE_INFO, LocaleInfo, SUPPORTED_LOCALES};
44
use crate::rust_version::RustVersion;
55
use crate::teams::{PageData, RustTeams};
6-
use crate::{ENGLISH, LAYOUT, PONTOON_ENABLED, baseurl};
6+
use crate::{BaseUrl, ENGLISH, LAYOUT, PONTOON_ENABLED};
77
use anyhow::Context;
88
use handlebars::Handlebars;
99
use handlebars_fluent::{Loader, SimpleLoader};
@@ -72,6 +72,7 @@ pub struct RenderCtx<'a> {
7272
pub rust_version: RustVersion,
7373
pub teams: RustTeams,
7474
pub assets: AssetFiles,
75+
pub base_url: BaseUrl,
7576
}
7677

7778
impl<'a> RenderCtx<'a> {
@@ -95,8 +96,8 @@ impl<'a> RenderCtx<'a> {
9596
parent: LAYOUT,
9697
is_landing: false,
9798
data,
98-
baseurl: baseurl(&lang),
99-
is_translation: lang != "en-US",
99+
baseurl: self.base_url.resolve(lang),
100+
is_translation: lang != ENGLISH,
100101
lang: lang.to_string(),
101102
pontoon_enabled: PONTOON_ENABLED,
102103
assets: &self.assets,

0 commit comments

Comments
 (0)