summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-02-13 21:35:08 +0100
committermetamuffin <metamuffin@disroot.org>2023-02-13 21:35:08 +0100
commit9732ed5ae9ae7e5bc26f8302b436d67d103e740b (patch)
tree9a3fa0d4a05d40837745e83d03f3e129fd9e03e6
parent9cefa70c3594445c3af6428be982b8b5b5883a42 (diff)
downloadmetamuffin-website-9732ed5ae9ae7e5bc26f8302b436d67d103e740b.tar
metamuffin-website-9732ed5ae9ae7e5bc26f8302b436d67d103e740b.tar.bz2
metamuffin-website-9732ed5ae9ae7e5bc26f8302b436d67d103e740b.tar.zst
atom feed integrated aswell (with a cost of two new deps)
-rw-r--r--Cargo.lock178
-rw-r--r--Cargo.toml7
-rw-r--r--src/blog/atom.rs75
-rw-r--r--src/blog/mod.rs12
-rw-r--r--src/main.rs1
5 files changed, 262 insertions, 11 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ecc9d14..41f517e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -47,6 +47,15 @@ dependencies = [
]
[[package]]
+name = "android_system_properties"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
+dependencies = [
+ "libc",
+]
+
+[[package]]
name = "anyhow"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -284,6 +293,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
+name = "chrono"
+version = "0.4.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f"
+dependencies = [
+ "iana-time-zone",
+ "js-sys",
+ "num-integer",
+ "num-traits",
+ "time 0.1.45",
+ "wasm-bindgen",
+ "winapi",
+]
+
+[[package]]
name = "cipher"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -294,6 +318,16 @@ dependencies = [
]
[[package]]
+name = "codespan-reporting"
+version = "0.11.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e"
+dependencies = [
+ "termcolor",
+ "unicode-width",
+]
+
+[[package]]
name = "concurrent-queue"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -316,11 +350,17 @@ dependencies = [
"rand",
"sha2",
"subtle",
- "time",
+ "time 0.3.17",
"version_check",
]
[[package]]
+name = "core-foundation-sys"
+version = "0.8.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
+
+[[package]]
name = "cpufeatures"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -369,6 +409,50 @@ dependencies = [
]
[[package]]
+name = "cxx"
+version = "1.0.90"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "90d59d9acd2a682b4e40605a242f6670eaa58c5957471cbf85e8aa6a0b97a5e8"
+dependencies = [
+ "cc",
+ "cxxbridge-flags",
+ "cxxbridge-macro",
+ "link-cplusplus",
+]
+
+[[package]]
+name = "cxx-build"
+version = "1.0.90"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ebfa40bda659dd5c864e65f4c9a2b0aff19bea56b017b9b77c73d3766a453a38"
+dependencies = [
+ "cc",
+ "codespan-reporting",
+ "once_cell",
+ "proc-macro2",
+ "quote",
+ "scratch",
+ "syn",
+]
+
+[[package]]
+name = "cxxbridge-flags"
+version = "1.0.90"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "457ce6757c5c70dc6ecdbda6925b958aae7f959bda7d8fb9bde889e34a09dc03"
+
+[[package]]
+name = "cxxbridge-macro"
+version = "1.0.90"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ebf883b7aacd7b2aeb2a7b338648ee19f57c140d4ee8e52c68979c6b2f7f2263"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "devise"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -631,7 +715,7 @@ checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
dependencies = [
"cfg-if",
"libc",
- "wasi",
+ "wasi 0.11.0+wasi-snapshot-preview1",
]
[[package]]
@@ -794,6 +878,30 @@ dependencies = [
]
[[package]]
+name = "iana-time-zone"
+version = "0.1.53"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765"
+dependencies = [
+ "android_system_properties",
+ "core-foundation-sys",
+ "iana-time-zone-haiku",
+ "js-sys",
+ "wasm-bindgen",
+ "winapi",
+]
+
+[[package]]
+name = "iana-time-zone-haiku"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca"
+dependencies = [
+ "cxx",
+ "cxx-build",
+]
+
+[[package]]
name = "include_dir"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -876,7 +984,9 @@ version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "924e5d73ea28f59011fec52a0d12185d496a9b075d360657aed2a5707f701153"
dependencies = [
+ "chrono",
"nom",
+ "num-traits",
]
[[package]]
@@ -916,6 +1026,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
[[package]]
+name = "link-cplusplus"
+version = "1.0.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5"
+dependencies = [
+ "cc",
+]
+
+[[package]]
name = "linux-raw-sys"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1021,7 +1140,7 @@ checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de"
dependencies = [
"libc",
"log",
- "wasi",
+ "wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys 0.42.0",
]
@@ -1066,6 +1185,25 @@ dependencies = [
]
[[package]]
+name = "num-integer"
+version = "0.1.45"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
+dependencies = [
+ "autocfg",
+ "num-traits",
+]
+
+[[package]]
+name = "num-traits"
+version = "0.2.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
name = "num_cpus"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1350,7 +1488,7 @@ dependencies = [
"serde_json",
"state",
"tempfile",
- "time",
+ "time 0.3.17",
"tokio",
"tokio-stream",
"tokio-util",
@@ -1397,7 +1535,7 @@ dependencies = [
"smallvec",
"stable-pattern",
"state",
- "time",
+ "time 0.3.17",
"tokio",
"uncased",
]
@@ -1441,6 +1579,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
+name = "scratch"
+version = "1.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2"
+
+[[package]]
name = "serde"
version = "1.0.152"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1600,6 +1744,17 @@ dependencies = [
[[package]]
name = "time"
+version = "0.1.45"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a"
+dependencies = [
+ "libc",
+ "wasi 0.10.0+wasi-snapshot-preview1",
+ "winapi",
+]
+
+[[package]]
+name = "time"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376"
@@ -1802,6 +1957,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
[[package]]
+name = "unicode-width"
+version = "0.1.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
+
+[[package]]
name = "unicode-xid"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1857,6 +2018,12 @@ dependencies = [
[[package]]
name = "wasi"
+version = "0.10.0+wasi-snapshot-preview1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
+
+[[package]]
+name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
@@ -1943,6 +2110,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"async-std",
+ "chrono",
"env_logger",
"futures",
"include_dir",
diff --git a/Cargo.toml b/Cargo.toml
index fbe0897..028480e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,9 +9,10 @@ tokio = { version = "1.25.0", features = ["full"] }
log = "0.4.17"
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"
-iso8601 = "0.6.1"
+iso8601 = { version = "0.6.1", features = ["chrono"] }
futures = "0.3.26"
anyhow = "1.0.69"
+markup = "0.13.1"
+markdown = "1.0.0-alpha.7"
+chrono = "0.4.23"
diff --git a/src/blog/atom.rs b/src/blog/atom.rs
new file mode 100644
index 0000000..e6b931c
--- /dev/null
+++ b/src/blog/atom.rs
@@ -0,0 +1,75 @@
+use super::{
+ helper::{get_articles, ArticleMeta},
+ rocket_uri_macro_r_blog_article, rocket_uri_macro_r_blog_index, ARTICLE_ROOT,
+};
+use crate::{error::MyResult, uri};
+use rocket::get;
+use std::{path::PathBuf, str::FromStr};
+
+#[get("/blog/feed.atom")]
+pub async fn r_blog_atom() -> MyResult<String> {
+ let entries = get_articles(&PathBuf::from_str(ARTICLE_ROOT).unwrap())
+ .await?
+ .iter()
+ .map(
+ |ArticleMeta {
+ title,
+ date,
+ canonical_name,
+ ..
+ }| {
+ let title = horrible_escape_function(title);
+ let datetime = iso8601::DateTime {
+ date: date.clone(),
+ time: iso8601::Time::default(),
+ };
+ let href = uri!(r_blog_article(canonical_name));
+ format!(
+ r#"
+ <entry>
+ <title>{title}</title>
+ <link href="{href}/{canonical_name}" />
+ <id>tag:metamuffin.org,{date},{title}</id>
+ <published>{datetime}</published>
+ <summary>N/A</summary>
+ <author>
+ <name>metamuffin</name>
+ <email>metamuffin@disroot.org</email>
+ </author>
+ </entry>"#
+ )
+ },
+ )
+ .collect::<Vec<_>>();
+
+ let feed_url = uri!(r_blog_atom());
+ let index_url = uri!(r_blog_index());
+ let now = chrono::Utc::now().to_rfc3339();
+
+ Ok(format!(
+ r#"<?xml version="1.0" encoding="utf-8"?>
+ <feed xmlns="http://www.w3.org/2005/Atom">
+ <title>metamuffin's blog</title>
+ <subtitle>where they post pointless stuff</subtitle>
+ <link href="{feed_url}" rel="self" />
+ <link href="{index_url}" />
+ <id>urn:uuid:3cf2b704-3d94-4f1f-b194-42798ab5b47c</id>
+ <updated>{now}</updated>
+ <author>
+ <name>metamuffin</name>
+ <email>metamuffin@disroot.org</email>
+ </author>
+ {}
+ </feed>
+ "#,
+ entries.join("\n")
+ ))
+}
+
+pub fn horrible_escape_function(text: &str) -> String {
+ text.replace("&", "&amp;")
+ .replace("<", "&lt;")
+ .replace(">", "&gt;")
+ .replace("'", "&#8217;")
+ .replace("\"", "&quot;")
+}
diff --git a/src/blog/mod.rs b/src/blog/mod.rs
index 3ac38eb..23f0721 100644
--- a/src/blog/mod.rs
+++ b/src/blog/mod.rs
@@ -1,3 +1,4 @@
+pub mod atom;
pub mod helper;
use self::helper::{article_metadata, get_articles};
@@ -5,10 +6,14 @@ use crate::error::MyResult;
use crate::layout::{DynScaffold, Scaffold};
use crate::uri;
use anyhow::anyhow;
+pub use atom::r_blog_atom;
+use atom::rocket_uri_macro_r_blog_atom;
use rocket::{get, response::Redirect};
use std::{path::PathBuf, str::FromStr};
use tokio::fs::read_to_string;
+pub const ARTICLE_ROOT: &'static str = "./blog/articles";
+
#[get("/blog")]
pub fn r_blog() -> Redirect {
Redirect::to(rocket::uri!(r_blog_index()))
@@ -17,12 +22,13 @@ pub fn r_blog() -> Redirect {
#[get("/blog/index")]
pub async fn r_blog_index() -> MyResult<DynScaffold<'static>> {
// TODO this is a major performance issue here. requires O(n) syscalls to complete
- let articles = get_articles(&PathBuf::from_str("./blog/articles").unwrap()).await?;
+ let articles = get_articles(&PathBuf::from_str(ARTICLE_ROOT).unwrap()).await?;
Ok(Scaffold {
title: "blog index".to_string(),
content: markup::new! {
h2 { "The Weblog" }
- i { "Articles in reverse-chronological order." }
+ p { i { "Articles in reverse-chronological order." } }
+ p { a[href=uri!(r_blog_atom())]{ "Atom feed" } }
ul {
@for a in &articles {
li {
@@ -37,7 +43,7 @@ pub async fn r_blog_index() -> MyResult<DynScaffold<'static>> {
#[get("/blog/<name>")]
pub async fn r_blog_article(name: &str) -> MyResult<DynScaffold<'static>> {
- let apath = PathBuf::from_str("./blog/articles")
+ let apath = PathBuf::from_str(ARTICLE_ROOT)
.unwrap()
.join(PathBuf::new().with_file_name(name).with_extension("md"));
let a = article_metadata(apath.clone()).await?;
diff --git a/src/main.rs b/src/main.rs
index 1857cfe..70646c3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -38,6 +38,7 @@ async fn main() {
r_blog,
r_blog_index,
r_blog_article,
+ r_blog_atom,
r_wellknown_security,
r_wellknown_matrix_server,
r_wellknown_matrix_client,