// creates a new RSS file with the contents of the site blog
creates a new RSS file with the contents of the site blog
creates a new RSS file with the contents of the site blog
fn create_rss(path: &str, dest: &Path, config: &Config, posts: &[Document]) -> Result<()> {
    let rss_path = dest.join(path);
    debug!("Creating RSS file at {}", rss_path.display());
    let title = &config.posts.title;
    let description = config
        .posts
        .description
        .as_ref()
        .map(|s| s.as_str())
        .unwrap_or("");
    let link = config
        .site
        .base_url
        .as_ref()
        .ok_or(ErrorKind::ConfigFileMissingFields)?;
    let items: Result<Vec<rss::Item>> = posts.iter().map(|doc| doc.to_rss(link)).collect();
    let items = items?;
    let channel = rss::ChannelBuilder::default()
        .title(title.to_owned())
        .link(link.to_owned())
        .description(description.to_owned())
        .items(items)
        .build()?;
    let rss_string = channel.to_string();
    trace!("RSS data: {}", rss_string);
    // create target directories if any exist
    if let Some(parent) = rss_path.parent() {
        fs::create_dir_all(parent)
            .map_err(|e| format!("Could not create {:?}: {}", parent, e))?;
    }
    let mut rss_file = fs::File::create(&rss_path)?;
    rss_file
        .write_all(br#"<?xml version="1.0" encoding="UTF-8"?>"#)?;
    rss_file.write_all(&rss_string.into_bytes())?;
    rss_file.write_all(b"\n")?;
    Ok(())
}
fn create_rss ( path : & str , dest : & Path , config : & Config , posts : & [ Document ] ) -> Result < ( ) > { let rss_path = dest . join ( path ) ; debug ! ( " " rss_path display ( ) ) ; let title = & config . posts . title ; let description = config . posts . description . as_ref ( ) . map ( | s | s . as_str ( ) ) . unwrap_or ( " " ) ; let link = config . site . base_url . as_ref ( ) . ok_or ( ErrorKind :: ConfigFileMissingFields ) ? ; let items : Result < Vec < rss :: Item > > = posts . iter ( ) . map ( | doc | doc . to_rss ( link ) ) . collect ( ) ; let items = items ? ; let channel = rss :: ChannelBuilder :: default ( ) . title ( title . to_owned ( ) ) . link ( link . to_owned ( ) ) . description ( description . to_owned ( ) ) . items ( items ) . build ( ) ? ; let rss_string = channel . to_string ( ) ; trace ! ( " " rss_string ) ; // create target directories if any exist if let Some ( parent ) = rss_path . parent ( ) { fs :: create_dir_all ( parent ) . map_err ( | e | format ! ( " " parent e ) ) ? ; } let mut rss_file = fs :: File :: create ( & rss_path ) ? ; rss_file . write_all ( br#"<?xml version="1.0" encoding="UTF-8"?>"# ) ? ; rss_file . write_all ( & rss_string . into_bytes ( ) ) ? ; rss_file . write_all ( b" \n " ) ? ; Ok ( ( ) ) }
creates a new RSS file with the contents of the site blog
creates a new RSS file with the contents of the site blog
path
&str
dest
&Path
config
&Config
posts
&[Document]