1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//! module handling content before it goes to the template engine

mod katex;
mod process_md;
mod process_toml;

/// Splits markdown content from toml frontmatter
///
/// Splits markdown content from toml frontmatter delimited by '+++'.
///
/// Returns (toml, markdown) if succesfull
pub(crate) fn split_front_matter(mixed_content: &str) -> Result<(&str, &str), &str> {
    const SEPARATOR: &str = "+++";

    let separate = mixed_content.strip_prefix(SEPARATOR);
    if let Some(stripped) = separate {
        if let Some(separated) = stripped.split_once(SEPARATOR) {
            return Ok(separated);
        } else {
            return Err("Front matter not enclosed (missing second '+++')");
        }
    } else {
        return Err("File not beginning with '+++' (missing front matter)");
    }
}

pub(crate) use process_md::process_md;
pub(crate) use process_toml::process_toml;