Añade carga de archivos estáticos desde directorio
Con el ajuste de configuración "dev.static_files" se puede elegir entre integrar los archivos estáticos en el binario ejecutable (por defecto) o servirlos desde su propio directorio. Esto facilita el desarrollo al no tener que compilar cada vez que se modifican estos archivos.
This commit is contained in:
parent
3ee5859eae
commit
e3f592b3b0
18 changed files with 93 additions and 71 deletions
|
|
@ -1,12 +1,12 @@
|
||||||
[app]
|
[app]
|
||||||
name = "Drust"
|
name = "Drust"
|
||||||
description = """\
|
description = """\
|
||||||
A modern Content Management System for sharing the world.\
|
A modern web Content Management System to share your world.\
|
||||||
"""
|
"""
|
||||||
language = "es-ES"
|
|
||||||
#theme = "Aliner"
|
#theme = "Aliner"
|
||||||
#theme = "Minimal"
|
#theme = "Minimal"
|
||||||
theme = "Bootsier"
|
theme = "Bootsier"
|
||||||
|
language = "es-ES"
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
db_type = "mysql"
|
db_type = "mysql"
|
||||||
|
|
@ -16,3 +16,6 @@ db_pass = "DrU__#3T"
|
||||||
|
|
||||||
[log]
|
[log]
|
||||||
tracing = "Info,sqlx::query=Warn"
|
tracing = "Info,sqlx::query=Warn"
|
||||||
|
|
||||||
|
[dev]
|
||||||
|
#static_files = "pagetop/static"
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ authors = [
|
||||||
"Manuel Cillero <manuel@cillero.es>"
|
"Manuel Cillero <manuel@cillero.es>"
|
||||||
]
|
]
|
||||||
description = """\
|
description = """\
|
||||||
A modern Content Management System for sharing the world.\
|
A modern web Content Management System to share your world.\
|
||||||
"""
|
"""
|
||||||
homepage = "https://suitepro.cillero.es/projects/drust"
|
homepage = "https://suitepro.cillero.es/projects/drust"
|
||||||
repository = "https://gitlab.com/manuelcillero/drust"
|
repository = "https://gitlab.com/manuelcillero/drust"
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,10 @@ authors = [
|
||||||
"Manuel Cillero <manuel@cillero.es>"
|
"Manuel Cillero <manuel@cillero.es>"
|
||||||
]
|
]
|
||||||
description = """\
|
description = """\
|
||||||
Allows content to be submitted to the site and displayed on pages.\
|
...\
|
||||||
"""
|
"""
|
||||||
homepage = "https://suitepro.cillero.es/projects/drust"
|
homepage = "https://suitepro.cillero.es/projects/pagetop"
|
||||||
repository = "https://gitlab.com/manuelcillero/drust"
|
repository = "https://gitlab.com/manuelcillero/pagetop"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
pagetop = { path = "../pagetop" }
|
pagetop = { path = "../pagetop" }
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ authors = [
|
||||||
description = """\
|
description = """\
|
||||||
Allows content to be submitted to the site and displayed on pages.\
|
Allows content to be submitted to the site and displayed on pages.\
|
||||||
"""
|
"""
|
||||||
homepage = "https://suitepro.cillero.es/projects/drust"
|
homepage = "https://suitepro.cillero.es/projects/pagetop"
|
||||||
repository = "https://gitlab.com/manuelcillero/drust"
|
repository = "https://gitlab.com/manuelcillero/pagetop"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
pagetop = { path = "../pagetop" }
|
pagetop = { path = "../pagetop" }
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,10 @@ authors = [
|
||||||
description = """\
|
description = """\
|
||||||
Allows content to be submitted to the site and displayed on pages.\
|
Allows content to be submitted to the site and displayed on pages.\
|
||||||
"""
|
"""
|
||||||
homepage = "https://suitepro.cillero.es/projects/drust"
|
homepage = "https://suitepro.cillero.es/projects/pagetop"
|
||||||
repository = "https://gitlab.com/manuelcillero/drust"
|
repository = "https://gitlab.com/manuelcillero/pagetop"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
pagetop = { path = "../pagetop" }
|
pagetop = { path = "../pagetop" }
|
||||||
|
sea-orm = { version = "0.6.0" }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|
||||||
[dependencies.sea-orm]
|
|
||||||
version = "0.6.0"
|
|
||||||
features = ["debug-print", "macros"]
|
|
||||||
default-features = false
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
module_fullname = Usuario
|
module_fullname = Usuario
|
||||||
module_description = Gestion el registro de usuarios y el sistema de accesos.
|
module_description = Gestiona el registro de usuarios y el sistema de accesos.
|
||||||
|
|
||||||
username = Nombre de usuario
|
username = Nombre de usuario
|
||||||
password = Contraseña
|
password = Contraseña
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,8 @@ authors = [
|
||||||
"Manuel Cillero <manuel@cillero.es>"
|
"Manuel Cillero <manuel@cillero.es>"
|
||||||
]
|
]
|
||||||
description = """\
|
description = """\
|
||||||
PageTop es un proyecto personal para aprender Rust. Incluye algunos de los \
|
PageTop is an opinionated framework for using the most stable and popular \
|
||||||
crates más estables y populares para desarrollar soluciones web modulares, \
|
Rust packages to build modular, extensible and configurable web solutions.\
|
||||||
extensibles y configurables. También es un sistema para la gestión de \
|
|
||||||
contenidos web.\
|
|
||||||
"""
|
"""
|
||||||
homepage = "https://suitepro.cillero.es/projects/pagetop"
|
homepage = "https://suitepro.cillero.es/projects/pagetop"
|
||||||
repository = "https://gitlab.com/manuelcillero/pagetop"
|
repository = "https://gitlab.com/manuelcillero/pagetop"
|
||||||
|
|
@ -44,6 +42,7 @@ unic-langid = "0.9.0"
|
||||||
|
|
||||||
actix-web = "3.3.3"
|
actix-web = "3.3.3"
|
||||||
actix-web-static-files = "3.0.5"
|
actix-web-static-files = "3.0.5"
|
||||||
|
actix-files = "0.4.1"
|
||||||
|
|
||||||
maud = { version = "0.23.0", features = ["actix-web"] }
|
maud = { version = "0.23.0", features = ["actix-web"] }
|
||||||
sycamore = { version = "0.7.1", features = ["ssr"] }
|
sycamore = { version = "0.7.1", features = ["ssr"] }
|
||||||
|
|
@ -62,9 +61,6 @@ features = ["debug-print", "migration"]
|
||||||
default-features = false
|
default-features = false
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
tokio = { version = "1.17.0", features = ["macros", "rt-multi-thread"] }
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
mysql = ["sea-orm", "sea-schema", "sea-orm/sqlx-mysql"]
|
mysql = ["sea-orm", "sea-schema", "sea-orm/sqlx-mysql"]
|
||||||
|
|
@ -74,5 +70,8 @@ sqlite = ["sea-orm", "sea-schema", "sea-orm/sqlx-sqlite"]
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
actix-web-static-files = "3.0.5"
|
actix-web-static-files = "3.0.5"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
tokio = { version = "1.17.0", features = ["macros", "rt-multi-thread"] }
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "pagetop"
|
name = "pagetop"
|
||||||
|
|
|
||||||
|
|
@ -8,24 +8,20 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies.pagetop]
|
[dependencies.pagetop]
|
||||||
path = "../pagetop"
|
path = "../pagetop"
|
||||||
# Opcional. Por defecto se puede usar PageTop sin base de datos.
|
# PageTop por defecto no requiere base de datos. Hay que habilitarla:
|
||||||
features = ["mysql"]
|
features = ["mysql"]
|
||||||
# features = ["postgres"]
|
# features = ["postgres"]
|
||||||
# features = ["sqlite"]
|
# features = ["sqlite"]
|
||||||
# PageTop puede dar soporte a todas las bases de datos.
|
# PageTop puede dar soporte a todas las bases de datos:
|
||||||
# features = ["mysql", "postgres", "sqlite"]
|
# features = ["mysql", "postgres", "sqlite"]
|
||||||
# Sólo cuando no se usen las características predeterminadas.
|
# En estos casos hay que deshabilitar las características predeterminadas:
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Requerido.
|
|
||||||
actix-web = "3.3.3"
|
actix-web = "3.3.3"
|
||||||
# Opcional. Sólo si se usa la macro html!.
|
# Opcional. Sólo si se usa la macro html!:
|
||||||
maud = { version = "0.23.0" }
|
maud = { version = "0.23.0" }
|
||||||
# Opcional. Si se requiere serialización de estructuras de datos.
|
# Opcional. Sólo si se usa base de datos:
|
||||||
|
sea-orm = { version = "0.6.0" }
|
||||||
|
# Opcional. Para la serialización de estructuras de datos:
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|
||||||
[dependencies.sea-orm]
|
|
||||||
version = "0.6.0"
|
|
||||||
features = ["debug-print", "macros"]
|
|
||||||
default-features = false
|
|
||||||
|
|
|
||||||
|
|
@ -6,24 +6,11 @@ edition = "2021"
|
||||||
# Ver más claves y sus definiciones en
|
# Ver más claves y sus definiciones en
|
||||||
# https://doc.rust-lang.org/cargo/reference/manifest.html
|
# https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies.pagetop]
|
|
||||||
path = "../pagetop"
|
|
||||||
# Opcional. Por defecto se puede usar PageTop sin base de datos.
|
|
||||||
features = ["mysql"]
|
|
||||||
# features = ["postgres"]
|
|
||||||
# features = ["sqlite"]
|
|
||||||
# PageTop puede dar soporte a todas las bases de datos.
|
|
||||||
# features = ["mysql", "postgres", "sqlite"]
|
|
||||||
# Sólo cuando no se usen las características predeterminadas.
|
|
||||||
default-features = false
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Opcional. Sólo si se usa la macro html!.
|
pagetop = { path = "../pagetop" }
|
||||||
|
# Opcional. Sólo si se usa la macro html!:
|
||||||
maud = { version = "0.23.0" }
|
maud = { version = "0.23.0" }
|
||||||
# Opcional. Si se requiere serialización de estructuras de datos.
|
# Opcional. Sólo si se usa base de datos:
|
||||||
|
sea-orm = { version = "0.6.0" }
|
||||||
|
# Opcional. Para la serialización de estructuras de datos:
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|
||||||
[dependencies.sea-orm]
|
|
||||||
version = "0.6.0"
|
|
||||||
features = ["debug-print", "macros"]
|
|
||||||
default-features = false
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ fn main() {
|
||||||
Path::new(env::var("OUT_DIR").unwrap().as_str())
|
Path::new(env::var("OUT_DIR").unwrap().as_str())
|
||||||
.join("theme.rs")
|
.join("theme.rs")
|
||||||
)
|
)
|
||||||
.with_generated_fn("assets")
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
@ -18,7 +17,6 @@ fn main() {
|
||||||
Path::new(env::var("OUT_DIR").unwrap().as_str())
|
Path::new(env::var("OUT_DIR").unwrap().as_str())
|
||||||
.join("aliner.rs")
|
.join("aliner.rs")
|
||||||
)
|
)
|
||||||
.with_generated_fn("assets")
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
@ -27,7 +25,6 @@ fn main() {
|
||||||
Path::new(env::var("OUT_DIR").unwrap().as_str())
|
Path::new(env::var("OUT_DIR").unwrap().as_str())
|
||||||
.join("bootsier.rs")
|
.join("bootsier.rs")
|
||||||
)
|
)
|
||||||
.with_generated_fn("assets")
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,3 +43,11 @@ max_pool_size = 5
|
||||||
# Configuración del servidor web.
|
# Configuración del servidor web.
|
||||||
bind_address = "localhost"
|
bind_address = "localhost"
|
||||||
bind_port = 8088
|
bind_port = 8088
|
||||||
|
|
||||||
|
[dev]
|
||||||
|
# Los archivos estáticos requeridos por temas y componentes incluidos en PageTop
|
||||||
|
# se integran de manera predeterminada en el binario ejecutable. Sin embargo, es
|
||||||
|
# útil servir estos archivos desde su propio directorio durante el desarrollo ya
|
||||||
|
# que no requiere compilar cada vez que se modifican. En este caso, normalmente,
|
||||||
|
# basta con indicar el directorio "pagetop/static".
|
||||||
|
static_files = ""
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,7 @@ impl ThemeTrait for AlinerTheme {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn configure_theme(&self, cfg: &mut app::web::ServiceConfig) {
|
fn configure_theme(&self, cfg: &mut app::web::ServiceConfig) {
|
||||||
cfg.service(actix_web_static_files::ResourceFiles::new(
|
theme_static_files!(cfg, "/aliner");
|
||||||
"/aliner",
|
|
||||||
assets()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn before_render_page(&self, page: &mut Page) {
|
fn before_render_page(&self, page: &mut Page) {
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,7 @@ impl ThemeTrait for BootsierTheme {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn configure_theme(&self, cfg: &mut app::web::ServiceConfig) {
|
fn configure_theme(&self, cfg: &mut app::web::ServiceConfig) {
|
||||||
cfg.service(actix_web_static_files::ResourceFiles::new(
|
theme_static_files!(cfg, "/bootsier");
|
||||||
"/bootsier",
|
|
||||||
assets()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn before_render_page(&self, page: &mut Page) {
|
fn before_render_page(&self, page: &mut Page) {
|
||||||
|
|
@ -61,7 +58,7 @@ impl ThemeTrait for BootsierTheme {
|
||||||
div class="jumbotron" {
|
div class="jumbotron" {
|
||||||
div class="media" {
|
div class="media" {
|
||||||
img
|
img
|
||||||
src="/bootsier/images/caution.png"
|
src="/static/bootsier/images/caution.png"
|
||||||
class="mr-4"
|
class="mr-4"
|
||||||
style="width: 20%; max-width: 188px"
|
style="width: 20%; max-width: 188px"
|
||||||
alt="Caution!";
|
alt="Caution!";
|
||||||
|
|
|
||||||
|
|
@ -104,12 +104,18 @@ pub struct Webserver {
|
||||||
pub bind_port : u16,
|
pub bind_port : u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct Dev {
|
||||||
|
pub static_files : String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
pub app : App,
|
pub app : App,
|
||||||
pub log : Log,
|
pub log : Log,
|
||||||
pub database : Database,
|
pub database : Database,
|
||||||
pub webserver : Webserver,
|
pub webserver : Webserver,
|
||||||
|
pub dev : Dev,
|
||||||
}
|
}
|
||||||
|
|
||||||
config_map!(r#"
|
config_map!(r#"
|
||||||
|
|
@ -144,5 +150,8 @@ Ajustes globales y valores predeterminados para las secciones *\[app\]*,
|
||||||
|
|
||||||
// [webserver]
|
// [webserver]
|
||||||
"webserver.bind_address" => "localhost",
|
"webserver.bind_address" => "localhost",
|
||||||
"webserver.bind_port" => 8088
|
"webserver.bind_port" => 8088,
|
||||||
|
|
||||||
|
// [dev]
|
||||||
|
"dev.static_files" => ""
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{Lazy, app, base, run_now, trace};
|
use crate::{Lazy, app, base, run_now, theme_static_files, trace};
|
||||||
use crate::config::SETTINGS;
|
use crate::config::SETTINGS;
|
||||||
use crate::db::migration::*;
|
use crate::db::migration::*;
|
||||||
use crate::module::*;
|
use crate::module::*;
|
||||||
|
|
@ -84,10 +84,7 @@ pub fn theme_by_name(name: &str) -> Option<&'static dyn ThemeTrait> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn themes(cfg: &mut app::web::ServiceConfig) {
|
pub fn themes(cfg: &mut app::web::ServiceConfig) {
|
||||||
cfg.service(actix_web_static_files::ResourceFiles::new(
|
theme_static_files!(cfg, "/theme");
|
||||||
"/theme",
|
|
||||||
assets()
|
|
||||||
));
|
|
||||||
|
|
||||||
for t in THEMES.read().unwrap().iter() {
|
for t in THEMES.read().unwrap().iter() {
|
||||||
t.configure_theme(cfg);
|
t.configure_theme(cfg);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
//! Re-exporta recursos comunes.
|
//! Re-exporta recursos comunes.
|
||||||
|
|
||||||
pub use crate::args;
|
// Macros.
|
||||||
|
pub use crate::{
|
||||||
|
args,
|
||||||
|
theme_static_files,
|
||||||
|
};
|
||||||
|
|
||||||
pub use crate::config::SETTINGS;
|
pub use crate::config::SETTINGS;
|
||||||
pub use crate::trace;
|
pub use crate::trace;
|
||||||
pub use crate::localize;
|
pub use crate::localize;
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,24 @@ macro_rules! args {
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! theme_static_files {
|
||||||
|
( $cfg:ident, $dir:expr ) => {{
|
||||||
|
let static_files = &$crate::config::SETTINGS.dev.static_files;
|
||||||
|
if static_files.is_empty() {
|
||||||
|
$cfg.service(actix_web_static_files::ResourceFiles::new(
|
||||||
|
$dir,
|
||||||
|
generate()
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
$cfg.service(actix_files::Files::new(
|
||||||
|
$dir,
|
||||||
|
&[static_files, $dir].join("")
|
||||||
|
).show_files_listing());
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
pub fn valid_id(id: &str) -> Option<String> {
|
pub fn valid_id(id: &str) -> Option<String> {
|
||||||
let id = id.trim().replace(" ", "_").to_lowercase();
|
let id = id.trim().replace(" ", "_").to_lowercase();
|
||||||
match id.is_empty() {
|
match id.is_empty() {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,16 @@
|
||||||
html {
|
html {
|
||||||
background-color: white;
|
background-color: white;
|
||||||
|
padding: 1px 3px;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
padding: 1px 3px;
|
||||||
|
}
|
||||||
|
div {
|
||||||
|
padding: 1px 3px;
|
||||||
|
margin: 5px;
|
||||||
|
}
|
||||||
|
h1, h2, h3, h4,h5, h6, p {
|
||||||
|
background-color: snow;
|
||||||
}
|
}
|
||||||
* * {
|
* * {
|
||||||
outline: 5px solid rgba(255,0,0,.1);
|
outline: 5px solid rgba(255,0,0,.1);
|
||||||
|
|
@ -21,7 +32,9 @@ html {
|
||||||
background: #faa;
|
background: #faa;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
font: normal normal 400 10px/1.2 monospace;
|
font: normal normal 400 10px/1.2 monospace;
|
||||||
|
vertical-align: middle;
|
||||||
padding: 1px 3px;
|
padding: 1px 3px;
|
||||||
|
margin: 0 3px;
|
||||||
}
|
}
|
||||||
*::before {
|
*::before {
|
||||||
content: "(";
|
content: "(";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue