feat: Copy THEME/assets to out_dir
This commit is contained in:
		
							parent
							
								
									6ee952133d
								
							
						
					
					
						commit
						90f29bd2a4
					
				@ -5,7 +5,7 @@ use anyhow::Result;
 | 
			
		||||
use camino::Utf8Path;
 | 
			
		||||
use feed_rs::model::Feed;
 | 
			
		||||
use std::collections::HashMap;
 | 
			
		||||
use std::fs::File;
 | 
			
		||||
use std::fs::{copy, create_dir_all, File};
 | 
			
		||||
use tera::{from_value, Tera};
 | 
			
		||||
 | 
			
		||||
pub fn build(config: &Config, feed_store: &mut FeedStore) -> Result<()> {
 | 
			
		||||
@ -32,6 +32,35 @@ pub fn build(config: &Config, feed_store: &mut FeedStore) -> Result<()> {
 | 
			
		||||
        let file = File::create(format!("{out_dir}/{name}"))?;
 | 
			
		||||
        tera.render_to(name, &context, file)?;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Copy static assets from theme, if any
 | 
			
		||||
    if let Some(theme) = &config.theme {
 | 
			
		||||
        let assets_dir = config.templates_dir.join(theme).join("assets");
 | 
			
		||||
        if assets_dir.is_dir() {
 | 
			
		||||
            copy_assets(&assets_dir, &out_dir)?;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Recursively copy assets from one dir to another
 | 
			
		||||
///
 | 
			
		||||
/// Symlinks are ignored.
 | 
			
		||||
fn copy_assets(orig: &Utf8Path, dest: &Utf8Path) -> Result<()> {
 | 
			
		||||
    if orig.is_dir() {
 | 
			
		||||
        if !dest.is_dir() {
 | 
			
		||||
            create_dir_all(dest)?;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        for entry in orig.read_dir_utf8()? {
 | 
			
		||||
            let entry = entry?;
 | 
			
		||||
            copy_assets(entry.path(), &dest.join(entry.file_name()))?;
 | 
			
		||||
        }
 | 
			
		||||
    } else if orig.is_file() {
 | 
			
		||||
        copy(orig, dest)?;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user