<commit_before><?php

namespace STC;

use Cocur\Slugify\Slugify;

/**
 * @author <NAME> <<EMAIL>>
 * @license MIT License (see LICENSE)
 */
class PageRender
{
  private $slugify;

  /**
   * @constructor
   */
  public function __construct()
  {
    $this->slugify = new Slugify();
  }

  /**
   * Check if it has 'index' in the filename.
   * @param $file string | The filename.
   * @return bool
   */
  private function is_index($filename = '')
  {
    $pattern = '/(^index).+$/';
    return preg_match($pattern, $filename);
  }

  /**
   * Make the page slug.
   * @param $file array | Raw file data.
   * @param $tmpl array | Reference to the new file data.
   * @return void
   */
  private function make_slug($file, &$tmpl)
  {
    $filename = $file['file'];
    return $this->is_index($filename) ?
      '' :
      $this->slugify->slugify($file['title']);
  }

  /**
   * Format a file to be rendered.
   * @param $template Template | A Template.
   * @param $file array | Json file as array.
   * @return array
   */
  private function make_data($file)
  {
    if (!array_key_exists('template', $file)) {
      throw new Exception('x> Current page: ' . $file['title'] . ' does not have a template.');
    }

    $t = Config::templates()->template($file['template']);

    $tmpl = $file;
    $tmpl['slug'] = $this->make_slug($file, $tmpl);

    $data_folder = Config::data_folder();
    $template_name = $data_folder . '/templates/' . $t;
    $content_template = $data_folder . '/' . $file['content'];

    $tmpl['html'] = view($template_name, [
      'content' => view($content_template),
      'post'=> $file,
    ]);

    printLn('==> Current page: ' . $file['title'] . ': ' . $tmpl['slug']);

    return $tmpl;
  }

  /**
   * Render function.
   * @param $files array | A list of all available entries.
   * @return void
   */
  public function render($files)
  {
    printLn('=> PageRender.');
    $pages = Config::db()->retrieve('page_list');

    $t = Config::templates()->templates_path() . '/';

    $writer = new DataWriter();

    foreach($pages as $page) {
      $tmpl = $this->make_data($page);
      $writer->write($tmpl['slug'], 'index.html', $tmpl['html']);
    }
  }
}
<commit_msg>clean up PageRender::make_slug().<commit_after><?php

namespace STC;

use Cocur\Slugify\Slugify;

/**
 * @author <NAME> <<EMAIL>>
 * @license MIT License (see LICENSE)
 */
class PageRender
{
  private $slugify;

  /**
   * @constructor
   */
  public function __construct()
  {
    $this->slugify = new Slugify();
  }

  /**
   * Check if it has 'index' in the filename.
   * @param $file string | The filename.
   * @return bool
   */
  private function is_index($filename = '')
  {
    $pattern = '/(^index).+$/';
    return preg_match($pattern, $filename);
  }

  /**
   * Make the page slug.
   * @param $file array | Raw file data.
   * @param $tmpl array | Reference to the new file data.
   * @return void
   */
  private function make_slug($file, &$tmpl)
  {
    return $this->is_index($file['file']) ?
      '' :
      $this->slugify->slugify($file['title']);
  }

  /**
   * Format a file to be rendered.
   * @param $template Template | A Template.
   * @param $file array | Json file as array.
   * @return array
   */
  private function make_data($file)
  {
    if (!array_key_exists('template', $file)) {
      throw new Exception('x> Current page: ' . $file['title'] . ' does not have a template.');
    }

    $t = Config::templates()->template($file['template']);

    $tmpl = $file;
    $tmpl['slug'] = $this->make_slug($file, $tmpl);

    $data_folder = Config::data_folder();
    $template_name = $data_folder . '/templates/' . $t;
    $content_template = $data_folder . '/' . $file['content'];

    $tmpl['html'] = view($template_name, [
      'content' => view($content_template),
      'post'=> $file,
    ]);

    printLn('==> Current page: ' . $file['title'] . ': ' . $tmpl['slug']);

    return $tmpl;
  }

  /**
   * Render function.
   * @param $files array | A list of all available entries.
   * @return void
   */
  public function render($files)
  {
    printLn('=> PageRender.');
    $pages = Config::db()->retrieve('page_list');

    $t = Config::templates()->templates_path() . '/';

    $writer = new DataWriter();

    foreach($pages as $page) {
      $tmpl = $this->make_data($page);
      $writer->write($tmpl['slug'], 'index.html', $tmpl['html']);
    }
  }
}

{'fraction_non_alphanumeric': 0.18992511912865895, 'fraction_numerical': 0.0, 'mean_word_length': 2.836379460400348, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 39, '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': '5487231', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1489, 'n_words': 352}