Formatting
This commit is contained in:
		
							parent
							
								
									6dbedc5eb6
								
							
						
					
					
						commit
						ae3c4a9a6f
					
				| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
use serde::{Deserialize,Serialize};
 | 
			
		||||
use serde::{Deserialize, Serialize};
 | 
			
		||||
use std::fs::read_to_string;
 | 
			
		||||
 | 
			
		||||
#[derive(Deserialize,Serialize,Debug)]
 | 
			
		||||
#[derive(Deserialize, Serialize, Debug)]
 | 
			
		||||
pub struct Config {
 | 
			
		||||
    pub output_dir: String,
 | 
			
		||||
    pub src_dir: String,
 | 
			
		||||
| 
						 | 
				
			
			@ -9,7 +9,7 @@ pub struct Config {
 | 
			
		|||
    pub emoji_config: Option<EmojiConfig>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Deserialize,Serialize,Debug)]
 | 
			
		||||
#[derive(Deserialize, Serialize, Debug)]
 | 
			
		||||
pub struct EmojiConfig {
 | 
			
		||||
    pub emoji_web_directory: String,
 | 
			
		||||
    pub emoji_local_directory: String,
 | 
			
		||||
| 
						 | 
				
			
			@ -17,7 +17,12 @@ pub struct EmojiConfig {
 | 
			
		|||
 | 
			
		||||
impl Default for Config {
 | 
			
		||||
    fn default() -> Self {
 | 
			
		||||
        Config { output_dir: "output".to_string() , src_dir: "md_src".to_string(), templates_dir: "templates".to_string(), emoji_config: None }
 | 
			
		||||
        Config {
 | 
			
		||||
            output_dir: "output".to_string(),
 | 
			
		||||
            src_dir: "md_src".to_string(),
 | 
			
		||||
            templates_dir: "templates".to_string(),
 | 
			
		||||
            emoji_config: None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
pub fn read_config() -> Config {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										11
									
								
								src/emoji.rs
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/emoji.rs
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -2,10 +2,7 @@ use regex::Regex;
 | 
			
		|||
use std::{ffi::OsString, fs::read_dir};
 | 
			
		||||
 | 
			
		||||
use crate::config;
 | 
			
		||||
pub fn emoji_pass(
 | 
			
		||||
    markdown: &str,
 | 
			
		||||
    emoji_config: &Option<config::EmojiConfig>,
 | 
			
		||||
) -> String {
 | 
			
		||||
pub fn emoji_pass(markdown: &str, emoji_config: &Option<config::EmojiConfig>) -> String {
 | 
			
		||||
    if emoji_config.is_none() {
 | 
			
		||||
        return markdown.to_string();
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -14,8 +11,10 @@ pub fn emoji_pass(
 | 
			
		|||
    let re_emojis = Regex::new(r":\w+:").unwrap();
 | 
			
		||||
 | 
			
		||||
    for emoji in re_emojis.find_iter(&markdown.clone()) {
 | 
			
		||||
        let emoji_file_name =
 | 
			
		||||
            get_emoji_file_name(&get_emoji_name(emoji.as_str()), &emoji_config.as_ref().unwrap().emoji_local_directory);
 | 
			
		||||
        let emoji_file_name = get_emoji_file_name(
 | 
			
		||||
            &get_emoji_name(emoji.as_str()),
 | 
			
		||||
            &emoji_config.as_ref().unwrap().emoji_local_directory,
 | 
			
		||||
        );
 | 
			
		||||
        if emoji_file_name.is_none() {
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										10
									
								
								src/index.rs
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/index.rs
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -39,13 +39,11 @@ fn get_unformatted_text(html: String) -> String {
 | 
			
		|||
 | 
			
		||||
fn truncate(value: &Value, args: &HashMap<String, Value>) -> Result<Value, tera::Error> {
 | 
			
		||||
    let mut value = value.as_str().unwrap().to_string();
 | 
			
		||||
    let new_len:usize = args.get("len").unwrap().as_str().unwrap().parse().unwrap();
 | 
			
		||||
    value
 | 
			
		||||
        .truncate(new_len);
 | 
			
		||||
    let new_len: usize = args.get("len").unwrap().as_str().unwrap().parse().unwrap();
 | 
			
		||||
    value.truncate(new_len);
 | 
			
		||||
    Ok(Value::String(value.to_string()))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#[cfg(test)]
 | 
			
		||||
mod tests {
 | 
			
		||||
    use crate::index::*;
 | 
			
		||||
| 
						 | 
				
			
			@ -54,13 +52,13 @@ mod tests {
 | 
			
		|||
        let mut args: HashMap<String, Value> = HashMap::new();
 | 
			
		||||
        args.insert("len".to_string(), Value::String("4".to_string()));
 | 
			
		||||
        let truncated_string = truncate(&Value::String("Meow Nya".to_string()), &args).unwrap();
 | 
			
		||||
        assert_eq!(truncated_string.as_str().unwrap(),"Meow");
 | 
			
		||||
        assert_eq!(truncated_string.as_str().unwrap(), "Meow");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn unformat_html() {
 | 
			
		||||
        let html_src = "<p>Meow nyaaa<em> UwU</em></p>".to_string();
 | 
			
		||||
        let unformatted_text = get_unformatted_text(html_src);
 | 
			
		||||
        assert_eq!(unformatted_text,"Meow nyaaa UwU");
 | 
			
		||||
        assert_eq!(unformatted_text, "Meow nyaaa UwU");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,7 @@ pub mod index;
 | 
			
		|||
use mlem::*;
 | 
			
		||||
use std::env;
 | 
			
		||||
 | 
			
		||||
fn main(){
 | 
			
		||||
fn main() {
 | 
			
		||||
    let args: Vec<String> = env::args().collect();
 | 
			
		||||
 | 
			
		||||
    if args.len() == 1 {
 | 
			
		||||
| 
						 | 
				
			
			@ -25,10 +25,7 @@ fn generate() {
 | 
			
		|||
 | 
			
		||||
    for file in raw_files {
 | 
			
		||||
        let mut markdown = read_to_string(file.path).expect("File does not exist");
 | 
			
		||||
        markdown = emoji::emoji_pass(
 | 
			
		||||
            &markdown,
 | 
			
		||||
            &config.emoji_config,
 | 
			
		||||
        );
 | 
			
		||||
        markdown = emoji::emoji_pass(&markdown, &config.emoji_config);
 | 
			
		||||
 | 
			
		||||
        let (html, index_content) = generate_blog_entry(markdown, &config.templates_dir);
 | 
			
		||||
        write_to_fs(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue