pub fn load<P>(directory: P, conn: &SqliteConnection) -> errors::Result<()>
where
    P: AsRef<Path>,
{
    use crate::schema::posts::dsl::*;

    let parsed_posts = parse_posts(&directory)?;
    info!(
        "parsed {} blog posts in {:?}",
        parsed_posts.len(),
        directory.as_ref()
    );

    let new_posts = parsed_posts
        .iter()
        .map(|post| {
            let post_html = markdown::render_html(&post.content);
            let post_summary = create_summary(&post_html, &post.url());

            NewPost {
                title: &post.metadata.title,
                date: post.metadata.date,
                html: post_html.to_string(),
                summary: post_summary.to_string(),
                url: post.url().to_string(),
                slug: post.slug(),
            }
        })
        .collect::<Vec<_>>();

    diesel::insert_into(posts)
        .values(&new_posts)
        .execute(conn)?;

    create_fts_index(conn)?;

    Ok(())
}
/// Retrieves blog post content and metadata by parsing all markdown files in a given directory,
/// then persists the posts into the database.
Retrieves blog post content and metadata by parsing all markdown files in a given directory,
then persists the posts into the database.
Retrieves blog post content and metadata by parsing all markdown files in a given directory then persists the posts into the database .
pub fn load<P>(directory: P, conn: &SqliteConnection) -> errors::Result<()>
where
    P: AsRef<Path>,
{
    use crate::schema::posts::dsl::*;
    let parsed_posts = parse_posts(&directory)?;
    info!(
        "parsed {} blog posts in {:?}",
        parsed_posts.len(),
        directory.as_ref()
    );
    let new_posts = parsed_posts
        .iter()
        .map(|post| {
            let post_html = markdown::render_html(&post.content);
            let post_summary = create_summary(&post_html, &post.url());
            NewPost {
                title: &post.metadata.title,
                date: post.metadata.date,
                html: post_html.to_string(),
                summary: post_summary.to_string(),
                url: post.url().to_string(),
                slug: post.slug(),
            }
        })
        .collect::<Vec<_>>();
    diesel::insert_into(posts)
        .values(&new_posts)
        .execute(conn)?;
    create_fts_index(conn)?;
    Ok(())
}
pub fn load < P > ( directory : P , conn : & SqliteConnection ) -> errors :: Result < ( ) > where P : AsRef < Path > , { use crate :: schema :: posts :: dsl :: * ; let parsed_posts = parse_posts ( & directory ) ? ; info ! ( " " parsed_posts len ( ) directory as_ref ( ) ) ; let new_posts = parsed_posts . iter ( ) . map ( | post | { let post_html = markdown :: render_html ( & post . content ) ; let post_summary = create_summary ( & post_html , & post . url ( ) ) ; NewPost { title : & post . metadata . title , date : post . metadata . date , html : post_html . to_string ( ) , summary : post_summary . to_string ( ) , url : post . url ( ) . to_string ( ) , slug : post . slug ( ) , } } ) . collect :: < Vec < _ > > ( ) ; diesel :: insert_into ( posts ) . values ( & new_posts ) . execute ( conn ) ? ; create_fts_index ( conn ) ? ; Ok ( ( ) ) }
Retrieves blog post content and metadata by parsing all markdown files in a given directory,
then persists the posts into the database.
Retrieves blog post content and metadata by parsing all markdown files in a given directory then persists the posts into the database .
directory
P
conn
&SqliteConnection
directory
P
conn
&SqliteConnection