<commit_before><?php

namespace Starship\Content;

use Symfony\Component\Finder\SplFileInfo;

class Post extends Content
{
    public $category;
    public $date;
    public $excerpt;
    public $slug;

    public $next;
    public $prev;

    public function __construct(SplFileInfo $file)
    {
        parent::__construct($file);

        // Determine post date and slug based on filename
        // Pattern: yyyy-mm-dd-slug.ext
        $name = $file->getFilename();
        $pattern = implode('', [
            '/^',
            '(?P<date>\\d{4}-\\d{2}-\\d{2})',
            '-',
            '(?P<slug>.+)',
            '\\.',
            $file->getExtension(),
            '$/',
        ]);

        if (!preg_match($pattern, $name, $matches)) {
            throw new \Exception("Failed parsing file name \"$name\"");
        }

        $sourcePath = $file->getRelativePathname();

        $this->category = $this->getCategory($sourcePath);
        $this->excerpt = $this->getExcerpt($this->content);
        $this->date = new \DateTime($matches['date']);
        $this->slug = $matches['slug'];

        $parts = $this->getTargetParts(
            $this->category,
            $this->date,
            $this->slug
        );

        $this->url = '/' . implode('/', $parts);
        $parts[] = "index.html";
        $this->target = implode(DIRECTORY_SEPARATOR, $parts);
    }

    /**
     * Determines post category based on it's source file path.
     *
     * Posts in /_posts will have no category.
     * Posts in /news/_posts will have the category "news"
     *
     * Others combinations throw an exception.
     */<commit_msg>Added date and excerpt overriding via metadata<commit_after><?php

namespace Starship\Content;

use Symfony\Component\Finder\SplFileInfo;

class Post extends Content
{
    public $category;
    public $date;
    public $excerpt;
    public $slug;

    public $next;
    public $prev;

    public function __construct(SplFileInfo $file)
    {
        parent::__construct($file);

        // Determine post date and slug based on filename
        // Pattern: yyyy-mm-dd-slug.ext
        $name = $file->getFilename();
        $pattern = implode('', [
            '/^',
            '(?P<date>\\d{4}-\\d{2}-\\d{2})',
            '-',
            '(?P<slug>.+)',
            '\\.',
            $file->getExtension(),
            '$/',
        ]);

        if (!preg_match($pattern, $name, $matches)) {
            throw new \Exception("Failed parsing file name \"$name\"");
        }

        $sourcePath = $file->getRelativePathname();

        $this->category = $this->getCategory($sourcePath);
        $this->slug = $matches['slug'];

        if (isset($this->meta['date'])) {
            $this->date = new \DateTime();
            $this->date->setTimestamp($this->meta['date']);
        } else {
            $this->date = new \DateTime($matches['date']);
        }

        if (isset($this->meta['excerpt'])) {
            $this->excerpt = $this->meta['excerpt'];
        } else {
            $this->excerpt = $this->getExcerpt($this->content);
        }

        $parts = $this->getTargetParts(
            $this->category,
            $this->date,
            $this->slug
        );

        $this->url = '/' . implode('/', $parts);
        $parts[] = "index.html";
        $this->target = implode(DIRECTORY_SEPARATOR, $parts);
    }

    /**
     * Determines post category based on it's source file path.
     *
     * Posts in /_posts will have no category.
     * Posts in /news/_posts will have the category "news"
     *
     * Others combinations throw an exception.
     */
{'fraction_non_alphanumeric': 0.16703478741027056, 'fraction_numerical': 0.0016565433462175593, 'mean_word_length': 1.8799682034976153, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 47, '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': '4783282', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1060, 'n_words': 232}