parent
78cb11b54a
commit
37d6c3cd4d
@ -0,0 +1,67 @@
|
||||
use askama_axum::IntoResponse;
|
||||
use axum::extract::{State, Path};
|
||||
use axum::http::StatusCode;
|
||||
use log::{warn, error};
|
||||
|
||||
use crate::block_types;
|
||||
use crate::{block_types::BlockTypes, AppState};
|
||||
use crate::entities::{prelude::*, *};
|
||||
use sea_orm::*;
|
||||
|
||||
use super::{PageTemplate, NotFoundTemplate};
|
||||
|
||||
pub(crate) async fn resolver(
|
||||
Path(slug): Path<String>,
|
||||
state: State<AppState>
|
||||
) -> impl IntoResponse {
|
||||
let page_search: Result<Option<page::Model>, DbErr> = Page::find()
|
||||
.filter(page::Column::Slug.eq(&slug))
|
||||
.one(&state.db_conn)
|
||||
.await;
|
||||
|
||||
let page_meta: page::Model = match page_search {
|
||||
Ok(page_result) => {
|
||||
match page_result {
|
||||
Some(page_result) => page_result,
|
||||
None => return (StatusCode::NOT_FOUND, NotFoundTemplate { slug, year: "2023".to_owned() }).into_response(),
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
error!("{}", e);
|
||||
return (StatusCode::INTERNAL_SERVER_ERROR, ()).into_response();
|
||||
},
|
||||
};
|
||||
|
||||
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");
|
||||
|
||||
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();
|
||||
|
||||
(StatusCode::FOUND, PageTemplate {
|
||||
title: page_meta.clone().title,
|
||||
description: page_meta.clone().description,
|
||||
show_title: page_meta.clone().show_title,
|
||||
content_blocks,
|
||||
year: "2023".to_string()
|
||||
}).into_response()
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}404{% endblock %}
|
||||
|
||||
{% block description %}
|
||||
This page wasn't found!
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h1>Page not found!</h1>
|
||||
|
||||
<p><code>{{ slug }}</code> was not found! Would you like to go <a href="/">home</a>?</p>
|
||||
|
||||
{% endblock %}
|
Loading…
Reference in new issue