Swap to for loop to build content blocks
This commit is contained in:
parent
9a4548fecf
commit
b922771a5a
3 changed files with 74 additions and 53 deletions
|
@ -93,23 +93,32 @@ pub(crate) async fn root(
|
|||
.await
|
||||
.expect("Failed to get home page blocks! HALTING");
|
||||
|
||||
let content_blocks: Vec<BlockTypes> = blocks.into_iter().map(|f|
|
||||
match f.r#type.as_str() {
|
||||
"HR" => BlockTypes::HR,
|
||||
"PARAGRAPH" => BlockTypes::PARAGRAPH { text: f.content },
|
||||
"MARKDOWN" => BlockTypes::MARKDOWN { content: f.content },
|
||||
"HEADER" => {
|
||||
let deserde: block_types::Header = serde_json::from_str(&f.content.as_str()).expect("Incorrect HEADER formatting");
|
||||
let mut content_blocks: Vec<BlockTypes> = vec![];
|
||||
|
||||
BlockTypes::HEADER { text: deserde.text, size: deserde.size }
|
||||
},
|
||||
"HTML" => BlockTypes::HTML { content: f.content },
|
||||
_ => {
|
||||
warn!("Unsupported block type! ({})", f.r#type.as_str());
|
||||
BlockTypes::UNSUPPORTED
|
||||
}
|
||||
}
|
||||
).collect();
|
||||
for block in blocks {
|
||||
content_blocks.push(
|
||||
match block.r#type.as_str() {
|
||||
"HR" => BlockTypes::HR,
|
||||
"PARAGRAPH" => BlockTypes::PARAGRAPH { text: block.content },
|
||||
"MARKDOWN" => BlockTypes::MARKDOWN { content: block.content },
|
||||
"HEADER" => {
|
||||
let deserde: block_types::Header = serde_json::from_str(&block.content.as_str()).expect("Incorrect HEADER blockormatting");
|
||||
|
||||
BlockTypes::HEADER { text: deserde.text, size: deserde.size }
|
||||
},
|
||||
"HTML" => BlockTypes::HTML { content: block.content },
|
||||
"IMAGE" => BlockTypes::IMAGE { content: {
|
||||
Image::find_by_id(block.content)
|
||||
.one(&state.db_conn)
|
||||
.await
|
||||
.expect("Failed to get image! HALTING")
|
||||
}},
|
||||
_ => {
|
||||
warn!("Unsupported block type! ({})", block.r#type.as_str());
|
||||
BlockTypes::UNSUPPORTED
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let menu: Vec<menu_entry::Model> = match Menu::find()
|
||||
.filter(menu::Column::Name.eq("primary"))
|
||||
|
|
|
@ -63,25 +63,33 @@ pub(crate) async fn resolver(
|
|||
.await
|
||||
.expect("Failed to get home page blocks! HALTING");
|
||||
|
||||
let content_blocks: Vec<BlockTypes> = blocks.into_iter().map(|f|
|
||||
match f.r#type.as_str() {
|
||||
"HR" => BlockTypes::HR,
|
||||
"PARAGRAPH" => BlockTypes::PARAGRAPH { text: f.content },
|
||||
"MARKDOWN" => BlockTypes::MARKDOWN { content: f.content },
|
||||
"HEADER" => {
|
||||
let deserde: block_types::Header = serde_json::from_str(&f.content.as_str()).expect("Incorrect HEADER formatting");
|
||||
let mut content_blocks: Vec<BlockTypes> = vec![];
|
||||
|
||||
BlockTypes::HEADER { text: deserde.text, size: deserde.size }
|
||||
},
|
||||
"HTML" => BlockTypes::HTML { content: f.content },
|
||||
_ => {
|
||||
warn!("Unsupported block type! ({})", f.r#type.as_str());
|
||||
BlockTypes::UNSUPPORTED
|
||||
}
|
||||
for block in blocks {
|
||||
content_blocks.push(
|
||||
match block.r#type.as_str() {
|
||||
"HR" => BlockTypes::HR,
|
||||
"PARAGRAPH" => BlockTypes::PARAGRAPH { text: block.content },
|
||||
"MARKDOWN" => BlockTypes::MARKDOWN { content: block.content },
|
||||
"HEADER" => {
|
||||
let deserde: block_types::Header = serde_json::from_str(&block.content.as_str()).expect("Incorrect HEADER blockormatting");
|
||||
|
||||
BlockTypes::HEADER { text: deserde.text, size: deserde.size }
|
||||
},
|
||||
"HTML" => BlockTypes::HTML { content: block.content },
|
||||
"IMAGE" => BlockTypes::IMAGE { content: {
|
||||
Image::find_by_id(block.content)
|
||||
.one(&state.db_conn)
|
||||
.await
|
||||
.expect("Failed to get image! HALTING")
|
||||
}},
|
||||
_ => {
|
||||
warn!("Unsupported block type! ({})", block.r#type.as_str());
|
||||
BlockTypes::UNSUPPORTED
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
).collect();
|
||||
|
||||
(StatusCode::FOUND, PageTemplate {
|
||||
draft: page_meta.clone().draft,
|
||||
title: page_meta.clone().title,
|
||||
|
|
|
@ -63,28 +63,32 @@ pub(crate) async fn resolver(
|
|||
.await
|
||||
.expect("Failed to get post blocks! HALTING");
|
||||
|
||||
let content_blocks: Vec<BlockTypes> = blocks.into_iter().map(|f|
|
||||
match f.r#type.as_str() {
|
||||
"HR" => BlockTypes::HR,
|
||||
"PARAGRAPH" => BlockTypes::PARAGRAPH { text: f.content },
|
||||
"MARKDOWN" => BlockTypes::MARKDOWN { content: f.content },
|
||||
"HEADER" => {
|
||||
let deserde: block_types::Header = serde_json::from_str(&f.content.as_str()).expect("Incorrect HEADER formatting");
|
||||
let mut content_blocks: Vec<BlockTypes> = vec![];
|
||||
|
||||
BlockTypes::HEADER { text: deserde.text, size: deserde.size }
|
||||
},
|
||||
"HTML" => BlockTypes::HTML { content: f.content },
|
||||
"IMAGE" => BlockTypes::IMAGE { content: {
|
||||
Image::find_by_id(f.content)
|
||||
.one(&state.db_conn)
|
||||
.await
|
||||
.expect("Failed to get image! HALTING")
|
||||
}},
|
||||
_ => {
|
||||
warn!("Unsupported block type! ({})", f.r#type.as_str());
|
||||
BlockTypes::UNSUPPORTED
|
||||
}
|
||||
}).collect();
|
||||
for block in blocks {
|
||||
content_blocks.push(
|
||||
match block.r#type.as_str() {
|
||||
"HR" => BlockTypes::HR,
|
||||
"PARAGRAPH" => BlockTypes::PARAGRAPH { text: block.content },
|
||||
"MARKDOWN" => BlockTypes::MARKDOWN { content: block.content },
|
||||
"HEADER" => {
|
||||
let deserde: block_types::Header = serde_json::from_str(&block.content.as_str()).expect("Incorrect HEADER blockormatting");
|
||||
|
||||
BlockTypes::HEADER { text: deserde.text, size: deserde.size }
|
||||
},
|
||||
"HTML" => BlockTypes::HTML { content: block.content },
|
||||
"IMAGE" => BlockTypes::IMAGE { content: {
|
||||
Image::find_by_id(block.content)
|
||||
.one(&state.db_conn)
|
||||
.await
|
||||
.expect("Failed to get image! HALTING")
|
||||
}},
|
||||
_ => {
|
||||
warn!("Unsupported block type! ({})", block.r#type.as_str());
|
||||
BlockTypes::UNSUPPORTED
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let last_updated = match post_meta.clone().updated {
|
||||
Some(updated) => Some(updated.to_string()),
|
||||
|
|
Reference in a new issue