<commit_before><?php

namespace Ghastly;

use \Michelf\Markdown;

class PostModel {

    protected $db;

    public function __construct(PostRepositoryInterface $db){
        $this->db = $db;
    }

    public function findAll($limit=0)
    {
        $posts = $this->db->findAll()->limit($limit)->getResults();

        foreach($posts as $key => $post)
        {
            $posts[$key] = $this->_buildPostFromMarkdownFile($post);
        }

        return $posts;
    }

    public function findAllHeaders($limit=0)
    {
        $posts = $this->db->findAll()->limit($limit)->getResults(true);

        return $posts;
    }

    public function getPostById($id)
    {
        $post = $this->db->find($id)->getResult();
        return $this->_buildPostFromMarkdownFile($post);
    }

    private function _buildPostFromMarkdownFile($post)
    {

        $post_content = $post['content'];
      
        $config_options = $post_config_lines = array();

        $post_config = $post_content = explode('-----', $post_content);
        $post_config = explode(PHP_EOL, $post_config[1]);
        $post_config = array_filter($post_config, function($n){ return trim($n); });
        $post_config = array_map(function($n){ return explode(':', $n); }, $post_config);

        foreach($post_config as $option){
            $config_options[trim($option[0])] = trim($option[1]);
        }

        $config_options['slug'] = strtolower(preg_replace('/[^A-Za-z0-9-]+/', '-', trim($post['filename'])));

        $config_options['date'] = $post['date']->format('Y-m-d');

        $post_content = $post_content[2];
        $post_content = Markdown::defaultTransform($post_content);

        $post_summary = false;
        if(str_word_count($post_content) > 50){
            $post_summary = implode(' ', array_slice(explode(' ', $post_content), 0, 50));
        }  

        $post = array('metadata'=>$config_options, 'content'=>$post_content);

        // Use a summary: in the front matter over judiciously chopping the first 50 words.
        if( ! array_key_exists('summary', $config_options)) {
            $post['summary'] = $post_summary;
        }
        
        return $post;
    }

}<commit_msg>fixed issue with post summary<commit_after><?php

namespace Ghastly;

use \Michelf\Markdown;

class PostModel {

    protected $db;

    public function __construct(PostRepositoryInterface $db){
        $this->db = $db;
    }

    public function findAll($limit=0)
    {
        $posts = $this->db->findAll()->limit($limit)->getResults();

        foreach($posts as $key => $post)
        {
            $posts[$key] = $this->_buildPostFromMarkdownFile($post);
        }

        return $posts;
    }

    public function findAllHeaders($limit=0)
    {
        $posts = $this->db->findAll()->limit($limit)->getResults(true);

        return $posts;
    }

    public function getPostById($id)
    {
        $post = $this->db->find($id)->getResult();
        return $this->_buildPostFromMarkdownFile($post);
    }

    private function _buildPostFromMarkdownFile($post)
    {

        $post_content = $post['content'];
      
        $config_options = $post_config_lines = array();

        $post_config = $post_content = explode('-----', $post_content);
        $post_config = explode(PHP_EOL, $post_config[1]);
        $post_config = array_filter($post_config, function($n){ return trim($n); });
        $post_config = array_map(function($n){ return explode(':', $n); }, $post_config);

        foreach($post_config as $option){
            $config_options[trim($option[0])] = trim($option[1]);
        }

        $config_options['slug'] = strtolower(preg_replace('/[^A-Za-z0-9-]+/', '-', trim($post['filename'])));

        $config_options['date'] = $post['date']->format('Y-m-d');

        $post_content = $post_content[2];
        $post_content = Markdown::defaultTransform($post_content);

        $post_summary = false;
        if(str_word_count($post_content) > 50){
            $post_summary = implode(' ', array_slice(explode(' ', $post_content), 0, 50));
        }  

        $post = array('metadata'=>$config_options, 'content'=>$post_content);

        // Use a summary: in the front matter over judiciously chopping the first 50 words.
        if( ! array_key_exists('summary', $config_options)) {
            $post['metadata']['summary'] = $post_summary;
        }

        return $post;
    }

}
{'fraction_non_alphanumeric': 0.16780354706684858, 'fraction_numerical': 0.0068212824010914054, 'mean_word_length': 2.7694944301628106, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3661902', 'n_tokens_mistral': 1390, 'n_tokens_neox': 1335, 'n_words': 236}