2021-04-19 02:50:30 +02:00
|
|
|
<?php
|
|
|
|
use function _\find;
|
|
|
|
use function _\filter;
|
|
|
|
|
|
|
|
class Sorting
|
|
|
|
{
|
|
|
|
private static $_tags = [];
|
|
|
|
private static $_archive = [];
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function tags()
|
|
|
|
{
|
|
|
|
$pages = (new Book("../content/pages"))->getContents();
|
|
|
|
foreach ($pages as $page) {
|
|
|
|
$temp = [];
|
|
|
|
$temp = explode(",", $page["tags"]);
|
|
|
|
foreach ($temp as $tag) {
|
|
|
|
$label = trim($tag);
|
|
|
|
if (!find(self::$_tags, ["tag_name" => $label])) {
|
|
|
|
array_push(self::$_tags, [
|
|
|
|
"tag_name" => $label,
|
|
|
|
"slug" => StringTools::safeString($label),
|
2021-04-22 03:41:32 +02:00
|
|
|
"pages" => self::tagPages($label, $pages),
|
2021-04-19 02:50:30 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return self::$_tags;
|
|
|
|
}
|
|
|
|
|
2021-04-22 03:41:32 +02:00
|
|
|
private static function tagPages($tag, $pages)
|
|
|
|
{
|
|
|
|
$tagged = [];
|
|
|
|
foreach ($pages as $page) {
|
|
|
|
if (strpos($page["tags"], $tag) !== false) {
|
|
|
|
array_push($tagged, [
|
|
|
|
"title" => $page["title"],
|
|
|
|
"slug" => $page["slug"],
|
|
|
|
"path" => $page["path"],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $tagged;
|
|
|
|
}
|
|
|
|
|
2021-04-19 02:50:30 +02:00
|
|
|
public static function archive()
|
|
|
|
{
|
|
|
|
$pages = (new Book("../content/pages"))->getContents();
|
|
|
|
$years = [];
|
|
|
|
$archive = [];
|
|
|
|
foreach ($pages as $page) {
|
2021-04-22 03:41:32 +02:00
|
|
|
//$year = date("Y", date($page["rawCreated"]));
|
|
|
|
$date = explode("/", $page["path"]);
|
2021-04-19 02:50:30 +02:00
|
|
|
//echo $page["title"] . " : " . $year . "\n";
|
2021-04-22 03:41:32 +02:00
|
|
|
if (!find($years, ["year" => trim($date[0])])) {
|
|
|
|
$findPages = filter($pages, ["createdYear" => trim($date[0])]);
|
2021-04-19 02:50:30 +02:00
|
|
|
//var_dump($findPages);
|
2021-04-22 03:41:32 +02:00
|
|
|
array_push($years, [
|
|
|
|
"year" => trim($date[0]),
|
|
|
|
"count" => count($findPages),
|
|
|
|
]);
|
2021-04-19 02:50:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($years as $year) {
|
|
|
|
$sorted = [];
|
|
|
|
$filtered = filter($pages, ["createdYear" => $year["year"]]);
|
|
|
|
|
|
|
|
foreach ($filtered as $obj) {
|
|
|
|
$month = date("m", date($obj["rawCreated"]));
|
|
|
|
if (!find($sorted, ["month" => $month])) {
|
|
|
|
$perMonth = filter($pages, [
|
2021-04-22 03:41:32 +02:00
|
|
|
"path" => $year["year"] . "/" . $month,
|
2021-04-19 02:50:30 +02:00
|
|
|
"deleted" => false,
|
|
|
|
"published" => true,
|
|
|
|
"layout" => "page",
|
|
|
|
]);
|
|
|
|
array_push($sorted, [
|
|
|
|
"month" => $month,
|
|
|
|
"full_month" => date("F", date($obj["rawCreated"])),
|
|
|
|
"count" => count($perMonth),
|
|
|
|
"pages" => $perMonth,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
array_push(self::$_archive, [
|
|
|
|
"year" => $year["year"],
|
|
|
|
"year_data" => $sorted,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
return self::$_archive;
|
|
|
|
}
|
|
|
|
}
|