Moved initial asset fetching to compile time

This commit is contained in:
2024-11-14 02:30:41 -05:00
parent a8c0bb1641
commit 1b79a07c5b
3 changed files with 56 additions and 25 deletions
+1
View File
@@ -35,6 +35,7 @@ pub(crate) fn make_page<S>(content: S, settings: PageSettings) -> String
where
S: AsRef<str>,
{
for t in TEMPLATES.into_iter() {}
rewrite_str(
template!("default"),
RewriteStrSettings {
+3 -25
View File
@@ -31,6 +31,7 @@ use blogdb::BlogDb;
use glob::glob;
use crate::html;
include!(concat!(env!("OUT_DIR"), "/codegen.rs"));
const DB_URL: &str = "sqlite://evie.db";
@@ -146,35 +147,12 @@ impl BlogStateInner {
Ok(())
}
const ASSETS_DIR: &'static str = concat!(env!("CARGO_MANIFEST_DIR"), "/src/client/assets");
async fn add_initial_assets(db: &BlogDb) -> anyhow::Result<()> {
let pattern = [Self::ASSETS_DIR, "/*/*"].concat();
let paths = glob(&pattern).unwrap();
let mut assets = vec![];
for path in paths.into_iter() {
match path {
Ok(path) => {
let slug_path = path.clone();
let slug: String = slug_path
.strip_prefix(Self::ASSETS_DIR)?
.as_os_str()
.to_str()
.unwrap()
.into(); // eek
let mut file = File::open(path.clone())?;
let mut data = vec![];
file.read_to_end(&mut data).unwrap();
assets.push((slug, data));
}
Err(_) => todo!(),
}
}
db.add_assets(assets).await?;
include!(concat!(env!("OUT_DIR"), "/add_assets.rs"));
Ok(())
}
const INDEX_PATH: &'static str = concat!(env!("CARGO_MANIFEST_DIR"), "/index");
const INDEX_PATH: &'static str = "./index";
const MEMORY_BUDGET: usize = 50_000_000;
async fn generate_index(db: &BlogDb) -> anyhow::Result<(Index, IndexWriter)> {