environment variables for port and filtering posts

This commit is contained in:
Michal Vanko 2024-01-18 20:53:39 +01:00
parent 35e3d595df
commit e0ad3f29ae
3 changed files with 16 additions and 4 deletions

View File

@ -1,3 +1,4 @@
use askama::filters::format;
use axum;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
@ -22,9 +23,10 @@ async fn main() {
// build our application with a single route
let app = router::get_router();
// run our app with hyper, listening globally on port 3080
let listener = tokio::net::TcpListener::bind("0.0.0.0:3080").await.unwrap();
let port = std::option_env!("PORT").unwrap_or("3080");
let addr = format!("0.0.0.0:{}", port);
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
axum::serve(listener, app).await.unwrap();
}
// TODO Port from env variable
// TODO displaying Image from netlify CDN

View File

@ -37,7 +37,7 @@ pub async fn render_post_list(tag: Option<Path<String>>) -> Result<PostListTempl
posts.push(post);
}
let posts = match &tag {
let mut posts = match &tag {
Some(tag) => posts
.into_iter()
.filter(|post| {
@ -52,6 +52,16 @@ pub async fn render_post_list(tag: Option<Path<String>>) -> Result<PostListTempl
None => posts,
};
if std::env::var("TARGET")
.unwrap_or_else(|_| "DEV".to_owned())
.eq("PROD")
{
posts = posts
.into_iter()
.filter(|post| !post.slug.starts_with("dev"))
.collect()
}
Ok(PostListTemplate {
title: "Posts".to_owned(),
posts,

View File

@ -19,4 +19,4 @@
{% endfor %}
</ul>
{# <ArticlePreviewList {...data} segment="blog" /> #} {% endblock %}
{% endblock %}