Skip to content

Commit 8982649

Browse files
committed
Add uwu support with image rendering
1 parent 93d89c5 commit 8982649

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

src/main.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,34 @@ fn robots_txt() -> Option<content::RawText<&'static str>> {
154154
}
155155
}
156156

157-
#[get("/")]
158-
async fn index(version_cache: &Cache<RustVersion>) -> Template {
159-
render_index(ENGLISH.into(), version_cache).await
157+
#[get("/?<uwu>")]
158+
async fn index(
159+
uwu: Option<bool>,
160+
version_cache: &Cache<RustVersion>,
161+
) -> Template {
162+
let is_uwu = uwu.unwrap_or(false);
163+
render_index_with_uwu(ENGLISH.into(), version_cache, is_uwu).await
164+
}
165+
166+
async fn render_index_with_uwu(
167+
lang: String,
168+
version_cache: &Cache<RustVersion>,
169+
is_uwu: bool,
170+
) -> Template {
171+
#[derive(Serialize)]
172+
struct IndexData {
173+
rust_version: String,
174+
uwu: bool,
175+
}
176+
177+
let data = IndexData {
178+
rust_version: rust_version::rust_version(version_cache).await,
179+
uwu: is_uwu,
180+
};
181+
182+
let page = "index";
183+
let context = Context::new(page, "", true, data, lang);
184+
Template::render(page, context)
160185
}
161186

162187
#[get("/<locale>", rank = 3)]

static/images/rust-uwu.png

130 KB
Loading

templates/index.html.hbs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
<header class="mt3 mb6 w-100 mw-none ph3 mw8-m mw9-l center">
33
<div class="flex flex-column flex-row-l">
44
<div class="w-70-l mw8-l">
5-
<h1>{{fluent "rust"}}</h1>
5+
{{#if data.uwu}}
6+
<img src="/static/images/rust-uwu.png" height="200" alt="Rust uwu image" />
7+
{{else}}
8+
<h1>{{fluent "rust"}}</h1>
9+
{{/if}}
610
<h2 class="mt4 mb0 f2 f1-ns">
711
{{fluent "tagline" linebreak="<br class='dn db-ns'>"}}
8-
</h2>
12+
</h2>{{!-- --}}
913
</div>
1014
<div class="w-30-l flex-column pl0-l pr0-l pl3 pr3">
1115
<a class="button button-download ph4 mt0 w-100" href="{{baseurl}}/learn/get-started">

0 commit comments

Comments
 (0)