Group base template parameters
This commit is contained in:
parent
729b3ba672
commit
90a446a576
7 changed files with 46 additions and 33 deletions
|
|
@ -40,12 +40,6 @@ impl Default for Repo {
|
|||
}
|
||||
}
|
||||
|
||||
impl Repo {
|
||||
pub fn name(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Web {
|
||||
#[serde(default = "default::web_base")]
|
||||
|
|
|
|||
27
src/web.rs
27
src/web.rs
|
|
@ -5,7 +5,32 @@ mod r#static;
|
|||
|
||||
use axum::{routing::get, Router, Server};
|
||||
|
||||
use crate::{somehow, state::AppState};
|
||||
use crate::{config::Config, somehow, state::AppState};
|
||||
|
||||
pub enum Tab {
|
||||
Index,
|
||||
Commit,
|
||||
}
|
||||
|
||||
pub struct Base {
|
||||
root: String,
|
||||
repo_name: String,
|
||||
current: String,
|
||||
}
|
||||
|
||||
impl Base {
|
||||
pub fn new(config: &Config, tab: Tab) -> Self {
|
||||
let current = match tab {
|
||||
Tab::Index => "index",
|
||||
Tab::Commit => "commit",
|
||||
};
|
||||
Self {
|
||||
root: config.web.base(),
|
||||
repo_name: config.repo.name.clone(),
|
||||
current: current.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run(state: AppState) -> somehow::Result<()> {
|
||||
// TODO Add text body to body-less status codes
|
||||
|
|
|
|||
|
|
@ -3,18 +3,16 @@ use axum::{extract::State, response::IntoResponse};
|
|||
|
||||
use crate::{config::Config, somehow};
|
||||
|
||||
use super::{Base, Tab};
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "commit.html")]
|
||||
struct CommitTemplate {
|
||||
base: String,
|
||||
repo_name: String,
|
||||
current: &'static str,
|
||||
base: Base,
|
||||
}
|
||||
|
||||
pub async fn get(State(config): State<&'static Config>) -> somehow::Result<impl IntoResponse> {
|
||||
Ok(CommitTemplate {
|
||||
base: config.web.base(),
|
||||
repo_name: config.repo.name(),
|
||||
current: "commit",
|
||||
base: Base::new(config, Tab::Commit),
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ use sqlx::SqlitePool;
|
|||
|
||||
use crate::{config::Config, somehow, util};
|
||||
|
||||
use super::{Base, Tab};
|
||||
|
||||
struct Commit {
|
||||
hash: String,
|
||||
short: String,
|
||||
|
|
@ -28,9 +30,7 @@ impl Commit {
|
|||
#[derive(Template)]
|
||||
#[template(path = "commit_hash.html")]
|
||||
struct CommitIdTemplate {
|
||||
base: String,
|
||||
repo_name: String,
|
||||
current: &'static str,
|
||||
base: Base,
|
||||
hash: String,
|
||||
author: String,
|
||||
author_date: String,
|
||||
|
|
@ -98,9 +98,7 @@ pub async fn get(
|
|||
.await?;
|
||||
|
||||
Ok(CommitIdTemplate {
|
||||
base: config.web.base(),
|
||||
repo_name: config.repo.name(),
|
||||
current: "commit",
|
||||
base: Base::new(config, Tab::Commit),
|
||||
hash: commit.hash,
|
||||
author: commit.author,
|
||||
author_date: util::format_time(commit.author_date)?,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ use sqlx::SqlitePool;
|
|||
|
||||
use crate::{config::Config, somehow, util};
|
||||
|
||||
use super::{Base, Tab};
|
||||
|
||||
struct Ref {
|
||||
name: String,
|
||||
hash: String,
|
||||
|
|
@ -15,9 +17,7 @@ struct Ref {
|
|||
#[derive(Template)]
|
||||
#[template(path = "index.html")]
|
||||
struct IndexTemplate {
|
||||
base: String,
|
||||
repo_name: String,
|
||||
current: &'static str,
|
||||
base: Base,
|
||||
tracked_refs: Vec<Ref>,
|
||||
untracked_refs: Vec<Ref>,
|
||||
}
|
||||
|
|
@ -54,9 +54,7 @@ pub async fn get(
|
|||
}
|
||||
|
||||
Ok(IndexTemplate {
|
||||
base: config.web.base(),
|
||||
repo_name: config.repo.name(),
|
||||
current: "index",
|
||||
base: Base::new(config, Tab::Index),
|
||||
tracked_refs,
|
||||
untracked_refs,
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue