From c4d99ef7307c238244c975e45ae1e24c923538b6 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 13 Feb 2023 19:48:42 +0100 Subject: prepare for blog stuff --- .gitignore | 1 - Cargo.lock | 16 ++++++++++++++++ Cargo.toml | 1 + src/blog/mod.rs | 15 +++++++++++++++ src/layout.rs | 30 ++++++++++++++++++------------ src/main.rs | 6 ++++-- src/pages.rs | 19 +++++++++---------- src/source.rs | 7 +++---- 8 files changed, 66 insertions(+), 29 deletions(-) create mode 100644 src/blog/mod.rs diff --git a/.gitignore b/.gitignore index ae9c070..ea8c4bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ /target -/modules diff --git a/Cargo.lock b/Cargo.lock index fbe6600..f2f1207 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -917,6 +917,15 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "markdown" +version = "1.0.0-alpha.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98de49c677e95e00eaa74c42a0b07ea55e1e0b1ebca5b2cbc7657f288cd714eb" +dependencies = [ + "unicode-id", +] + [[package]] name = "markup" version = "0.13.1" @@ -1725,6 +1734,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "unicode-id" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d70b6494226b36008c8366c288d77190b3fad2eb4c10533139c1c1f461127f1a" + [[package]] name = "unicode-ident" version = "1.0.6" @@ -1875,6 +1890,7 @@ dependencies = [ "env_logger", "include_dir", "log", + "markdown", "markup", "rocket", "tokio", diff --git a/Cargo.toml b/Cargo.toml index 2eb7a52..4059389 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,3 +11,4 @@ env_logger = "0.10.0" async-std = "1.12.0" markup = "0.13.1" include_dir = { version = "0.7.3", features = ["glob"] } +markdown = "1.0.0-alpha.7" diff --git a/src/blog/mod.rs b/src/blog/mod.rs new file mode 100644 index 0000000..5cc5f0b --- /dev/null +++ b/src/blog/mod.rs @@ -0,0 +1,15 @@ +use crate::layout::{DynScaffold, Scaffold}; +use rocket::{get, response::Redirect}; + +#[get("/blog")] +pub fn r_blog() -> Redirect { + Redirect::to(rocket::uri!(r_blog_index())) +} + +#[get("/blog/index")] +pub fn r_blog_index() -> DynScaffold<'static> { + Scaffold { + title: "blog index".to_string(), + content: markup::new! {}, + } +} diff --git a/src/layout.rs b/src/layout.rs index c553990..421f50e 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -1,10 +1,15 @@ /* - This file is part of metamuffins website (https://codeberg.org/metamuffin/website) - which is licensed under the GNU Affero General Public License (version 3); see /COPYING. - Copyright (C) 2023 metamuffin +This file is part of metamuffins website (https://codeberg.org/metamuffin/website) +which is licensed under the GNU Affero General Public License (version 3); see /COPYING. +Copyright (C) 2023 metamuffin */ -use crate::pages::*; -use crate::source::*; + +use crate::blog::rocket_uri_macro_r_blog; +use crate::pages::{ + rocket_uri_macro_r_about, rocket_uri_macro_r_contact, rocket_uri_macro_r_pgp_key, + rocket_uri_macro_r_projects, +}; +use crate::source::rocket_uri_macro_r_source; use crate::uri; use markup::Render; use rocket::{ @@ -15,7 +20,7 @@ use rocket::{ use std::io::Cursor; markup::define! { - Layout(title: String, main: Main, noimg: bool) { + ScaffoldImpl(title: String, main: Main, noimg: bool) { @markup::doctype() html { head { @@ -26,11 +31,11 @@ markup::define! { h1 { "metamuffin's personal website" } nav { a[href=uri!(r_about())] { "About" } " " + a[href=uri!(r_blog())] { "Blog" } " " a[href=uri!(r_projects())] { "Projects" } " " a[href=uri!(r_contact())] { "Contact" } " " a[href="https://codeberg.org/metamuffin"] { "Codeberg" } " " a[href=uri!(r_pgp_key())] { "PGP-Key" } " " - a[href=uri!(r_source())] { "Sources" } " " } hr; section { @main } @@ -38,7 +43,8 @@ markup::define! { footer { p { "metamuffin's website; version " @include_str!("../.git/refs/heads/main")[0..10] "; " - "sources available on " a[href="https://codeberg.org/metamuffin/website"] { "codeberg" } + "sources available on " a[href=uri!(r_source())] { "this page itself" } + " and on " a[href="https://codeberg.org/metamuffin/website"] { "codeberg" } } } } @@ -46,17 +52,17 @@ markup::define! { } } -pub type DynLayoutPage<'a> = LayoutPage>; +pub type DynScaffold<'a> = Scaffold>; -pub struct LayoutPage { +pub struct Scaffold { pub title: String, pub content: T, } -impl<'r, Main: Render> Responder<'r, 'static> for LayoutPage
{ +impl<'r, Main: Render> Responder<'r, 'static> for Scaffold
{ fn respond_to(self, _req: &'r Request<'_>) -> response::Result<'static> { let mut out = String::new(); - Layout { + ScaffoldImpl { main: self.content, noimg: self.title == "Source", title: self.title, diff --git a/src/main.rs b/src/main.rs index b0822e8..b1b5147 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,11 +3,13 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2023 metamuffin */ +pub mod blog; pub mod layout; pub mod pages; pub mod source; pub mod wellknown; +use blog::*; use pages::*; use rocket::{catchers, fairing::AdHoc, http::Header, routes}; use source::*; @@ -16,7 +18,6 @@ use wellknown::*; #[tokio::main] async fn main() { env_logger::init_from_env("LOG"); - let _ = rocket::build() .attach(AdHoc::on_response("set server header", |_req, res| { res.set_header(Header::new("server", "blub")); @@ -32,12 +33,13 @@ async fn main() { r_projects, r_pgp_key, r_source, + r_blog, + r_blog_index, r_wellknown_security, r_wellknown_matrix_server, r_wellknown_matrix_client, ], ) - // .mount("/", FileServer::from("modules")) .register("/", catchers![r_catch]) .launch() .await diff --git a/src/pages.rs b/src/pages.rs index 720bfba..00626e3 100644 --- a/src/pages.rs +++ b/src/pages.rs @@ -1,15 +1,14 @@ +use crate::layout::{DynScaffold, Scaffold}; use rocket::{catch, get, http::Status, response::Redirect, uri, Request}; -use crate::layout::{DynLayoutPage, LayoutPage}; - #[get("/")] pub fn r_root() -> Redirect { Redirect::to(uri!(r_about())) } #[get("/about")] -pub fn r_about() -> DynLayoutPage<'static> { - LayoutPage { +pub fn r_about() -> DynScaffold<'static> { + Scaffold { title: "about".to_string(), content: markup::new! { p { @@ -40,8 +39,8 @@ pub fn r_about() -> DynLayoutPage<'static> { } #[get("/projects")] -pub fn r_projects() -> DynLayoutPage<'static> { - LayoutPage { +pub fn r_projects() -> DynScaffold<'static> { + Scaffold { title: "projects".to_string(), content: markup::new! { p { "I am starting a lot of projects - here are a few selected ones:" } @@ -77,8 +76,8 @@ pub fn r_projects() -> DynLayoutPage<'static> { } #[get("/contact")] -pub fn r_contact() -> DynLayoutPage<'static> { - LayoutPage { +pub fn r_contact() -> DynScaffold<'static> { + Scaffold { title: "contact".to_string(), content: markup::new! { p { "You can reach out to me in a bunch of ways. I am also generally looking for nice software ideas to implement." } @@ -98,8 +97,8 @@ pub fn r_pgp_key() -> &'static str { } #[catch(default)] -pub fn r_catch<'a>(status: Status, _request: &Request) -> DynLayoutPage<'a> { - LayoutPage { +pub fn r_catch<'a>(status: Status, _request: &Request) -> DynScaffold<'a> { + Scaffold { title: "Error".to_string(), content: markup::new! { h2 { "Error" } diff --git a/src/source.rs b/src/source.rs index ef76512..04ec929 100644 --- a/src/source.rs +++ b/src/source.rs @@ -1,3 +1,4 @@ +use crate::layout::{DynScaffold, Scaffold}; use rocket::{ get, http::Header, @@ -6,8 +7,6 @@ use rocket::{ }; use std::time::{Duration, SystemTime, UNIX_EPOCH}; -use crate::layout::{DynLayoutPage, LayoutPage}; - pub struct Reload(pub T); #[rocket::async_trait] @@ -51,7 +50,7 @@ pub fn prepare_source() -> SourceWrap { } #[get("/source")] -pub async fn r_source(text: &State) -> Reload { +pub async fn r_source(text: &State) -> Reload { let mspf = 100u128; let ts = SystemTime::now() @@ -74,7 +73,7 @@ pub async fn r_source(text: &State) -> Reload { out += &text.0[(i % text.0.len() as u128) as usize]; out += "\n"; } - Reload(LayoutPage { + Reload(Scaffold { title: "Source".to_string(), content: markup::new! { pre { @out } }, }) -- cgit v1.2.3-70-g09d2