<commit_before><?php
	ini_set('date.timezone', 'Asia/Taipei');

	$page = isset($_GET['p']) ? intval($_GET['p']) : 1;
	$num = count(array_diff(scandir(__DIR__ . '/data'), array('.', '..', '.gitignore')));

	$path = $_SERVER['REQUEST_URI'];
	$pos = strpos($path, '?');

	if ($pos !== false) {
		$path = substr($path, 0, $pos);
	}

	if ($page < 1) {
		header('Location: ' . $path);
		die();
	}

	if ($page > $num && $num !== 0) {
		header('Location: ' . $path . '?p=' . $num);
		die();
	}

	$cachePath = __DIR__ . "/cache/$page.html";
	$dataPath = __DIR__ . "/data/$page.json";

	if (file_exists($cachePath) === true && filemtime($cachePath) > filemtime($dataPath) && (isset($_GET['c']) === false || intval($_GET['c']) !== 0)) {
		echo file_get_contents($cachePath);
		die();
	}

	$sourceMap = array(
			'udn' => array(
					'title' => '聯合新聞網',
					'link' => 'http://udn.com'
				),
			'chinatimes' => array(
					'title' => '中時電子報',
					'link' => 'http://www.chinatimes.com'
				),
			'libertytimes' => array(
					'title' => '自由電子報',
					'link' => 'http://www.ltn.com.tw'
				),
			'appledaily' => array(
					'title' => '蘋果即時新聞',
					'link' => 'http://www.appledaily.com.tw'
				),
			'cna' => array(
					'title' => '中央通訊社',
					'link' => 'http://www.cna.com.tw'
				),
			'storm' => array(
					'title' => '風傳媒',
					'link' => 'http://www.storm.mg'
				),
			'newtalk' => array(
					'title' => '新頭殼',
					'link' => 'http://newtalk.tw'
				),
			'ettoday' => array(
					'title' => 'ETtoday',
					'link' => 'http://www.ettoday.net'
				),
			'nownews' => array(
					'title' => 'NOWnews',
					'link' => 'http://nownews.com'
				),
			'twreporter' => array(
					'title' => '報導者',
					'link' => 'https://www.twreporter.org'
				),
			'theinitium' => array(
					'title' => '端傳媒',
					'link' => 'https://theinitium.com'
				),
			'upmedia' => array(
					'title' => '上報',
					'link' => 'http://www.upmedia.mg'
				),
			'mirrormedia' => array(
					'title' => '鏡傳媒',
					'link' => 'https://www.mirrormedia.mg'
				),
			'setn' => array(
					'title' => '三立新聞網',
					'link' => 'http://www.setn.com'
				)
		);

	ob_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" >
<meta name="format-detection" content="telephone=no" >
<meta charset="UTF-8" >
<title>台灣即時新聞</title>
<link rel="apple-touch-icon" href="realtime.png" >
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv-printshiv.min.js" ></script>
<![endif]-->
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.2/normalize.min.css" rel="stylesheet" >
<link href="css/index.min.css" rel="stylesheet" >
</head>
<body>
<?php
    $base = $page;
    $temp = $num - 5;

    if($base > $temp) {
        $base = $temp;
    }

    if($base < 5) {
        $base = 5;
    }

    $start = $base - 4;
    $end = $base + 5;
    
    if($end > $num) {
        $end = $num;
    }
?>
<header>
	<h1><a href="<?php echo $path ?>" >台灣即時新聞</a></h1>
	<p>這是第 <?php echo $page ?> 頁，共 <?php echo $num ?> 頁</p>
