<commit_before><?php

class Archive extends \Ghastly\Plugin\Plugin {
    public $events;
    public $Ghastly;

    public function __construct()
    {
        $this->events = [
            ['event'=>'Ghastly.route', 'func'=>'onGhastlyRoute'],
            ['event'=>'Ghastly.pre_render', 'func'=>'onGhastlyPreRender']
        ];
    }

    /** Respond to new routes **/
    public function onGhastlyRoute(\Ghastly\GhastlyRouteEvent $event){
        $event->router->with('/archive', function() use ($event) {
            $this->Ghastly= $event->Ghastly;

            $posts = $this->Ghastly->postModel->findAllHeaders(0);
            $this->Ghastly->template_dirs[] = "plugins/archive";
            $this->Ghastly->template = "archive.html";

            $event->router->respond('/?', function() use ($posts, $event){
                $this->Ghastly->template_vars['archive_links'] = $this->generateLinks($posts, date('m'), date('Y'));
                $this->Ghastly->template_vars['posts'] = $this->getPostsForMonthYear($posts, date('m'), date('Y'));                
            });

            $event->router->respond('/[:month]/[:year]', function($req) use ($posts, $event){
                $this->Ghastly->template_vars['archive_links'] = $this->generateLinks($posts, $req->month, $req->year);
                $this->Ghastly->template_vars['posts'] = $this->getPostsForMonthYear($posts, $req->month, $req->year);
            });
        });
    }

    /** Add variables to all templates on all routes **/
    public function onGhastlyPreRender(\Ghastly\GhastlyPreRenderEvent $event){
        $event->Ghastly->template_vars['archives_url'] = "archive";
    }

    public function getPostsForMonthYear($posts, $month, $year)
    {
        $posts = array_filter($posts, function($post) use ($month, $year){;
            $post_month = $post['date']->format('m');
            $post_year  = $post['date']->format('Y');

            return $post_month == $month && $post_year == $year;
        });

        foreach($posts as $key => $post) {
            $posts[$key] = $this->Ghastly->postModel->getPostById($post['filename']);
        }

        return $posts;
    }

    public function generateLinks($posts, $active_month=false, $active_year=false)
    {
        $month_year = $posts[0]['date']->format('Y-m');
        $counts = $links = [];

        foreach($posts as $post)
        {
            $post_month_year = $post['date']->format('Y-m');

            if($post_month_year == $month_year) {
                $counts[$month_year] = (isset($counts[$month_year])) ? ++$counts[$month_year] : 1;
            } else {<commit_msg>fixed namespacing<commit_after><?php

class Archive extends \Ghastly\Plugin\Plugin {
    public $events;
    public $Ghastly;

    public function __construct()
    {
        $this->events = [
            ['event'=>'Ghastly.PreRoute', 'func'=>'onPreRoute'],
            ['event'=>'Ghastly.PreRender', 'func'=>'onPreRender']
        ];
    }

    /** Respond to new routes **/
    public function onPreRoute(\Ghastly\Event\PreRouteEvent $event){
        $event->router->with('/archive', function() use ($event) {
            $this->Ghastly= $event->Ghastly;

            $posts = $this->Ghastly->postModel->findAllHeaders(0);
            $this->Ghastly->template_dirs[] = "plugins/archive";
            $this->Ghastly->template = "archive.html";

            $event->router->respond('/?', function() use ($posts, $event){
                $this->Ghastly->template_vars['archive_links'] = $this->generateLinks($posts, date('m'), date('Y'));
                $this->Ghastly->template_vars['posts'] = $this->getPostsForMonthYear($posts, date('m'), date('Y'));                
            });

            $event->router->respond('/[:month]/[:year]', function($req) use ($posts, $event){
                $this->Ghastly->template_vars['archive_links'] = $this->generateLinks($posts, $req->month, $req->year);
                $this->Ghastly->template_vars['posts'] = $this->getPostsForMonthYear($posts, $req->month, $req->year);
            });
        });
    }

    /** Add variables to all templates on all routes **/
    public function onPreRender(\Ghastly\Event\PreRenderEvent $event){
        $event->Ghastly->template_vars['archives_url'] = "archive";
    }

    public function getPostsForMonthYear($posts, $month, $year)
    {
        $posts = array_filter($posts, function($post) use ($month, $year){;
            $post_month = $post['date']->format('m');
            $post_year  = $post['date']->format('Y');

            return $post_month == $month && $post_year == $year;
        });

        foreach($posts as $key => $post) {
            $posts[$key] = $this->Ghastly->postModel->getPostById($post['filename']);
        }

        return $posts;
    }

    public function generateLinks($posts, $active_month=false, $active_year=false)
    {
        $month_year = $posts[0]['date']->format('Y-m');
        $counts = $links = [];

        foreach($posts as $post)
        {
            $post_month_year = $post['date']->format('Y-m');

            if($post_month_year == $month_year) {
                $counts[$month_year] = (isset($counts[$month_year])) ? ++$counts[$month_year] : 1;
            } else {
{'fraction_non_alphanumeric': 0.1889673601832411, 'fraction_numerical': 0.0011452567283832794, 'mean_word_length': 2.584131326949384, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 95, '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': '5678174', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1576, 'n_words': 253}