hide posts with future dates
This commit is contained in:
parent
9c5d3ef58e
commit
0d9115749b
8 changed files with 164 additions and 15 deletions
116
Cargo.lock
generated
116
Cargo.lock
generated
|
@ -381,6 +381,25 @@ dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-channel"
|
||||||
|
version = "0.5.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"crossbeam-utils",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-utils"
|
||||||
|
version = "0.8.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crypto-common"
|
name = "crypto-common"
|
||||||
version = "0.1.6"
|
version = "0.1.6"
|
||||||
|
@ -470,6 +489,19 @@ dependencies = [
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dashmap"
|
||||||
|
version = "5.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"hashbrown 0.12.3",
|
||||||
|
"lock_api",
|
||||||
|
"once_cell",
|
||||||
|
"parking_lot_core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "deunicode"
|
name = "deunicode"
|
||||||
version = "0.4.3"
|
version = "0.4.3"
|
||||||
|
@ -572,12 +604,34 @@ version = "0.3.27"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd"
|
checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-executor"
|
||||||
|
version = "0.3.27"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1997dd9df74cdac935c76252744c1ed5794fac083242ea4fe77ef3ed60ba0f83"
|
||||||
|
dependencies = [
|
||||||
|
"futures-core",
|
||||||
|
"futures-task",
|
||||||
|
"futures-util",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-io"
|
name = "futures-io"
|
||||||
version = "0.3.27"
|
version = "0.3.27"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "89d422fa3cbe3b40dca574ab087abb5bc98258ea57eea3fd6f1fa7162c778b91"
|
checksum = "89d422fa3cbe3b40dca574ab087abb5bc98258ea57eea3fd6f1fa7162c778b91"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-macro"
|
||||||
|
version = "0.3.27"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-sink"
|
name = "futures-sink"
|
||||||
version = "0.3.27"
|
version = "0.3.27"
|
||||||
|
@ -597,6 +651,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab"
|
checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
"futures-macro",
|
||||||
"futures-sink",
|
"futures-sink",
|
||||||
"futures-task",
|
"futures-task",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
|
@ -1077,6 +1132,52 @@ version = "1.17.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "opentelemetry"
|
||||||
|
version = "0.18.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "69d6c3d7288a106c0a363e4b0e8d308058d56902adefb16f4936f417ffef086e"
|
||||||
|
dependencies = [
|
||||||
|
"opentelemetry_api",
|
||||||
|
"opentelemetry_sdk",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "opentelemetry_api"
|
||||||
|
version = "0.18.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c24f96e21e7acc813c7a8394ee94978929db2bcc46cf6b5014fc612bf7760c22"
|
||||||
|
dependencies = [
|
||||||
|
"fnv",
|
||||||
|
"futures-channel",
|
||||||
|
"futures-util",
|
||||||
|
"indexmap",
|
||||||
|
"js-sys",
|
||||||
|
"once_cell",
|
||||||
|
"pin-project-lite",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "opentelemetry_sdk"
|
||||||
|
version = "0.18.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1ca41c4933371b61c2a2f214bf16931499af4ec90543604ec828f7a625c09113"
|
||||||
|
dependencies = [
|
||||||
|
"async-trait",
|
||||||
|
"crossbeam-channel",
|
||||||
|
"dashmap",
|
||||||
|
"fnv",
|
||||||
|
"futures-channel",
|
||||||
|
"futures-executor",
|
||||||
|
"futures-util",
|
||||||
|
"once_cell",
|
||||||
|
"opentelemetry_api",
|
||||||
|
"percent-encoding",
|
||||||
|
"rand",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "overload"
|
name = "overload"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
|
@ -1862,6 +1963,20 @@ dependencies = [
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-opentelemetry"
|
||||||
|
version = "0.18.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "21ebb87a95ea13271332df069020513ab70bdb5637ca42d6e492dc3bbbad48de"
|
||||||
|
dependencies = [
|
||||||
|
"once_cell",
|
||||||
|
"opentelemetry",
|
||||||
|
"tracing",
|
||||||
|
"tracing-core",
|
||||||
|
"tracing-log",
|
||||||
|
"tracing-subscriber",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-subscriber"
|
name = "tracing-subscriber"
|
||||||
version = "0.3.16"
|
version = "0.3.16"
|
||||||
|
@ -2105,6 +2220,7 @@ dependencies = [
|
||||||
"tower",
|
"tower",
|
||||||
"tower-http",
|
"tower-http",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
"tracing-opentelemetry",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -27,4 +27,5 @@ toml = "0.7.3"
|
||||||
tower = { version = "0.4.12", features = ["full"] }
|
tower = { version = "0.4.12", features = ["full"] }
|
||||||
tower-http = { version = "0.4.0", features = ["full"] }
|
tower-http = { version = "0.4.0", features = ["full"] }
|
||||||
tracing = "0.1.35"
|
tracing = "0.1.35"
|
||||||
|
tracing-opentelemetry = "0.18.0"
|
||||||
tracing-subscriber = { version = "0.3.11", features = ["fmt"] }
|
tracing-subscriber = { version = "0.3.11", features = ["fmt"] }
|
||||||
|
|
21
Dockerfile
21
Dockerfile
|
@ -1,12 +1,15 @@
|
||||||
FROM rust:slim AS chef
|
FROM rust:slim AS chef
|
||||||
RUN cargo install cargo-chef
|
RUN cargo install cargo-chef
|
||||||
WORKDIR app
|
WORKDIR /app
|
||||||
|
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
## Planner
|
## Planner
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
FROM chef AS planner
|
FROM chef AS planner
|
||||||
COPY . .
|
WORKDIR /app
|
||||||
|
COPY ./Cargo.lock ./
|
||||||
|
COPY ./Cargo.toml ./
|
||||||
|
COPY ./src ./src
|
||||||
RUN cargo chef prepare --recipe-path recipe.json
|
RUN cargo chef prepare --recipe-path recipe.json
|
||||||
|
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
|
@ -33,10 +36,14 @@ RUN adduser \
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY --from=planner /app/recipe.json .
|
COPY --from=planner /app/recipe.json ./
|
||||||
|
|
||||||
RUN cargo chef cook --target x86_64-unknown-linux-musl --release --recipe-path recipe.json
|
RUN cargo chef cook --target x86_64-unknown-linux-musl --release --recipe-path recipe.json
|
||||||
|
|
||||||
COPY . .
|
COPY ./Cargo.lock ./
|
||||||
|
COPY ./Cargo.toml ./
|
||||||
|
|
||||||
|
COPY ./src ./src
|
||||||
|
|
||||||
RUN cargo build --target x86_64-unknown-linux-musl --release
|
RUN cargo build --target x86_64-unknown-linux-musl --release
|
||||||
|
|
||||||
|
@ -53,9 +60,9 @@ WORKDIR /app
|
||||||
|
|
||||||
# Copy our build
|
# Copy our build
|
||||||
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/website ./
|
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/website ./
|
||||||
COPY --from=builder /app/posts ./posts
|
COPY ./static ./static
|
||||||
COPY --from=builder /app/static ./static
|
COPY ./templates ./templates
|
||||||
COPY --from=builder /app/templates ./templates
|
COPY ./posts ./posts
|
||||||
|
|
||||||
EXPOSE 8180
|
EXPOSE 8180
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
+++
|
+++
|
||||||
title="TOML metadata test"
|
title="TOML metadata test"
|
||||||
date=2023-03-25T14:50:25+01:00
|
date=2023-03-26T11:57:00+02:00
|
||||||
+++
|
+++
|
||||||
|
|
||||||
hope it works yay
|
hope it works yay
|
||||||
|
|
||||||
here have a squid miku to test relative paths:
|
here have a squid kid miku to test relative paths:
|
||||||
|
|
||||||
![Squid kid miku](FbHSmoeUUAA2x-m.png)
|
![Squid kid miku](FbHSmoeUUAA2x-m.png)
|
||||||
|
|
||||||
|
modified post test, see if docker skips build using
|
||||||
|
its cache if only a post has changed.
|
||||||
|
|
|
@ -13,8 +13,11 @@ use crate::{State, WebsiteError};
|
||||||
pub mod posts;
|
pub mod posts;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref HIT_COUNTER: IntCounterVec =
|
pub static ref HIT_COUNTER: IntCounterVec = prometheus::register_int_counter_vec!(
|
||||||
prometheus::register_int_counter_vec!(opts!("page_hits", "Number of hits to various pages"), &["page"]).unwrap();
|
opts!("page_hits", "Number of hits to various pages"),
|
||||||
|
&["page"]
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(state))]
|
#[instrument(skip(state))]
|
||||||
|
|
|
@ -26,9 +26,16 @@ pub async fn view(
|
||||||
debug!("viewing post: {slug}");
|
debug!("viewing post: {slug}");
|
||||||
let post = state.posts.get(&slug).ok_or(WebsiteError::NotFound)?;
|
let post = state.posts.get(&slug).ok_or(WebsiteError::NotFound)?;
|
||||||
|
|
||||||
|
if !post.is_published() {
|
||||||
|
warn!("attempted to view post before it has been published!");
|
||||||
|
return Err(WebsiteError::NotFound);
|
||||||
|
}
|
||||||
|
|
||||||
let res = render_post(&state.tera, post).await?;
|
let res = render_post(&state.tera, post).await?;
|
||||||
|
|
||||||
HIT_COUNTER.with_label_values(&[&format!("/posts/{}/", slug)]).inc();
|
HIT_COUNTER
|
||||||
|
.with_label_values(&[&format!("/posts/{}/", slug)])
|
||||||
|
.inc();
|
||||||
Ok(Html(res))
|
Ok(Html(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +47,11 @@ struct IndexContext<'a> {
|
||||||
|
|
||||||
#[instrument(skip(state))]
|
#[instrument(skip(state))]
|
||||||
pub async fn index(Extension(state): Extension<Arc<State>>) -> Result<Html<String>, WebsiteError> {
|
pub async fn index(Extension(state): Extension<Arc<State>>) -> Result<Html<String>, WebsiteError> {
|
||||||
let mut posts = state.posts.values().collect::<Vec<&Post>>();
|
let mut posts = state
|
||||||
|
.posts
|
||||||
|
.values()
|
||||||
|
.filter(|p| p.is_published())
|
||||||
|
.collect::<Vec<&Post>>();
|
||||||
|
|
||||||
posts.sort_by_key(|p| &p.date);
|
posts.sort_by_key(|p| &p.date);
|
||||||
posts.reverse();
|
posts.reverse();
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
|
|
||||||
use axum::{routing::get, Extension, Router, response::Response, body};
|
use axum::{body, response::Response, routing::get, Extension, Router};
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
use hyper::header::CONTENT_TYPE;
|
use hyper::header::CONTENT_TYPE;
|
||||||
use post::Post;
|
use post::Post;
|
||||||
use prometheus::{TextEncoder, Encoder};
|
use prometheus::{Encoder, TextEncoder};
|
||||||
use tera::Tera;
|
use tera::Tera;
|
||||||
use tower_http::{compression::CompressionLayer, trace::TraceLayer};
|
use tower_http::{compression::CompressionLayer, trace::TraceLayer};
|
||||||
use tracing::{instrument, log::*};
|
use tracing::{instrument, log::*};
|
||||||
|
|
|
@ -47,6 +47,14 @@ impl Post {
|
||||||
tags: fm.tags.unwrap_or_default(),
|
tags: fm.tags.unwrap_or_default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_published(&self) -> bool {
|
||||||
|
let now = chrono::offset::Local::now();
|
||||||
|
if let Some(date) = self.date {
|
||||||
|
return date.timestamp() - now.timestamp() <= 0;
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
|
|
Loading…
Reference in a new issue