Skip to content

Commit bb879c6

Browse files
committed
refactor(website): ♻️ refactored website to use new ergonomics macros
1 parent 57d6dc8 commit bb879c6

File tree

5 files changed

+47
-43
lines changed

5 files changed

+47
-43
lines changed

website/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "perseus-website"
3-
version = "0.3.0-beta.13"
3+
version = "0.3.0-beta.16"
44
edition = "2018"
55
description = "The official website for the Perseus framework."
66
authors = ["arctic_hen7 <[email protected]>"]
@@ -13,7 +13,7 @@ readme = "./README.md"
1313

1414
[dependencies]
1515
# We use the current version of Perseus, not the local one
16-
perseus = { version = "0.3.0-beta.15", features = [ "translator-fluent" ] }
16+
perseus = { version = "0.3.0-beta.16", features = [ "translator-fluent" ] }
1717
sycamore = "0.6"
1818
sycamore-router = "0.6"
1919
serde = "1"

website/src/templates/comparisons.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ pub struct ComparisonsPageProps {
288288
/// The comparison data for Perseus itself.
289289
pub perseus_comparison: Comparison,
290290
}
291+
292+
#[perseus::template(ComparisonsPage)]
291293
#[component(ComparisonsPage<G>)]
292294
pub fn comparisons_page(props: ComparisonsPageProps) -> SycamoreTemplate<G> {
293295
let comparisons = props.comparisons.clone();
@@ -362,22 +364,25 @@ pub fn comparisons_page(props: ComparisonsPageProps) -> SycamoreTemplate<G> {
362364
}
363365
}
364366

367+
#[perseus::head]
368+
pub fn head() -> SycamoreTemplate<SsrNode> {
369+
template! {
370+
title { (format!("{} | {}", t!("comparisons-title"), t!("perseus"))) }
371+
}
372+
}
373+
365374
pub fn get_template<G: GenericNode>() -> Template<G> {
366375
Template::new("comparisons")
367-
.template(|props| {
368-
template! {
369-
ComparisonsPage(serde_json::from_str(&props.unwrap()).unwrap())
370-
}
371-
})
372-
.head(|_| {
373-
template! {
374-
title { (format!("{} | {}", t!("comparisons-title"), t!("perseus"))) }
375-
}
376-
})
376+
.template(comparisons_page)
377+
.head(head)
377378
.build_state_fn(get_build_state)
378379
}
379380

380-
pub async fn get_build_state(_path: String, _locale: String) -> RenderFnResultWithCause<String> {
381+
#[perseus::autoserde(build_state)]
382+
pub async fn get_build_state(
383+
_path: String,
384+
_locale: String,
385+
) -> RenderFnResultWithCause<ComparisonsPageProps> {
381386
// Get all the comparisons from JSON
382387
// This includes the special properties for Perseus itself
383388
let mut perseus_comparison: Option<Comparison> = None;
@@ -416,6 +421,5 @@ pub async fn get_build_state(_path: String, _locale: String) -> RenderFnResultWi
416421
})
417422
}
418423
};
419-
let props_str = serde_json::to_string(&props)?;
420-
Ok(props_str)
424+
Ok(props)
421425
}

website/src/templates/docs/generation.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ pub struct DocsManifest {
105105
pub history_map: HashMap<String, String>,
106106
}
107107

108-
pub async fn get_build_state(path: String, locale: String) -> RenderFnResultWithCause<String> {
108+
#[perseus::autoserde(build_state)]
109+
pub async fn get_build_state(
110+
path: String,
111+
locale: String,
112+
) -> RenderFnResultWithCause<DocsPageProps> {
109113
let path_vec: Vec<&str> = path.split('/').collect();
110114
// Localize the path again to what it'll be on the filesystem
111115
// TODO get Perseus to pass in props from build paths for ease of use?
@@ -281,8 +285,7 @@ pub async fn get_build_state(path: String, locale: String) -> RenderFnResultWith
281285
current_version: version.to_string(),
282286
};
283287

284-
let props_str = serde_json::to_string(&props)?;
285-
Ok(props_str)
288+
Ok(props)
286289
}
287290

288291
pub async fn get_build_paths() -> RenderFnResult<Vec<String>> {

website/src/templates/docs/template.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub struct DocsPageProps {
1818
pub current_version: String,
1919
}
2020

21+
#[perseus::template(DocsPage)]
2122
#[component(DocsPage<G>)]
2223
pub fn docs_page(props: DocsPageProps) -> SycamoreTemplate<G> {
2324
// These come pre-translated for the current locale
@@ -50,22 +51,20 @@ pub fn docs_page(props: DocsPageProps) -> SycamoreTemplate<G> {
5051
}
5152
}
5253

54+
#[perseus::head]
55+
pub fn head(props: DocsPageProps) -> SycamoreTemplate<SsrNode> {
56+
template! {
57+
title { (format!("{} | {}", props.title, t!("docs-title-base"))) }
58+
link(rel = "stylesheet", href = ".perseus/static/styles/markdown.css")
59+
link(rel = "stylesheet", href = ".perseus/static/styles/docs_links_markdown.css")
60+
link(rel = "stylesheet", href = ".perseus/static/prism.css")
61+
}
62+
}
63+
5364
pub fn get_template<G: GenericNode>() -> Template<G> {
5465
Template::new("docs")
5566
.build_paths_fn(get_build_paths)
5667
.build_state_fn(get_build_state)
57-
.template(|props| {
58-
template! {
59-
DocsPage(serde_json::from_str(&props.unwrap()).unwrap())
60-
}
61-
})
62-
.head(|props| {
63-
let props: DocsPageProps = serde_json::from_str(&props.unwrap()).unwrap();
64-
template! {
65-
title { (format!("{} | {}", props.title, t!("docs-title-base"))) }
66-
link(rel = "stylesheet", href = ".perseus/static/styles/markdown.css")
67-
link(rel = "stylesheet", href = ".perseus/static/styles/docs_links_markdown.css")
68-
link(rel = "stylesheet", href = ".perseus/static/prism.css")
69-
}
70-
})
68+
.template(docs_page)
69+
.head(head)
7170
}

website/src/templates/index.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use perseus::{link, t, GenericNode, Template};
55
use sycamore::prelude::Template as SycamoreTemplate;
66
use sycamore::prelude::*;
77

8+
#[perseus::template(IndexPage)]
89
#[component(IndexPage<G>)]
910
pub fn index_page() -> SycamoreTemplate<G> {
1011
template! {
@@ -128,16 +129,13 @@ pub fn index_page() -> SycamoreTemplate<G> {
128129
}
129130
}
130131

132+
#[perseus::head]
133+
pub fn head() -> SycamoreTemplate<SsrNode> {
134+
template! {
135+
title { (t!("perseus")) }
136+
}
137+
}
138+
131139
pub fn get_template<G: GenericNode>() -> Template<G> {
132-
Template::new("index")
133-
.template(|_| {
134-
template! {
135-
IndexPage()
136-
}
137-
})
138-
.head(|_| {
139-
template! {
140-
title { (t!("perseus")) }
141-
}
142-
})
140+
Template::new("index").template(index_page).head(head)
143141
}

0 commit comments

Comments
 (0)