Skip to content

Commit

Permalink
feat(spas): default values for SPAs
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Nov 27, 2024
1 parent 1790afa commit 1ef6e16
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 29 deletions.
10 changes: 8 additions & 2 deletions crates/rari-doc/src/cached_readers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ pub fn wiki_histories() -> Cow<'static, WikiHistories> {
}
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct BasicSPA {
pub only_follow: bool,
Expand All @@ -757,7 +757,13 @@ pub enum SPAData {
BasicSPA(BasicSPA),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
impl Default for SPAData {
fn default() -> Self {
Self::BasicSPA(BasicSPA::default())
}
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct BuildSPA {
pub slug: Cow<'static, str>,
Expand Down
40 changes: 13 additions & 27 deletions crates/rari-doc/src/pages/types/spa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,6 @@ impl PageLike for SPA {
}
}

const DEFAULT_BASIC_SPA: BuildSPA = BuildSPA {
slug: Cow::Borrowed(""),
page_title: Cow::Borrowed(""),
page_description: None,
trailing_slash: false,
en_us_only: false,
data: SPAData::BasicSPA(BasicSPA {
only_follow: false,
no_indexing: false,
}),
};

const MDN_PLUS_TITLE: &str = "MDN Plus";
const OBSERVATORY_TITLE_FULL: &str = "HTTP Observatory | MDN";

Expand All @@ -275,40 +263,38 @@ static BASIC_SPAS: LazyLock<HashMap<String, BuildSPA>> = LazyLock::new(|| {
BuildSPA {
slug: Cow::Borrowed(""),
page_title: Cow::Borrowed("MDN Web Docs"),
page_description: None,
trailing_slash: true,
data: SPAData::HomePage,
..DEFAULT_BASIC_SPA
..Default::default()
},
),
(
"404",
BuildSPA {
slug: Cow::Borrowed("404"),
page_title: Cow::Borrowed("404"),
page_description: None,
trailing_slash: false,
en_us_only: true,
data: SPAData::NotFound,
..Default::default()
},
),
(
"blog",
BuildSPA {
slug: Cow::Borrowed("blog"),
page_title: Cow::Borrowed("MDN Blog"),
page_description: None,
trailing_slash: true,
en_us_only: true,
data: SPAData::BlogIndex,
..Default::default()
},
),
(
"play",
BuildSPA {
slug: Cow::Borrowed("play"),
page_title: Cow::Borrowed("Playground | MDN"),
..DEFAULT_BASIC_SPA
..Default::default()
},
),
(
Expand All @@ -320,7 +306,7 @@ static BASIC_SPAS: LazyLock<HashMap<String, BuildSPA>> = LazyLock::new(|| {
OBSERVATORY_TITLE_FULL
)),
page_description: Some(Cow::Borrowed(OBSERVATORY_DESCRIPTION)),
..DEFAULT_BASIC_SPA
..Default::default()
},
),
(
Expand All @@ -336,7 +322,7 @@ static BASIC_SPAS: LazyLock<HashMap<String, BuildSPA>> = LazyLock::new(|| {
no_indexing: true,
only_follow: false,
}),
..DEFAULT_BASIC_SPA
..Default::default()
},
),
(
Expand All @@ -348,15 +334,15 @@ static BASIC_SPAS: LazyLock<HashMap<String, BuildSPA>> = LazyLock::new(|| {
only_follow: true,
no_indexing: false,
}),
..DEFAULT_BASIC_SPA
..Default::default()
},
),
(
"plus/ai-help",
BuildSPA {
slug: Cow::Borrowed("plus/ai-help"),
page_title: Cow::Borrowed(concat!("AI Help | ", MDN_PLUS_TITLE)),
..DEFAULT_BASIC_SPA
..Default::default()
},
),
(
Expand All @@ -368,7 +354,7 @@ static BASIC_SPAS: LazyLock<HashMap<String, BuildSPA>> = LazyLock::new(|| {
no_indexing: true,
only_follow: false,
}),
..DEFAULT_BASIC_SPA
..Default::default()
},
),
(
Expand All @@ -383,15 +369,15 @@ static BASIC_SPAS: LazyLock<HashMap<String, BuildSPA>> = LazyLock::new(|| {
no_indexing: true,
only_follow: false,
}),
..DEFAULT_BASIC_SPA
..Default::default()
},
),
(
"plus/updates",
BuildSPA {
slug: Cow::Borrowed("plus/updates"),
page_title: Cow::Borrowed(concat!("Updates | ", MDN_PLUS_TITLE)),
..DEFAULT_BASIC_SPA
..Default::default()
},
),
(
Expand All @@ -403,15 +389,15 @@ static BASIC_SPAS: LazyLock<HashMap<String, BuildSPA>> = LazyLock::new(|| {
no_indexing: true,
only_follow: false,
}),
..DEFAULT_BASIC_SPA
..Default::default()
},
),
(
"newsletter",
BuildSPA {
slug: Cow::Borrowed("newsletter"),
page_title: Cow::Borrowed("Stay Informed with MDN"),
..DEFAULT_BASIC_SPA
..Default::default()
},
),
]
Expand Down

0 comments on commit 1ef6e16

Please sign in to comment.