Set up base template
This commit is contained in:
parent
feb73c96c4
commit
e17483b4d6
6 changed files with 73 additions and 44 deletions
|
|
@ -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"
|
|
||||||
}
|
|
||||||
|
|
@ -8,13 +8,23 @@ use tracing::{debug, info};
|
||||||
mod default {
|
mod default {
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
pub fn repo_name() -> String {
|
||||||
|
"Local repo".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn repo_update_delay() -> Duration {
|
pub fn repo_update_delay() -> Duration {
|
||||||
Duration::from_secs(60)
|
Duration::from_secs(60)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn web_base() -> String {
|
||||||
|
"".to_string()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct Repo {
|
pub struct Repo {
|
||||||
|
#[serde(default = "default::repo_name")]
|
||||||
|
pub name: String,
|
||||||
#[serde(default = "default::repo_update_delay", with = "humantime_serde")]
|
#[serde(default = "default::repo_update_delay", with = "humantime_serde")]
|
||||||
pub update_delay: Duration,
|
pub update_delay: Duration,
|
||||||
}
|
}
|
||||||
|
|
@ -22,14 +32,45 @@ pub struct Repo {
|
||||||
impl Default for Repo {
|
impl Default for Repo {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
name: default::repo_name(),
|
||||||
update_delay: default::repo_update_delay(),
|
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)]
|
#[derive(Debug, Default, Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub repo: Repo,
|
pub repo: Repo,
|
||||||
|
pub web: Web,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use axum::{extract::State, response::IntoResponse};
|
use axum::{extract::State, response::IntoResponse};
|
||||||
use sqlx::SqlitePool;
|
|
||||||
|
use crate::config::Config;
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "index.html")]
|
#[template(path = "index.html")]
|
||||||
struct IndexTemplate {
|
struct IndexTemplate {
|
||||||
number: i32,
|
base: String,
|
||||||
|
repo_name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get(State(db): State<SqlitePool>) -> super::Result<impl IntoResponse> {
|
pub async fn get(State(config): State<&'static Config>) -> super::Result<impl IntoResponse> {
|
||||||
let result = sqlx::query!("SELECT column1 AS number FROM (VALUES (1))")
|
Ok(IndexTemplate {
|
||||||
.fetch_one(&db)
|
base: config.web.base(),
|
||||||
.await?;
|
repo_name: config.repo.name(),
|
||||||
|
})
|
||||||
let number = result.number;
|
|
||||||
Ok(IndexTemplate { number })
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
0
static/base.css
Normal file
0
static/base.css
Normal file
19
templates/base.html
Normal file
19
templates/base.html
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>{% block title %}{% endblock %}</title>
|
||||||
|
<link rel="icon" href="/logo.svg">
|
||||||
|
<link rel="stylesheet" href="{{ base }}/base.css" />
|
||||||
|
{% block head %}{% endblock %}
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<nav>
|
||||||
|
<a href="{{ base }}/"><img src="{{ base }}/logo.svg"> {{ repo_name }}</a>
|
||||||
|
</nav>
|
||||||
|
{% block body %}{% endblock %}
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
|
@ -1,16 +1,5 @@
|
||||||
<!DOCTYPE html>
|
{% extends "base.html" %}
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
{% block body %}
|
||||||
<meta charset="utf-8" />
|
<h1>{{ repo_name }}</h1>
|
||||||
<title>index</title>
|
{% endblock %}
|
||||||
<script type="module" src="main.js"></script>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<h1>Hello</h1>
|
|
||||||
<p>The number from the DB is {{ number }}, yay!</p>
|
|
||||||
<button id="button">Click me!</button>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue