diff --git a/.gitignore b/.gitignore index 3399b78..807d687 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ # Devfiles .devfiles/bin/**/* +public/assets/** +public/.vite #### -- TEMPLATES BEGIN -- #### @@ -109,7 +111,6 @@ dist # vuepress v2.x temp and cache directory .temp -.cache # Docusaurus cache and generated files .docusaurus @@ -145,4 +146,3 @@ dist # Added by cargo /target -.env diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/QuickJinja_project.xml b/.idea/QuickJinja_project.xml new file mode 100644 index 0000000..76760d4 --- /dev/null +++ b/.idea/QuickJinja_project.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/biome.xml b/.idea/biome.xml new file mode 100644 index 0000000..8fa01ec --- /dev/null +++ b/.idea/biome.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/.idea/bun.xml b/.idea/bun.xml new file mode 100644 index 0000000..56b40f0 --- /dev/null +++ b/.idea/bun.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/compendium.iml b/.idea/compendium.iml new file mode 100644 index 0000000..cf84ae4 --- /dev/null +++ b/.idea/compendium.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..9567d63 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + postgresql + true + org.postgresql.Driver + jdbc:postgresql://localhost/compendium + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/dictionaries/project.xml b/.idea/dictionaries/project.xml new file mode 100644 index 0000000..5f28118 --- /dev/null +++ b/.idea/dictionaries/project.xml @@ -0,0 +1,8 @@ + + + + endblock + htmx + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..fefa8f5 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..99958cd --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Dev.xml b/.idea/runConfigurations/Dev.xml new file mode 100644 index 0000000..a76dce5 --- /dev/null +++ b/.idea/runConfigurations/Dev.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Run_with_vite.xml b/.idea/runConfigurations/Run_with_vite.xml new file mode 100644 index 0000000..e695ac0 --- /dev/null +++ b/.idea/runConfigurations/Run_with_vite.xml @@ -0,0 +1,25 @@ + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Vite_Dev_Server.xml b/.idea/runConfigurations/Vite_Dev_Server.xml new file mode 100644 index 0000000..63cf301 --- /dev/null +++ b/.idea/runConfigurations/Vite_Dev_Server.xml @@ -0,0 +1,16 @@ + + + + + + + + + + {% if is_production == false %} + + {% endif %} + + - {% block title %}Axum web service!{% endblock %} + {% block title %}Axum web service!{% endblock %} - + - -
- {% include "partials/header.html" ignore missing %} -
-
- {% block content %}{% endblock %} -
-
- {% include "partials/footer.html" ignore missing %} -
- + +
+ {% include "partials/header.html" ignore missing %} +
+
+ {% block content %}{% endblock %} +
+
+ {% include "partials/footer.html" ignore missing %} +
+ diff --git a/frontend/templates/partials/header.html b/frontend/templates/partials/header.html index e69de29..e6060c8 100644 --- a/frontend/templates/partials/header.html +++ b/frontend/templates/partials/header.html @@ -0,0 +1,35 @@ + diff --git a/package.json b/package.json index 5fbe37b..0988d01 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,26 @@ { - "name": "compendium", - "module": "index.ts", - "version": "0.1.0", - "devDependencies": { - "@alecodes/tmpl-build-and-load": "^0.1.3", - "@types/bun": "latest" - }, - "peerDependencies": { - "typescript": "^5.0.0" - }, - "type": "module", - "dependencies": { - "@mini-strap/core": "^0.1.2", - "@picocss/pico": "^2.1.1", - "htmx.org": "2.0.4" - } + "name": "compendium", + "module": "index.ts", + "version": "0.1.1", + "scripts": { + "dev": "vite", + "build": "vite build" + }, + "devDependencies": { + "@alecodes/tmpl-build-and-load": "^0.1.3", + "@biomejs/biome": "1.9.4", + "@types/bun": "^1.2.10", + "sass-embedded": "^1.86.3", + "vite": "^6.3.1" + }, + "peerDependencies": { + "typescript": "^5.7.3" + }, + "type": "module", + "dependencies": { + "@mini-strap/core": "^0.1.2", + "@picocss/pico": "^2.1.1", + "feather-icons": "^4.29.2", + "htmx.org": "2.0.4" + } } diff --git a/public/.gitkeep b/public/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/public/assets/.gitkeep b/public/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/config.rs b/src/config.rs index 7fde8e0..daff0d9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -40,12 +40,12 @@ impl Default for DBConfig { } impl DBConfig { - pub fn generate_db_string(&self, ofuscate: bool) -> Result { + pub fn generate_db_string(&self, obfuscate: bool) -> Result { if let Some(value) = &self.string { return Ok(value.clone()); } - let db_password = if ofuscate { + let db_password = if obfuscate { let mut db_password = self .password .clone() @@ -84,6 +84,7 @@ impl DBConfig { pub struct Config { pub db: DBConfig, pub addr: SocketAddr, + pub public_dir: PathBuf, } impl Default for Config { @@ -91,6 +92,7 @@ impl Default for Config { Config { db: DBConfig::default(), addr: "0.0.0.0:3000".parse().unwrap(), + public_dir: PathBuf::from("public"), } } } diff --git a/src/error.rs b/src/error.rs index 5bef9fb..a1c55bf 100644 --- a/src/error.rs +++ b/src/error.rs @@ -22,6 +22,9 @@ pub enum Error { #[error(transparent)] Env(#[from] std::env::VarError), + #[error(transparent)] + JsonParse(#[from] serde_json::Error), + #[error(transparent)] Template(#[from] minijinja::Error), diff --git a/src/lib.rs b/src/lib.rs index 109a915..5ba886b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,34 +1,23 @@ +pub mod static_assets; pub mod config; mod error; pub mod router; +use crate::static_assets::Assets; use axum::extract::FromRef; pub use error::{Error, Result, ResultTemplate}; -use minijinja::{Environment, Template}; -use serde::{Deserialize, Serialize}; pub type Tx = axum_sqlx_tx::Tx; pub type TxState = axum_sqlx_tx::State; -#[derive(Serialize, Deserialize, Debug)] -pub struct Link { - pub path: String, - pub text: String, - pub subpages: Vec, -} - #[derive(Clone, FromRef)] pub struct AppState { - tmpl_env: Environment<'static>, - tx: TxState, + pub assets: Assets, + pub tx: TxState, } impl AppState { - pub fn new(tmpl_env: Environment<'static>, tx: TxState) -> Self { - AppState { tmpl_env, tx } - } - - pub fn get_template(&self, name: &str) -> Result