65 lines
No EOL
2 KiB
Rust
65 lines
No EOL
2 KiB
Rust
use askama::Template;
|
|
use axum::extract::State;
|
|
use log::warn;
|
|
|
|
use crate::block_types;
|
|
use crate::{block_types::BlockTypes, AppState};
|
|
use crate::entities::{prelude::*, *};
|
|
use sea_orm::*;
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "page.html")]
|
|
pub(crate) struct HomeSpecialTemplate {
|
|
title: String,
|
|
description: Option<String>,
|
|
show_title: bool,
|
|
content_blocks: Vec<BlockTypes>,
|
|
year: String
|
|
}
|
|
|
|
// Handle the special home page
|
|
pub(crate) async fn root(
|
|
state: State<AppState>
|
|
) -> HomeSpecialTemplate {
|
|
|
|
// Grab special home slug page content
|
|
let page_meta: page::Model = Page::find()
|
|
.filter(page::Column::Slug.eq("home"))
|
|
.one(&state.db_conn)
|
|
.await
|
|
.expect("Failed to get home page! HALTING")
|
|
.unwrap();
|
|
|
|
let blocks: Vec<page_block::Model> = page_meta.find_related(PageBlock)
|
|
.order_by_asc(page_block::Column::Order)
|
|
.all(&state.db_conn)
|
|
.await
|
|
.expect("Failed to get home page blocks! HALTING");
|
|
|
|
// TODO: should move this into its own func, it'll be reused a bit
|
|
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");
|
|
|
|
BlockTypes::HEADER { text: deserde.text, size: deserde.size }
|
|
}
|
|
_ => {
|
|
warn!("Unsupported block type! ({})", f.r#type.as_str());
|
|
BlockTypes::UNSUPPORTED
|
|
}
|
|
}
|
|
|
|
).collect();
|
|
|
|
HomeSpecialTemplate {
|
|
title: page_meta.clone().title,
|
|
description: page_meta.clone().description,
|
|
show_title: page_meta.clone().show_title,
|
|
content_blocks,
|
|
year: "2023".to_string()
|
|
}
|
|
} |