pub fn make_entry(
    buf: &Path,
    dst: &Path,
    reg: &Handlebars,
    cfg: &Config,
) -> Result<Entry, Error> {
    let mut e = load_data(&fs::read_to_string(buf)?);
    if !e.has(Key::Content) {
        let empty = Entry::new();
        return Ok(empty);
    }

    // assign _path (a part of url) and slug
    let name = if e.has(Key::Slug) {
        e.get(Key::Slug).unwrap()
    } else {
        let stem = buf.file_stem().unwrap().to_string_lossy().into_owned();
        stem + ".html"
    };
    let path = dst.join(&name);

    e.add(Key::_Path, to_child_str_path(&path));
    e.add(Key::Slug, name);

    // TOC
    let s = e.get(Key::Content).unwrap();
    let mut tree: Vec<Heading> = vec![];
    if let Ok(mut doc) = parse_only(&s) {
        tree = extract_heading_tree(&mut doc);
    }

    let mut meta = &mut json!({
        "website": cfg.website.to_json(),
        "article": e.to_json(),
        "tree": tree,
    });
    meta = merge_authors(meta, cfg);

    let result = reg
        .render("layout", meta)
        .map_err(|e| Error::new(ErrorKind::InvalidInput, e))?;

    e.add(Key::_Body, result);
    Ok(e)
}
/// generates an entry into file in the dst directory and returns its metadata.
generates an entry into file in the dst directory and returns its metadata.
generates an entry into file in the dst directory and returns its metadata .
pub fn make_entry(
    buf: &Path,
    dst: &Path,
    reg: &Handlebars,
    cfg: &Config,
) -> Result<Entry, Error> {
    let mut e = load_data(&fs::read_to_string(buf)?);
    if !e.has(Key::Content) {
        let empty = Entry::new();
        return Ok(empty);
    }
    // assign _path (a part of url) and slug
    let name = if e.has(Key::Slug) {
        e.get(Key::Slug).unwrap()
    } else {
        let stem = buf.file_stem().unwrap().to_string_lossy().into_owned();
        stem + ".html"
    };
    let path = dst.join(&name);
    e.add(Key::_Path, to_child_str_path(&path));
    e.add(Key::Slug, name);
    // TOC
    let s = e.get(Key::Content).unwrap();
    let mut tree: Vec<Heading> = vec![];
    if let Ok(mut doc) = parse_only(&s) {
        tree = extract_heading_tree(&mut doc);
    }
    let mut meta = &mut json!({
        "website": cfg.website.to_json(),
        "article": e.to_json(),
        "tree": tree,
    });
    meta = merge_authors(meta, cfg);
    let result = reg
        .render("layout", meta)
        .map_err(|e| Error::new(ErrorKind::InvalidInput, e))?;
    e.add(Key::_Body, result);
    Ok(e)
}
pub fn make_entry ( buf : & Path , dst : & Path , reg : & Handlebars , cfg : & Config , ) -> Result < Entry , Error > { let mut e = load_data ( & fs :: read_to_string ( buf ) ? ) ; if ! e . has ( Key :: Content ) { let empty = Entry :: new ( ) ; return Ok ( empty ) ; } // assign _path (a part of url) and slug let name = if e . has ( Key :: Slug ) { e . get ( Key :: Slug ) . unwrap ( ) } else { let stem = buf . file_stem ( ) . unwrap ( ) . to_string_lossy ( ) . into_owned ( ) ; stem + " " } ; let path = dst . join ( & name ) ; e . add ( Key :: _Path , to_child_str_path ( & path ) ) ; e . add ( Key :: Slug , name ) ; // TOC let s = e . get ( Key :: Content ) . unwrap ( ) ; let mut tree : Vec < Heading > = vec ! [ ] ; if let Ok ( mut doc ) = parse_only ( & s ) { tree = extract_heading_tree ( & mut doc ) ; } let mut meta = & mut json ! ( { " " cfg website to_json ( ) " " e to_json ( ) " " tree } ) ; meta = merge_authors ( meta , cfg ) ; let result = reg . render ( " " , meta ) . map_err ( | e | Error :: new ( ErrorKind :: InvalidInput , e ) ) ? ; e . add ( Key :: _Body , result ) ; Ok ( e ) }
generates an entry into file in the dst directory and returns its metadata.
generates an entry into file in the dst directory and returns its metadata .
buf
&Path
dst
&Path
reg
&Handlebars
cfg
&Config
buf
&Path
dst
&Path
reg
&Handlebars
cfg
&Config