Compare commits

..

No commits in common. "master" and "caching" have entirely different histories.

12 changed files with 90 additions and 979 deletions

View File

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

View File

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

View File

@ -1,8 +1,8 @@
use crate::{ use std::collections::HashMap;
datasources::posts::PostsDatasource, use std::fmt;
state::AppState,
utils::{datetime::*, rss}, use crate::utils::rss;
}; use crate::{datasources::posts::PostsDatasource, state::AppState};
use axum::http::{HeaderMap, HeaderValue}; use axum::http::{HeaderMap, HeaderValue};
use axum::{ use axum::{
extract::{Path, State}, extract::{Path, State},
@ -13,8 +13,7 @@ use axum::{
}; };
use chrono::Utc; use chrono::Utc;
use fred::types::Expiration; use fred::types::Expiration;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::collections::HashMap;
#[derive(sqlx::FromRow, Deserialize, Serialize, Debug, Clone)] #[derive(sqlx::FromRow, Deserialize, Serialize, Debug, Clone)]
pub struct Post { pub struct Post {
@ -360,3 +359,56 @@ 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,20 +8,15 @@ use axum::{
pub struct RootRoute; pub struct RootRoute;
impl RootRoute { impl RootRoute {
pub fn routes() -> Router { pub fn routes() -> Router {
Router::new() Router::new().route("/", get(RootRoute::root))
.route("/", get(RootRoute::root)) // .fallback(RootRoute::not_found)
.route("/health", get(RootRoute::health))
} }
async fn root() -> Html<&'static str> { async fn root() -> Html<&'static str> {
Html("<p>Copyright Wyatt J. Miller 2024</p>") Html("<p>Copyright Wyatt J. Miller 2024</p>")
} }
pub async fn not_found() -> impl IntoResponse { async fn not_found() -> impl IntoResponse {
(StatusCode::NOT_FOUND, "¯\\_(ツ)_/¯") (StatusCode::NOT_FOUND, "¯\\_(ツ)_/¯")
} }
async fn health() -> impl IntoResponse {
StatusCode::OK
}
} }

View File

@ -1,56 +0,0 @@
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,2 +1 @@
pub mod datetime;
pub mod rss; pub mod rss;

921
backend/task/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@ -5,7 +5,7 @@ export const PostHeader = function PostHeader({ post }: PostHeaderOpts) {
return ( return (
<div class="p-6 bg-[#313244] shadow-md"> <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="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-8 mb-8 flex flex-col items-center gap-y-5 gap-x-10 md:flex-row"> <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="space-y-2 text-center md:text-left"> <div class="space-y-2 text-center md:text-left">
<p class="text-2xl text-[#f5e0dc] font-bold sm:text-4xl"> <p class="text-2xl text-[#f5e0dc] font-bold sm:text-4xl">
{post.title} {post.title}

View File

@ -13,7 +13,7 @@ export default function Error404() {
The page you were looking for doesn't exist! The page you were looking for doesn't exist!
</p> </p>
<a <a
href={`${Deno.env.get("BASE_URI_WEB")}/`} href="/"
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" 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 Go back home

View File

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