Skip to content

Commit

Permalink
fix(homepage): use hyData
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Sep 16, 2024
1 parent fae9ba2 commit 2981fea
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
13 changes: 9 additions & 4 deletions crates/rari-doc/src/pages/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,17 +346,22 @@ where
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct JsonHomePageSPA {
pub slug: &'static str,
pub url: String,
pub page_title: &'static str,
pub struct JsonHomePageSPAHyData {
pub page_description: Option<&'static str>,
pub featured_articles: Vec<HomePageFeaturedArticle>,
pub featured_contributor: Option<HomePageFeaturedContributor>,
pub latest_news: ItemContainer<HomePageLatestNewsItem>,
pub recent_contributions: ItemContainer<HomePageRecentContribution>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct JsonHomePageSPA {
pub hy_data: JsonHomePageSPAHyData,
pub page_title: &'static str,
pub url: String,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct JsonGenericHyData {
Expand Down
47 changes: 24 additions & 23 deletions crates/rari-doc/src/pages/types/spa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::cached_readers::blog_files;
use crate::error::DocError;
use crate::pages::json::{
BlogIndex, BuiltDocy, HyData, ItemContainer, JsonBasicSPA, JsonBlogPost, JsonBlogPostDoc,
JsonHomePageSPA,
JsonHomePageSPA, JsonHomePageSPAHyData,
};
use crate::pages::page::{Page, PageLike, PageReader};
use crate::pages::title::page_title;
Expand Down Expand Up @@ -129,30 +129,31 @@ impl SPA {
url: strcat!(self.base_slug.as_ref() self.slug),
}))),
SPAData::HomePage => Ok(BuiltDocy::HomePageSPA(Box::new(JsonHomePageSPA {
slug: self.slug,
url: strcat!("/" self.locale().as_url_str() "/" self.slug),
page_title: self.page_title,
page_description: self.page_description,
featured_articles: featured_articles(
&[
"/en-US/blog/mdn-scrimba-partnership/",
"/en-US/blog/learn-javascript-console-methods/",
"/en-US/blog/introduction-to-web-sustainability/",
"/en-US/docs/Web/API/CSS_Custom_Highlight_API",
],
self.locale,
)?,
featured_contributor: featured_contributor(self.locale)?,
latest_news: ItemContainer {
items: lastet_news(&[
"/en-US/blog/mdn-scrimba-partnership/",
"/en-US/blog/mdn-http-observatory-launch/",
"/en-US/blog/mdn-curriculum-launch/",
"/en-US/blog/baseline-evolution-on-mdn/",
])?,
},
recent_contributions: ItemContainer {
items: recent_contributions()?,
hy_data: JsonHomePageSPAHyData {
page_description: self.page_description,
featured_articles: featured_articles(
&[
"/en-US/blog/mdn-scrimba-partnership/",
"/en-US/blog/learn-javascript-console-methods/",
"/en-US/blog/introduction-to-web-sustainability/",
"/en-US/docs/Web/API/CSS_Custom_Highlight_API",
],
self.locale,
)?,
featured_contributor: featured_contributor(self.locale)?,
latest_news: ItemContainer {
items: lastet_news(&[
"/en-US/blog/mdn-scrimba-partnership/",
"/en-US/blog/mdn-http-observatory-launch/",
"/en-US/blog/mdn-curriculum-launch/",
"/en-US/blog/baseline-evolution-on-mdn/",
])?,
},
recent_contributions: ItemContainer {
items: recent_contributions()?,
},
},
}))),
}
Expand Down

0 comments on commit 2981fea

Please sign in to comment.