From 129083b88fe66facf8ec30c25b69db35de2fbb2d Mon Sep 17 00:00:00 2001 From: holly sparkles Date: Fri, 8 Dec 2023 18:23:09 +0100 Subject: [PATCH] feat: add displaying custom logo, logo url, and logo alt text --- src/methods/repo/about.rs | 4 ++++ src/methods/repo/commit.rs | 4 ++++ src/methods/repo/diff.rs | 4 ++++ src/methods/repo/log.rs | 4 ++++ src/methods/repo/refs.rs | 4 ++++ src/methods/repo/summary.rs | 4 ++++ src/methods/repo/tag.rs | 4 ++++ src/methods/repo/tree.rs | 6 ++++++ templates/base.html | 8 +++++++- 9 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/methods/repo/about.rs b/src/methods/repo/about.rs index b597f31..dd526d8 100644 --- a/src/methods/repo/about.rs +++ b/src/methods/repo/about.rs @@ -5,6 +5,7 @@ use axum::{extract::Query, response::IntoResponse, Extension}; use serde::Deserialize; use crate::{ + configuration::AppConfig, git::ReadmeFormat, into_response, methods::{ @@ -26,12 +27,14 @@ pub struct View { repo: Repository, readme: Option<(ReadmeFormat, Arc)>, branch: Option>, + config: AppConfig, } pub async fn handle( Extension(repo): Extension, Extension(RepositoryPath(repository_path)): Extension, Extension(git): Extension>, + Extension(config): Extension, Query(query): Query, ) -> Result { let open_repo = git @@ -44,5 +47,6 @@ pub async fn handle( repo, readme, branch: query.branch, + config, })) } diff --git a/src/methods/repo/commit.rs b/src/methods/repo/commit.rs index e089ab7..eaea9aa 100644 --- a/src/methods/repo/commit.rs +++ b/src/methods/repo/commit.rs @@ -5,6 +5,7 @@ use axum::{extract::Query, response::IntoResponse, Extension}; use serde::Deserialize; use crate::{ + configuration::AppConfig, git::Commit, into_response, methods::{ @@ -22,6 +23,7 @@ pub struct View { pub branch: Option>, pub dl_branch: Arc, pub id: Option, + pub config: AppConfig, } #[derive(Deserialize)] @@ -35,6 +37,7 @@ pub async fn handle( Extension(repo): Extension, Extension(RepositoryPath(repository_path)): Extension, Extension(git): Extension>, + Extension(config): Extension, Query(query): Query, ) -> Result { let open_repo = git.repo(repository_path, query.branch.clone()).await?; @@ -65,5 +68,6 @@ pub async fn handle( branch: query.branch, id: query.id, dl_branch, + config, })) } diff --git a/src/methods/repo/diff.rs b/src/methods/repo/diff.rs index 0a6a6c6..93fad14 100644 --- a/src/methods/repo/diff.rs +++ b/src/methods/repo/diff.rs @@ -9,6 +9,7 @@ use axum::{ }; use crate::{ + configuration::AppConfig, git::Commit, http, into_response, methods::{ @@ -24,12 +25,14 @@ pub struct View { pub repo: Repository, pub commit: Arc, pub branch: Option>, + pub config: AppConfig, } pub async fn handle( Extension(repo): Extension, Extension(RepositoryPath(repository_path)): Extension, Extension(git): Extension>, + Extension(config): Extension, Query(query): Query, ) -> Result { let open_repo = git.repo(repository_path, query.branch.clone()).await?; @@ -43,6 +46,7 @@ pub async fn handle( repo, commit, branch: query.branch, + config, })) } diff --git a/src/methods/repo/log.rs b/src/methods/repo/log.rs index 1882317..eb0b1ef 100644 --- a/src/methods/repo/log.rs +++ b/src/methods/repo/log.rs @@ -6,6 +6,7 @@ use axum::{extract::Query, response::IntoResponse, Extension}; use serde::Deserialize; use crate::{ + configuration::AppConfig, database::schema::{commit::YokedCommit, repository::YokedRepository}, into_response, methods::{ @@ -29,11 +30,13 @@ pub struct View { commits: Vec, next_offset: Option, branch: Option, + config: AppConfig, } pub async fn handle( Extension(repo): Extension, Extension(db): Extension>, + Extension(config): Extension, Query(query): Query, ) -> Result { tokio::task::spawn_blocking(move || { @@ -56,6 +59,7 @@ pub async fn handle( commits, next_offset, branch: query.branch, + config, })) }) .await diff --git a/src/methods/repo/refs.rs b/src/methods/repo/refs.rs index 9ed2814..c94730a 100644 --- a/src/methods/repo/refs.rs +++ b/src/methods/repo/refs.rs @@ -5,6 +5,7 @@ use askama::Template; use axum::{response::IntoResponse, Extension}; use crate::{ + configuration::AppConfig, into_response, methods::{ filters, @@ -18,11 +19,13 @@ pub struct View { repo: Repository, refs: Refs, branch: Option>, + config: AppConfig, } pub async fn handle( Extension(repo): Extension, Extension(db): Extension>, + Extension(config): Extension, ) -> Result { tokio::task::spawn_blocking(move || { let repository = crate::database::schema::repository::Repository::open(&db, &*repo)? @@ -44,6 +47,7 @@ pub async fn handle( repo, refs: Refs { heads, tags }, branch: None, + config, })) }) .await diff --git a/src/methods/repo/summary.rs b/src/methods/repo/summary.rs index d5cd176..24ed16b 100644 --- a/src/methods/repo/summary.rs +++ b/src/methods/repo/summary.rs @@ -5,6 +5,7 @@ use askama::Template; use axum::{response::IntoResponse, Extension}; use crate::{ + configuration::AppConfig, database::schema::{commit::YokedCommit, repository::YokedRepository}, into_response, methods::{ @@ -20,11 +21,13 @@ pub struct View { refs: Refs, commit_list: Vec, branch: Option>, + config: AppConfig, } pub async fn handle( Extension(repo): Extension, Extension(db): Extension>, + Extension(config): Extension, ) -> Result { tokio::task::spawn_blocking(move || { let repository = crate::database::schema::repository::Repository::open(&db, &*repo)? @@ -48,6 +51,7 @@ pub async fn handle( refs: Refs { heads, tags }, commit_list: commits, branch: None, + config, })) }) .await diff --git a/src/methods/repo/tag.rs b/src/methods/repo/tag.rs index 0b7dab4..036c845 100644 --- a/src/methods/repo/tag.rs +++ b/src/methods/repo/tag.rs @@ -5,6 +5,7 @@ use axum::{extract::Query, response::IntoResponse, Extension}; use serde::Deserialize; use crate::{ + configuration::AppConfig, git::DetailedTag, into_response, methods::{ @@ -26,12 +27,14 @@ pub struct View { repo: Repository, tag: DetailedTag, branch: Option>, + config: AppConfig, } pub async fn handle( Extension(repo): Extension, Extension(RepositoryPath(repository_path)): Extension, Extension(git): Extension>, + Extension(config): Extension, Query(query): Query, ) -> Result { let open_repo = git.repo(repository_path, Some(query.name.clone())).await?; @@ -41,5 +44,6 @@ pub async fn handle( repo, tag, branch: Some(query.name), + config, })) } diff --git a/src/methods/repo/tree.rs b/src/methods/repo/tree.rs index 485c2da..6fc8150 100644 --- a/src/methods/repo/tree.rs +++ b/src/methods/repo/tree.rs @@ -8,6 +8,7 @@ use axum::{extract::Query, response::IntoResponse, Extension}; use serde::Deserialize; use crate::{ + configuration::AppConfig, git::{FileWithContent, PathDestination, TreeItem}, into_response, methods::{ @@ -51,6 +52,7 @@ pub struct TreeView { pub items: Vec, pub query: UriQuery, pub branch: Option>, + pub config: AppConfig, } #[derive(Template)] @@ -59,6 +61,7 @@ pub struct FileView { pub repo: Repository, pub file: FileWithContent, pub branch: Option>, + pub config: AppConfig, } pub async fn handle( @@ -66,6 +69,7 @@ pub async fn handle( Extension(RepositoryPath(repository_path)): Extension, Extension(ChildPath(child_path)): Extension, Extension(git): Extension>, + Extension(config): Extension, Query(query): Query, ) -> Result { let open_repo = git.repo(repository_path, query.branch.clone()).await?; @@ -81,6 +85,7 @@ pub async fn handle( items, branch: query.branch.clone(), query, + config, }))) } PathDestination::File(file) if query.raw => ResponseEither::Right(file.content), @@ -89,6 +94,7 @@ pub async fn handle( repo, file, branch: query.branch, + config, }))) } }, diff --git a/templates/base.html b/templates/base.html index d573141..95abc2b 100644 --- a/templates/base.html +++ b/templates/base.html @@ -11,7 +11,13 @@

- 🏡 + + {% if config.logo.is_empty() %} + {{ config.logo_alt }} + {% else %} + {{ config.logo_alt }} + {% endif %} + {% block header -%}{{ config.root_title }}{%- endblock %}

-- libgit2 1.7.2