Skip to content

Commit b608389

Browse files
authored
feat(json): add fm description to generic and contributor (#242)
1 parent 5332969 commit b608389

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

crates/rari-doc/src/pages/build.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::html::sections::{split_sections, BuildSection, BuildSectionType, Spli
3030
use crate::html::sidebar::{
3131
build_sidebars, expand_details_and_mark_current_for_inline_sidebar, postprocess_sidebar,
3232
};
33-
use crate::pages::json::JsonContributorSpotlightPage;
33+
use crate::pages::json::{CommonJsonData, JsonContributorSpotlightPage};
3434
use crate::pages::types::blog::BlogPost;
3535
use crate::pages::types::curriculum::{
3636
build_landing_modules, build_overview_modules, build_sidebar, curriculum_group,
@@ -368,6 +368,9 @@ fn build_generic_page(page: &Generic) -> Result<BuiltPage, DocError> {
368368
},
369369
url: page.meta.url.clone(),
370370
id: page.meta.page.clone(),
371+
common: CommonJsonData {
372+
description: page.meta.description.clone(),
373+
},
371374
},
372375
page.meta.template,
373376
),
@@ -440,6 +443,9 @@ fn build_contributor_spotlight(cs: &ContributorSpotlight) -> Result<BuiltPage, D
440443
url: cs.meta.url.clone(),
441444
page_title: cs.meta.title.clone(),
442445
hy_data: contributor_spotlight_data,
446+
common: CommonJsonData {
447+
description: cs.meta.description.clone(),
448+
},
443449
}),
444450
)))
445451
}

crates/rari-doc/src/pages/json.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ pub struct ContributorSpotlightHyData {
596596
/// * `url` - A `String` that holds the URL of the contributor spotlight page.
597597
/// * `page_title` - A `String` that holds the title of the contributor spotlight page. Serialized as `pageTitle`.
598598
/// * `hy_data` - A `ContributorSpotlightHyData` that holds the data related to the contributor. Serialized as `hyData`.
599+
/// * `common` - Common data, e.g. description.
599600
#[derive(Debug, Clone, Serialize, JsonSchema)]
600601
#[schemars(rename = "ContributorSpotlightPage")]
601602
pub struct JsonContributorSpotlightPage {
@@ -604,6 +605,8 @@ pub struct JsonContributorSpotlightPage {
604605
pub page_title: String,
605606
#[serde(rename = "hyData")]
606607
pub hy_data: ContributorSpotlightHyData,
608+
#[serde(flatten)]
609+
pub common: CommonJsonData,
607610
}
608611

609612
/// Represents the different JSON artifacts of built pages.
@@ -923,6 +926,7 @@ pub struct JsonGenericHyData {
923926
/// * `page_title` - A `String` that holds the title of the generic page.
924927
/// * `url` - A `String` that holds the URL of the generic page.
925928
/// * `id` - A `String` that holds the unique identifier for the generic page.
929+
/// * `common` - Common data, e.g. description.
926930
#[derive(Debug, Clone, Serialize, JsonSchema)]
927931
#[serde(rename_all = "camelCase")]
928932
#[schemars(rename = "GenericPage")]
@@ -931,4 +935,13 @@ pub struct JsonGenericPage {
931935
pub page_title: String,
932936
pub url: String,
933937
pub id: String,
938+
#[serde(flatten)]
939+
pub common: CommonJsonData,
940+
}
941+
942+
#[derive(Debug, Clone, Serialize, JsonSchema)]
943+
#[serde(rename_all = "camelCase")]
944+
#[schemars(rename = "GenericPage")]
945+
pub struct CommonJsonData {
946+
pub description: Option<String>,
934947
}

crates/rari-doc/src/pages/types/contributors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub struct ContributorFrontMatter {
2929
pub img_alt: String,
3030
pub usernames: Usernames,
3131
pub quote: String,
32+
pub description: Option<String>,
3233
}
3334

3435
#[derive(Serialize, Clone, Debug)]
@@ -42,6 +43,7 @@ pub struct ContributorMeta {
4243
pub img_alt: String,
4344
pub usernames: Usernames,
4445
pub quote: String,
46+
pub description: Option<String>,
4547
}
4648

4749
#[derive(Serialize, Clone, Debug)]
@@ -59,6 +61,7 @@ pub struct ContributorBuildMeta {
5961
pub quote: String,
6062
pub path: PathBuf,
6163
pub full_path: PathBuf,
64+
pub description: Option<String>,
6265
}
6366

6467
impl From<&ContributorBuildMeta> for ContributorMeta {
@@ -73,6 +76,7 @@ impl From<&ContributorBuildMeta> for ContributorMeta {
7376
img_alt,
7477
usernames,
7578
quote,
79+
description,
7680
..
7781
} = value;
7882
ContributorMeta {
@@ -85,6 +89,7 @@ impl From<&ContributorBuildMeta> for ContributorMeta {
8589
img_alt: img_alt.clone(),
8690
usernames: usernames.clone(),
8791
quote: quote.clone(),
92+
description: description.clone(),
8893
}
8994
}
9095
}
@@ -108,6 +113,7 @@ impl ContributorBuildMeta {
108113
img_alt,
109114
usernames,
110115
quote,
116+
description,
111117
} = fm;
112118
let slug = concat_strs!("spotlight/", folder_name.as_str());
113119
Ok(Self {
@@ -128,6 +134,7 @@ impl ContributorBuildMeta {
128134
quote,
129135
full_path,
130136
path,
137+
description,
131138
})
132139
}
133140
}

crates/rari-doc/src/pages/types/generic.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub enum Template {
2525
pub struct GenericFrontmatter {
2626
pub title: String,
2727
pub template: Option<Template>,
28+
pub description: Option<String>,
2829
}
2930

3031
#[derive(Debug, Clone)]
@@ -38,6 +39,7 @@ pub struct GenericMeta {
3839
pub title_suffix: Option<String>,
3940
pub page: String,
4041
pub template: Template,
42+
pub description: Option<String>,
4143
}
4244

4345
impl GenericMeta {
@@ -68,6 +70,7 @@ impl GenericMeta {
6870
title_suffix,
6971
page,
7072
template: fm.template.unwrap_or_default(),
73+
description: fm.description,
7174
})
7275
}
7376
}

0 commit comments

Comments
 (0)