summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-02-13 19:48:42 +0100
committermetamuffin <metamuffin@disroot.org>2023-02-13 19:48:42 +0100
commitc4d99ef7307c238244c975e45ae1e24c923538b6 (patch)
treea80ce5de4547fff8347aeaa3e4b9cf48adfe75b2 /src
parentba4d782687b5eb8d91fd881a7cb9d0adce7dd9f0 (diff)
downloadmetamuffin-website-c4d99ef7307c238244c975e45ae1e24c923538b6.tar
metamuffin-website-c4d99ef7307c238244c975e45ae1e24c923538b6.tar.bz2
metamuffin-website-c4d99ef7307c238244c975e45ae1e24c923538b6.tar.zst
prepare for blog stuff
Diffstat (limited to 'src')
-rw-r--r--src/blog/mod.rs15
-rw-r--r--src/layout.rs30
-rw-r--r--src/main.rs6
-rw-r--r--src/pages.rs19
-rw-r--r--src/source.rs7
5 files changed, 49 insertions, 28 deletions
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 <metamuffin.org>
+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 <metamuffin.org>
*/
-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<Main: Render>(title: String, main: Main, noimg: bool) {
+ ScaffoldImpl<Main: Render>(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<markup::DynRender<'a>>;
+pub type DynScaffold<'a> = Scaffold<markup::DynRender<'a>>;
-pub struct LayoutPage<T> {
+pub struct Scaffold<T> {
pub title: String,
pub content: T,
}
-impl<'r, Main: Render> Responder<'r, 'static> for LayoutPage<Main> {
+impl<'r, Main: Render> Responder<'r, 'static> for Scaffold<Main> {
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 <metamuffin.org>
*/
+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<T>(pub T);
#[rocket::async_trait]
@@ -51,7 +50,7 @@ pub fn prepare_source() -> SourceWrap {
}
#[get("/source")]
-pub async fn r_source(text: &State<SourceWrap>) -> Reload<DynLayoutPage> {
+pub async fn r_source(text: &State<SourceWrap>) -> Reload<DynScaffold> {
let mspf = 100u128;
let ts = SystemTime::now()
@@ -74,7 +73,7 @@ pub async fn r_source(text: &State<SourceWrap>) -> Reload<DynLayoutPage> {
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 } },
})