Formatting
This commit is contained in:
parent
6dbedc5eb6
commit
ae3c4a9a6f
|
@ -17,7 +17,12 @@ pub struct EmojiConfig {
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
fn default() -> Self {
|
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 {
|
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 std::{ffi::OsString, fs::read_dir};
|
||||||
|
|
||||||
use crate::config;
|
use crate::config;
|
||||||
pub fn emoji_pass(
|
pub fn emoji_pass(markdown: &str, emoji_config: &Option<config::EmojiConfig>) -> String {
|
||||||
markdown: &str,
|
|
||||||
emoji_config: &Option<config::EmojiConfig>,
|
|
||||||
) -> String {
|
|
||||||
if emoji_config.is_none() {
|
if emoji_config.is_none() {
|
||||||
return markdown.to_string();
|
return markdown.to_string();
|
||||||
}
|
}
|
||||||
|
@ -14,8 +11,10 @@ pub fn emoji_pass(
|
||||||
let re_emojis = Regex::new(r":\w+:").unwrap();
|
let re_emojis = Regex::new(r":\w+:").unwrap();
|
||||||
|
|
||||||
for emoji in re_emojis.find_iter(&markdown.clone()) {
|
for emoji in re_emojis.find_iter(&markdown.clone()) {
|
||||||
let emoji_file_name =
|
let emoji_file_name = get_emoji_file_name(
|
||||||
get_emoji_file_name(&get_emoji_name(emoji.as_str()), &emoji_config.as_ref().unwrap().emoji_local_directory);
|
&get_emoji_name(emoji.as_str()),
|
||||||
|
&emoji_config.as_ref().unwrap().emoji_local_directory,
|
||||||
|
);
|
||||||
if emoji_file_name.is_none() {
|
if emoji_file_name.is_none() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,12 +40,10 @@ fn get_unformatted_text(html: String) -> String {
|
||||||
fn truncate(value: &Value, args: &HashMap<String, Value>) -> Result<Value, tera::Error> {
|
fn truncate(value: &Value, args: &HashMap<String, Value>) -> Result<Value, tera::Error> {
|
||||||
let mut value = value.as_str().unwrap().to_string();
|
let mut value = value.as_str().unwrap().to_string();
|
||||||
let new_len: usize = args.get("len").unwrap().as_str().unwrap().parse().unwrap();
|
let new_len: usize = args.get("len").unwrap().as_str().unwrap().parse().unwrap();
|
||||||
value
|
value.truncate(new_len);
|
||||||
.truncate(new_len);
|
|
||||||
Ok(Value::String(value.to_string()))
|
Ok(Value::String(value.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::index::*;
|
use crate::index::*;
|
||||||
|
|
|
@ -25,10 +25,7 @@ fn generate() {
|
||||||
|
|
||||||
for file in raw_files {
|
for file in raw_files {
|
||||||
let mut markdown = read_to_string(file.path).expect("File does not exist");
|
let mut markdown = read_to_string(file.path).expect("File does not exist");
|
||||||
markdown = emoji::emoji_pass(
|
markdown = emoji::emoji_pass(&markdown, &config.emoji_config);
|
||||||
&markdown,
|
|
||||||
&config.emoji_config,
|
|
||||||
);
|
|
||||||
|
|
||||||
let (html, index_content) = generate_blog_entry(markdown, &config.templates_dir);
|
let (html, index_content) = generate_blog_entry(markdown, &config.templates_dir);
|
||||||
write_to_fs(
|
write_to_fs(
|
||||||
|
|
Loading…
Reference in a new issue