Mejora gestión de archivos estáticos en el binario

This commit is contained in:
Manuel Cillero 2022-08-05 00:05:26 +02:00
parent c0a269f009
commit 9997a6b0b1
14 changed files with 163 additions and 72 deletions

View file

@ -23,4 +23,5 @@ pagetop-mdbook = { path = "../pagetop-mdbook" }
maud = { git = "https://github.com/lambda-fairy/maud", rev = "e6787cd6" }
[build-dependencies]
static-files = "0.2.3"
pagetop = { path = "../pagetop" }
pagetop-mdbook = { path = "../pagetop-mdbook" }

View file

@ -1,19 +1,15 @@
use static_files::resource_dir;
use std::env;
use std::path::Path;
use pagetop::util::bundle_resources;
use pagetop_mdbook::util::except_mdbook_common_resources;
fn main() -> std::io::Result<()> {
build_resource_dir("./static/doc/en", "guides_en")?;
build_resource_dir("./static/doc/es", "guias_es")
}
fn build_resource_dir(dir: &str, name: &str) -> std::io::Result<()> {
let mut resource = resource_dir(dir);
resource.with_generated_filename(
Path::new(env::var("OUT_DIR").unwrap().as_str()).join(format!("{}.rs", name)),
);
resource.with_module_name(format!("resources_{}", name));
resource.with_generated_fn(name);
resource.build()
bundle_resources(
"./static/doc/en",
"guides_en",
Some(except_mdbook_common_resources),
)?;
bundle_resources(
"./static/doc/es",
"guias_es",
Some(except_mdbook_common_resources),
)
}

View file

@ -1,14 +1,13 @@
use pagetop::prelude::*;
use pagetop_mdbook::BookMapResources;
use pagetop_mdbook::MdBook;
pub_const_handler!(APP_PAGETOP_WEBSITE);
include!(concat!(env!("OUT_DIR"), "/guides_en.rs"));
static GUIDES_EN: LazyStatic<BookMapResources> = LazyStatic::new(guides_en);
static GUIDES_EN: LazyStatic<HashMapResources> = LazyStatic::new(bundle_guides_en);
include!(concat!(env!("OUT_DIR"), "/guias_es.rs"));
static GUIAS_ES: LazyStatic<BookMapResources> = LazyStatic::new(guias_es);
static GUIAS_ES: LazyStatic<HashMapResources> = LazyStatic::new(bundle_guias_es);
struct PageTopWebSite;
@ -22,9 +21,9 @@ impl ModuleTrait for PageTopWebSite {
}
fn configure_service(&self, cfg: &mut app::web::ServiceConfig) {
MdBook::configure_mdbook_common(cfg);
MdBook::configure_mdbook_service(cfg, "/doc/en", &GUIDES_EN);
MdBook::configure_mdbook_service(cfg, "/doc/es", &GUIAS_ES);
MdBook::configure_service_for_common_resources(cfg);
MdBook::configure_service_for_mdbook(cfg, "/doc/en", &GUIDES_EN);
MdBook::configure_service_for_mdbook(cfg, "/doc/es", &GUIAS_ES);
}
}