Skip to content

Commit bb51db6

Browse files
committed
WIP
1 parent c3c85fc commit bb51db6

24 files changed

+129
-79
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: 26 additions & 7 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,24 @@ 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 = 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]
5469
async 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

@@ -61,7 +79,7 @@ async fn main() -> anyhow::Result<()> {
6179
std::fs::create_dir_all(&output_dir)?;
6280

6381
let root_dir = Path::new(".");
64-
let assets = compile_assets(root_dir, &output_dir, "/")?;
82+
let assets = compile_assets(root_dir, &output_dir, &base_url.resolve(ENGLISH))?;
6583
let handlebars = setup_handlebars()?;
6684

6785
let ctx = RenderCtx {
@@ -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(

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,

templates/404.html.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<h2 class="subtitle">{{fluent "error404-subtitle"}}</h2>
88
</div>
99
<div class="w-30-l w-100 mt5 mt0-l">
10-
<img id="ferris-error" src="/static/images/ferris-error.png" alt='{{fluent "error404-img-alt"}}'>
10+
<img id="ferris-error" src="{{baseurl}}/static/images/ferris-error.png" alt='{{fluent "error404-img-alt"}}'>
1111
</div>
1212
</div>
1313
</div>

templates/community/index.html.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
</ul>
171171
</div>
172172
</div>
173-
<img src="/static/images/rustfest.jpg" alt="{{fluent " community-rustfest-alt"}}">
173+
<img src="{{baseurl}}/static/images/rustfest.jpg" alt="{{fluent " community-rustfest-alt"}}">
174174
</div>
175175
</section>
176176

templates/components/footer.html.hbs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
<div class="flex flex-column mw8 w-100 measure-wide-l pv2 pv5-m pv2-ns ph4-m ph4-l">
3434
<h4>{{fluent "footer-social"}}</h4>
3535
<div class="flex flex-row flex-wrap items-center">
36-
<a rel="me" href="https://social.rust-lang.org/@rust" target="_blank"><img src="/static/images/mastodon.svg"
36+
<a rel="me" href="https://social.rust-lang.org/@rust" target="_blank"><img src="{{baseurl}}/static/images/mastodon.svg"
3737
alt="{{fluent "mastodon"}}" title="{{fluent "mastodon"}}" /></a>
3838
<a rel="me" href="https://bsky.app/profile/rust-lang.org" target="_blank"><img
39-
src="/static/images/bluesky.svg" alt="{{fluent "bluesky"}}" title="{{fluent "bluesky"}}" /></a>
39+
src="{{baseurl}}/static/images/bluesky.svg" alt="{{fluent "bluesky"}}" title="{{fluent "bluesky"}}" /></a>
4040
<a href="https://www.youtube.com/channel/UCaYhcUwRBNscFNUKTjgPFiA" target="_blank"><img class="pv2"
41-
src="/static/images/youtube.svg" alt="{{fluent "footer-alt-youtube"}}" title="YouTube" /></a>
42-
<a href="https://github.com/rust-lang" target="_blank"><img src="/static/images/github.svg" alt="github logo"
41+
src="{{baseurl}}/static/images/youtube.svg" alt="{{fluent "footer-alt-youtube"}}" title="YouTube" /></a>
42+
<a href="https://github.com/rust-lang" target="_blank"><img src="{{baseurl}}/static/images/github.svg" alt="github logo"
4343
title="{{fluent "footer-github-alt"}}" /></a>
4444
</div>
4545
</div>

templates/components/layout.html.hbs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@
2828
<meta property="og:locale" content="en_US" />
2929

3030
<!-- styles -->
31-
<link rel="stylesheet" href="/static/styles/a11y-dark.css"/>
31+
<link rel="stylesheet" href="{{baseurl}}/static/styles/a11y-dark.css"/>
3232
<link rel="stylesheet" href="{{assets.css.vendor}}"/>
3333
<link rel="stylesheet" href="{{assets.css.fonts}}"/>
3434
<link rel="stylesheet" href="{{assets.css.app}}"/>
3535

3636
<!-- favicon -->
37-
<link rel="apple-touch-icon" sizes="180x180" href="/static/images/apple-touch-icon.png?v=ngJW8jGAmR">
38-
<link rel="icon" sizes="16x16" type="image/png" href="/static/images/favicon-16x16.png">
39-
<link rel="icon" sizes="32x32" type="image/png" href="/static/images/favicon-32x32.png">
40-
<link rel="icon" type="image/svg+xml" href="/static/images/favicon.svg">
41-
<link rel="manifest" href="/static/images/site.webmanifest?v=ngJW8jGAmR">
42-
<link rel="mask-icon" href="/static/images/safari-pinned-tab.svg?v=ngJW8jGAmR" color="#000000">
37+
<link rel="apple-touch-icon" sizes="180x180" href="{{baseurl}}/static/images/apple-touch-icon.png?v=ngJW8jGAmR">
38+
<link rel="icon" sizes="16x16" type="image/png" href="{{baseurl}}/static/images/favicon-16x16.png">
39+
<link rel="icon" sizes="32x32" type="image/png" href="{{baseurl}}/static/images/favicon-32x32.png">
40+
<link rel="icon" type="image/svg+xml" href="{{baseurl}}/static/images/favicon.svg">
41+
<link rel="manifest" href="{{baseurl}}/static/images/site.webmanifest?v=ngJW8jGAmR">
42+
<link rel="mask-icon" href="{{baseurl}}/static/images/safari-pinned-tab.svg?v=ngJW8jGAmR" color="#000000">
4343
<meta name="msapplication-TileColor" content="#ffffff">
44-
<meta name="msapplication-config" content="/static/images/browserconfig.xml?v=ngJW8jGAmR">
44+
<meta name="msapplication-config" content="{{baseurl}}/static/images/browserconfig.xml?v=ngJW8jGAmR">
4545
<meta name="theme-color" content="#ffffff">
4646

4747
{{#if is_landing}}
@@ -54,8 +54,8 @@
5454

5555
<!-- Custom Highlight pack with: Rust, Markdown, TOML, Bash, JSON, YAML,
5656
and plaintext. -->
57-
<script src="/static/scripts/highlight.pack.js" defer></script>
58-
<script src="/static/scripts/init.js" defer></script>
57+
<script src="{{baseurl}}/static/scripts/highlight.pack.js" defer></script>
58+
<script src="{{baseurl}}/static/scripts/init.js" defer></script>
5959
</head>
6060
<body>
6161
{{> components/nav}}
@@ -66,6 +66,6 @@
6666
{{#if pontoon_enabled}}
6767
<script src="https://pontoon.rust-lang.org/pontoon.js"></script>
6868
{{/if}}
69-
<script src="/static/scripts/languages.js"></script>
69+
<script src="{{baseurl}}/static/scripts/languages.js"></script>
7070
</body>
7171
</html>

templates/components/nav.html.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<nav class="flex flex-row justify-center justify-end-l items-center flex-wrap ph2 pl3-ns pr3-ns pb3">
22
<div class="brand flex-auto w-100 w-auto-l self-start tc tl-l">
33
<a href="{{baseurl}}/" class="brand">
4-
<img class="v-mid ml0-l" alt="{{fluent "nav-logo-alt"}}" src="/static/images/rust-logo-blk.svg">
4+
<img class="v-mid ml0-l" alt="{{fluent "nav-logo-alt"}}" src="{{baseurl}}/static/images/rust-logo-blk.svg">
55
{{#unless is_landing}}
66
<span class="dib ml1 ml0-l">{{fluent "rust"}}</span>
77
{{/unless}}

0 commit comments

Comments
 (0)