diff --git a/.sqlx/query-fd70371b89698aa43665bd7bb12c462a111e5bd7c6aedc0fb74f551dcee71df0.json b/.sqlx/query-fd70371b89698aa43665bd7bb12c462a111e5bd7c6aedc0fb74f551dcee71df0.json deleted file mode 100644 index 65b9128..0000000 --- a/.sqlx/query-fd70371b89698aa43665bd7bb12c462a111e5bd7c6aedc0fb74f551dcee71df0.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "db_name": "SQLite", - "query": "SELECT column1 AS number FROM (VALUES (1))", - "describe": { - "columns": [ - { - "name": "number", - "ordinal": 0, - "type_info": "Int" - } - ], - "parameters": { - "Right": 0 - }, - "nullable": [ - false - ] - }, - "hash": "fd70371b89698aa43665bd7bb12c462a111e5bd7c6aedc0fb74f551dcee71df0" -} diff --git a/src/config.rs b/src/config.rs index 2f59d7b..c343455 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,13 +8,23 @@ use tracing::{debug, info}; mod default { use std::time::Duration; + pub fn repo_name() -> String { + "Local repo".to_string() + } + pub fn repo_update_delay() -> Duration { Duration::from_secs(60) } + + pub fn web_base() -> String { + "".to_string() + } } #[derive(Debug, Deserialize)] pub struct Repo { + #[serde(default = "default::repo_name")] + pub name: String, #[serde(default = "default::repo_update_delay", with = "humantime_serde")] pub update_delay: Duration, } @@ -22,14 +32,45 @@ pub struct Repo { impl Default for Repo { fn default() -> Self { Self { + name: default::repo_name(), update_delay: default::repo_update_delay(), } } } +impl Repo { + pub fn name(&self) -> String { + self.name.clone() + } +} + +#[derive(Debug, Deserialize)] +pub struct Web { + #[serde(default = "default::web_base")] + pub base: String, +} + +impl Default for Web { + fn default() -> Self { + Self { + base: default::web_base(), + } + } +} + +impl Web { + pub fn base(&self) -> String { + self.base + .strip_suffix('/') + .unwrap_or(&self.base) + .to_string() + } +} + #[derive(Debug, Default, Deserialize)] pub struct Config { pub repo: Repo, + pub web: Web, } impl Config { diff --git a/src/web/index.rs b/src/web/index.rs index 2f402a9..610a94e 100644 --- a/src/web/index.rs +++ b/src/web/index.rs @@ -1,18 +1,18 @@ use askama::Template; use axum::{extract::State, response::IntoResponse}; -use sqlx::SqlitePool; + +use crate::config::Config; #[derive(Template)] #[template(path = "index.html")] struct IndexTemplate { - number: i32, + base: String, + repo_name: String, } -pub async fn get(State(db): State) -> super::Result { - let result = sqlx::query!("SELECT column1 AS number FROM (VALUES (1))") - .fetch_one(&db) - .await?; - - let number = result.number; - Ok(IndexTemplate { number }) +pub async fn get(State(config): State<&'static Config>) -> super::Result { + Ok(IndexTemplate { + base: config.web.base(), + repo_name: config.repo.name(), + }) } diff --git a/static/base.css b/static/base.css new file mode 100644 index 0000000..e69de29 diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..ed94605 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,19 @@ + + + + + + {% block title %}{% endblock %} + + + {% block head %}{% endblock %} + + + + + {% block body %}{% endblock %} + + + diff --git a/templates/index.html b/templates/index.html index 96b7dc7..1cfabbf 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,16 +1,5 @@ - - +{% extends "base.html" %} - - - index - - - - -

Hello

-

The number from the DB is {{ number }}, yay!

- - - - +{% block body %} +

{{ repo_name }}

+{% endblock %}