<commit_before><?php
  // Load composer packages
  require_once 'vendor/autoload.php';

  /**
   * Returns the full script URL
   *
   * @return string $url
   */

  function returnFullURL(){
    return ((empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off') ? 'http://' : 'https://').$_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']);
  }

  /**
   * Function to construct the project URL based on the return status of
   * checkForModRewrite(). If true the function will return a pretty URL
   * otherwise it'll return a URL with GET parameters.
   *
   * @param string $project
   * @return string $url
   */

  function prepareProjectURL($project){
    return returnFullURL().$project;
  }

  /**
   * Return object with data loaded from JSON files data/github.json
   * and data/info.json
   *
   * @return obj $data
   */

  function loadJSONData(){
    // Load and store portfolio data
    $info_file = file_get_contents("data/info.json");
    $github_file = file_get_contents("data/github.json");

    // Convert from JSON
    $info_json = json_decode($info_file, true);
    $github_json = json_decode($github_file, true);

    // Assign to variables
    $data['info'] = $info_json['information'];
    $data['projects'] = $info_json['projects'];
    $data['github'] = $github_json['projects'];

    // Return data
    return $data;
  }

  // Create new Plates instance and map template folders
  $templates = new League\Plates\Engine('templates');

  // Create new Klein router instance
  $router = new Klein\Klein();

  // Load JSON data into variable
  $data = loadJSONData();

  /**
   * Route for home page
   *
   * @uses Klein\Klein::respond()
   * @example http://frd.mn/
   */

  $router->respond('GET', '/', function () use ($templates, $data)  {
    // Render "home" page
    echo $templates->render('pages/home', compact('data'));
  });

  /**
   * Route for project page
   *
   * @uses Klein\Klein::respond()
   * @example http://frd.mn/test-project
   * @param string $project
   */

  $router->respond('GET', '/[:project]', function ($request) use ($templates, $data)  {
    // Create new Markdown parser instance
    $markdown = new \cebe\markdown\Markdown();
    // Store "project" request
    $alias = $request->project;

    // Check if project actually exists
    if (isset($data['projects'][$alias])) {
      // Render "projects" page
      echo $templates->render('pages/projects', compact('data', 'alias', 'markdown'));
    } else {
      // Create error array
      $error['code'] = 404;
      $error['message'] = 'Project not found';

      // Render "error" page
      echo $templates->render('pages/error', compact('data', 'alias', 'error'));
    }
  });

  // Dispatch router
  $router->dispatch();
?><commit_msg>Return 404 if no project found<commit_after><?php
  // Load composer packages
  require_once 'vendor/autoload.php';

  /**
   * Returns the full script URL
   *
   * @return string $url
   */

  function returnFullURL(){
    return ((empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off') ? 'http://' : 'https://').$_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']);
  }

  /**
   * Function to construct the project URL based on the return status of
   * checkForModRewrite(). If true the function will return a pretty URL
   * otherwise it'll return a URL with GET parameters.
   *
   * @param string $project
   * @return string $url
   */

  function prepareProjectURL($project){
    return returnFullURL().$project;
  }

  /**
   * Return object with data loaded from JSON files data/github.json
   * and data/info.json
   *
   * @return obj $data
   */

  function loadJSONData(){
    // Load and store portfolio data
    $info_file = file_get_contents("data/info.json");
    $github_file = file_get_contents("data/github.json");

    // Convert from JSON
    $info_json = json_decode($info_file, true);
    $github_json = json_decode($github_file, true);

    // Assign to variables
    $data['info'] = $info_json['information'];
    $data['projects'] = $info_json['projects'];
    $data['github'] = $github_json['projects'];

    // Return data
    return $data;
  }

  // Create new Plates instance and map template folders
  $templates = new League\Plates\Engine('templates');

  // Create new Klein router instance
  $router = new Klein\Klein();

  // Load JSON data into variable
  $data = loadJSONData();

  /**
   * Route for home page
   *
   * @uses Klein\Klein::respond()
   * @example http://frd.mn/
   */

  $router->respond('GET', '/', function () use ($templates, $data)  {
    // Render "home" page
    echo $templates->render('pages/home', compact('data'));
  });

  /**
   * Route for project page
   *
   * @uses Klein\Klein::respond()
   * @example http://frd.mn/test-project
   * @param string $project
   */

  $router->respond('GET', '/[:project]', function ($request, $response) use ($templates, $data)  {
    // Create new Markdown parser instance
    $markdown = new \cebe\markdown\Markdown();
    // Store "project" request
    $alias = $request->project;

    // Check if project actually exists
    if (isset($data['projects'][$alias])) {
      // Render "projects" page
      echo $templates->render('pages/projects', compact('data', 'alias', 'markdown'));
    } else {
      // Create error array
      $error['code'] = 404;
      $error['message'] = 'Project not found';

      // Set 404 HTTP status
      $response->code(404);

      // Render "error" page
      echo $templates->render('pages/error', compact('data', 'alias', 'error'));
    }
  });

  // Dispatch router
  $router->dispatch();
?>
{'fraction_non_alphanumeric': 0.16405135520684735, 'fraction_numerical': 0.002674750356633381, 'mean_word_length': 3.026561378320172, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, 'https://': 2, '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': '552524', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1662, 'n_words': 455}