</header>
<?php
	$i = 0;

	foreach (json_decode(file_get_contents(__DIR__ . "/data/$page.json"), true) as $item) {
		$timestamp = $item['timestamp'];
		$description = $item['description'];
		$source = $sourceMap[$item['source']];

		if (isset($item['image'])) {
			$description .= '<br><img src="' . $item['image'] . '">';
		}
?>
<article>
	<p><a href="<?php echo $source['link'] ?>" target="_blank" ><?php echo $source['title'] ?></a> <time datetime="<?php echo date('c', $timestamp) ?>" ><?php echo date('Y-m-d H:i:s', $timestamp) ?></time></p>
	<h1><a href="<?php echo $item['link'] ?>" target="_blank" ><?php echo $item['title'] ?></a></h1>
<?php<commit_msg>Tuned image HTML when description === ''<commit_after><?php
	ini_set('date.timezone', 'Asia/Taipei');

	$page = isset($_GET['p']) ? intval($_GET['p']) : 1;
	$num = count(array_diff(scandir(__DIR__ . '/data'), array('.', '..', '.gitignore')));

	$path = $_SERVER['REQUEST_URI'];
	$pos = strpos($path, '?');

	if ($pos !== false) {
		$path = substr($path, 0, $pos);
	}

	if ($page < 1) {
		header('Location: ' . $path);
		die();
	}

	if ($page > $num && $num !== 0) {
		header('Location: ' . $path . '?p=' . $num);
		die();
	}

	$cachePath = __DIR__ . "/cache/$page.html";
	$dataPath = __DIR__ . "/data/$page.json";

	if (file_exists($cachePath) === true && filemtime($cachePath) > filemtime($dataPath) && (isset($_GET['c']) === false || intval($_GET['c']) !== 0)) {
		echo file_get_contents($cachePath);
		die();
	}

	$sourceMap = array(
			'udn' => array(
					'title' => '聯合新聞網',
					'link' => 'http://udn.com'
				),
			'chinatimes' => array(
					'title' => '中時電子報',
					'link' => 'http://www.chinatimes.com'
				),
			'libertytimes' => array(
					'title' => '自由電子報',
					'link' => 'http://www.ltn.com.tw'
				),
			'appledaily' => array(
					'title' => '蘋果即時新聞',
					'link' => 'http://www.appledaily.com.tw'
				),
			'cna' => array(
					'title' => '中央通訊社',
					'link' => 'http://www.cna.com.tw'
				),
			'storm' => array(
					'title' => '風傳媒',
					'link' => 'http://www.storm.mg'
				),
			'newtalk' => array(
					'title' => '新頭殼',
					'link' => 'http://newtalk.tw'
				),
			'ettoday' => array(
					'title' => 'ETtoday',
					'link' => 'http://www.ettoday.net'
				),
			'nownews' => array(
					'title' => 'NOWnews',
					'link' => 'http://nownews.com'
				),
			'twreporter' => array(
					'title' => '報導者',
					'link' => 'https://www.twreporter.org'
				),
			'theinitium' => array(
					'title' => '端傳媒',
					'link' => 'https://theinitium.com'
				),
			'upmedia' => array(
					'title' => '上報',
					'link' => 'http://www.upmedia.mg'
				),
			'mirrormedia' => array(
					'title' => '鏡傳媒',
					'link' => 'https://www.mirrormedia.mg'
				),
			'setn' => array(
					'title' => '三立新聞網',
					'link' => 'http://www.setn.com'
				)
		);

	ob_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" >
<meta name="format-detection" content="telephone=no" >
<meta charset="UTF-8" >
<title>台灣即時新聞</title>
<link rel="apple-touch-icon" href="realtime.png" >
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv-printshiv.min.js" ></script>
<![endif]-->
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.2/normalize.min.css" rel="stylesheet" >
<link href="css/index.min.css" rel="stylesheet" >
</head>
<body>
<?php
    $base = $page;
    $temp = $num - 5;

    if($base > $temp) {
        $base = $temp;
    }

    if($base < 5) {
        $base = 5;
    }

    $start = $base - 4;
    $end = $base + 5;
    
    if($end > $num) {
        $end = $num;
    }
?>
<header>
	<h1><a href="<?php echo $path ?>" >台灣即時新聞</a></h1>
	<p>這是第 <?php echo $page ?> 頁，共 <?php echo $num ?> 頁</p>
</header>
<?php
	$i = 0;

	foreach (json_decode(file_get_contents(__DIR__ . "/data/$page.json"), true) as $item) {
		$timestamp = $item['timestamp'];
		$description = $item['description'];
		$source = $sourceMap[$item['source']];

		if (isset($item['image'])) {
			if ($description !== '') {
				$description .= '<br>';
			}

			$description .= '<img src="' . $item['image'] . '">';
		}
?>
<article>
	<p><a href="<?php echo $source['link'] ?>" target="_blank" ><?php echo $source['title'] ?></a> <time datetime="<?php echo date('c', $timestamp) ?>" ><?php echo date('Y-m-d H:i:s', $timestamp) ?></time></p>
	<h1><a href="<?php echo $item['link'] ?>" target="_blank" ><?php echo $item['title'] ?></a></h1>
<?php
{'fraction_non_alphanumeric': 0.26294873493177906, 'fraction_numerical': 0.0068883295800768315, 'mean_word_length': 3.0245202558635396, 'pattern_counts': {'":': 0, '<': 109, '<?xml version=': 0, '>': 195, 'https://': 10, 'lorem ipsum': 0, 'www.': 20, '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': '279145', 'n_tokens_mistral': 3582, 'n_tokens_neox': 3148, 'n_words': 546}