Compare commits

...

6 Commits

12 changed files with 979 additions and 90 deletions

View File

@ -136,7 +136,8 @@ async fn main() {
TraceLayer::new_for_http()
.make_span_with(trace::DefaultMakeSpan::new().level(tracing::Level::INFO))
.on_response(trace::DefaultOnResponse::new().level(tracing::Level::INFO)),
);
)
.fallback(routes::root::RootRoute::not_found);
// .layer(cors);
//.layer(GovernorLayer {
// config: governor_conf,

View File

@ -1,5 +1,4 @@
use super::posts::{deserialize_datetime, serialize_datetime};
use crate::{datasources::comments::CommentsDatasource, state::AppState};
use crate::{datasources::comments::CommentsDatasource, state::AppState, utils::datetime::*};
use axum::{
extract::{Path, State},
http::StatusCode,

View File

@ -1,8 +1,8 @@
use std::collections::HashMap;
use std::fmt;
use crate::utils::rss;
use crate::{datasources::posts::PostsDatasource, state::AppState};
use crate::{
datasources::posts::PostsDatasource,
state::AppState,
utils::{datetime::*, rss},
};
use axum::http::{HeaderMap, HeaderValue};
use axum::{
extract::{Path, State},
@ -13,7 +13,8 @@ use axum::{
};
use chrono::Utc;
use fred::types::Expiration;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(sqlx::FromRow, Deserialize, Serialize, Debug, Clone)]
pub struct Post {
@ -359,56 +360,3 @@ impl PostsRoute {
}
}
}
pub fn serialize_datetime<S>(
date: &Option<chrono::DateTime<Utc>>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&date.unwrap().to_rfc3339())
}
pub fn deserialize_datetime<'de, D>(
deserializer: D,
) -> Result<Option<chrono::DateTime<Utc>>, D::Error>
where
D: Deserializer<'de>,
{
struct DateTimeVisitor;
impl<'de> serde::de::Visitor<'de> for DateTimeVisitor {
type Value = Option<chrono::DateTime<Utc>>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("an ISO 8601 formatted date string or null")
}
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
match chrono::DateTime::parse_from_rfc3339(value) {
Ok(dt) => Ok(Some(dt.with_timezone(&Utc))),
Err(e) => Err(E::custom(format!("Failed to parse datetime: {}", e))),
}
}
fn visit_none<E>(self) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
Ok(None)
}
fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
where
D: Deserializer<'de>,
{
deserializer.deserialize_str(self)
}
}
deserializer.deserialize_option(DateTimeVisitor)
}

View File

@ -8,15 +8,20 @@ use axum::{
pub struct RootRoute;
impl RootRoute {
pub fn routes() -> Router {
Router::new().route("/", get(RootRoute::root))
// .fallback(RootRoute::not_found)
Router::new()
.route("/", get(RootRoute::root))
.route("/health", get(RootRoute::health))
}
async fn root() -> Html<&'static str> {
Html("<p>Copyright Wyatt J. Miller 2024</p>")
}
async fn not_found() -> impl IntoResponse {
pub async fn not_found() -> impl IntoResponse {
(StatusCode::NOT_FOUND, "¯\\_(ツ)_/¯")
}
async fn health() -> impl IntoResponse {
StatusCode::OK
}
}

View File

@ -0,0 +1,56 @@
use chrono::Utc;
use serde::{Deserializer, Serializer};
use std::fmt;
pub fn serialize_datetime<S>(
date: &Option<chrono::DateTime<Utc>>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&date.unwrap().to_rfc3339())
}
pub fn deserialize_datetime<'de, D>(
deserializer: D,
) -> Result<Option<chrono::DateTime<Utc>>, D::Error>
where
D: Deserializer<'de>,
{
struct DateTimeVisitor;
impl<'de> serde::de::Visitor<'de> for DateTimeVisitor {
type Value = Option<chrono::DateTime<Utc>>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("an ISO 8601 formatted date string or null")
}
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
match chrono::DateTime::parse_from_rfc3339(value) {
Ok(dt) => Ok(Some(dt.with_timezone(&Utc))),
Err(e) => Err(E::custom(format!("Failed to parse datetime: {}", e))),
}
}
fn visit_none<E>(self) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
Ok(None)
}
fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
where
D: Deserializer<'de>,
{
deserializer.deserialize_str(self)
}
}
deserializer.deserialize_option(DateTimeVisitor)
}

View File

@ -1 +1,2 @@
pub mod datetime;
pub mod rss;

921
backend/task/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -20,3 +20,4 @@ futures = "0.3.30"
markdown = "1.0.0-alpha.20"
serde = {version = "*", features = ["derive"]}
serde_yaml = "*"
aws-sdk-s3 = "1.77.0"

View File

@ -35,7 +35,7 @@ export default function Header() {
return (
<header>
<nav>
<div class="bg-[#313244] flex justify-center space-x-6 p-4">
<div class="bg-[#313244] flex flex-wrap justify-center space-x-6 p-4">
{headerLinks.map((l) => {
const newTab = l.newTab ? "_blank" : "_self";
return (

View File

@ -5,7 +5,7 @@ export const PostHeader = function PostHeader({ post }: PostHeaderOpts) {
return (
<div class="p-6 bg-[#313244] shadow-md">
<div class="min-w-screen flex flex-col items-center justify-between bg-[#45475a] rounded-lg shadow-md">
<div class="sm:mt-14 sm:mb-14 mt-12 mb-4 flex flex-col items-center gap-y-5 gap-x-10 md:flex-row">
<div class="sm:mt-14 sm:mb-14 mt-8 mb-8 flex flex-col items-center gap-y-5 gap-x-10 md:flex-row">
<div class="space-y-2 text-center md:text-left">
<p class="text-2xl text-[#f5e0dc] font-bold sm:text-4xl">
{post.title}

View File

@ -13,7 +13,7 @@ export default function Error404() {
The page you were looking for doesn't exist!
</p>
<a
href="/"
href={`${Deno.env.get("BASE_URI_WEB")}/`}
class="text-[#cdd6f4] transition-all duration-300 ease-in-out hover:text-[#cba6f7] hover:drop-shadow-[0_0_20px_rgba(96,165,250,0.7)] hover:scale-110 cursor-pointer"
>
Go back home

View File

@ -27,7 +27,6 @@ export const handler: Handlers<PageData> = {
export default function PostIdentifier({ data }: PageProps<PageData>) {
const { postData } = data;
console.log(postData);
return (
<div>