tag html rendering implemented

This commit is contained in:
Ro 2021-04-21 18:41:32 -07:00
parent c78772e2c0
commit 9283a7f5b3
9 changed files with 92 additions and 45 deletions

1
.gitignore vendored
View file

@ -17,6 +17,7 @@ public/assets/images/*
content/ content/
vendor/ vendor/
cache/ cache/
_temp
.ftpconfig .ftpconfig
.vscode/ .vscode/
*.swp *.swp

View file

@ -13,31 +13,8 @@ class SettingsAPI
$task = $args["fourth"]; $task = $args["fourth"];
switch ($task) { switch ($task) {
case "publish": case "publish":
$view = Twig::fromRequest($request); $render = new Render();
$render->renderTags();
//$sortTags = Sorting::tags();
//var_dump($sortTags);
$sortArchive = Sorting::archive();
var_dump($sortArchive);
/*
$template = "dash/start.twig";
$pageOptions = [
"title" => "Welcome to Fucking Fipamo",
"status" => false,
];
$html = $view->fetch($template, $pageOptions);
$location = "../content/test.html";
if (!is_file($location)) {
file_put_contents($location, $html);
} else {
($new = fopen($location, "w")) or die("Unable to open file!");
fwrite($new, $html);
fclose($new);
}
*/
$result = [ $result = [
"message" => "Items sorted. GOOD EFFORT", "message" => "Items sorted. GOOD EFFORT",

View file

@ -12,11 +12,18 @@ class IndexControl
): ResponseInterface { ): ResponseInterface {
//unset($_SESSION); //unset($_SESSION);
$view = Twig::fromRequest($request); $view = Twig::fromRequest($request);
return $view->render($response, "front/start.twig", [
"title" => "Fipamo Dash", $html = file_get_contents("../public/index.html");
"status" => false, $response->getBody()->write($html);
"pages" => [], return $response;
"totalPages" => 0,
]); /*
return $view->render($response, "front/start.twig", [
"title" => "Fipamo Dash",
"status" => false,
"pages" => [],
"totalPages" => 0,
]);
*/
} }
} }

View file

@ -150,6 +150,7 @@ class Book
//once saved, update menu //once saved, update menu
$body["path"] = $path; $body["path"] = $path;
Settings::updateMenu($body); Settings::updateMenu($body);
Settings::updateTags();
} else { } else {
$response = [ $response = [
"message" => "Uh oh. File save problem. Don't panic", "message" => "Uh oh. File save problem. Don't panic",

View file

@ -2,7 +2,48 @@
class Render class Render
{ {
public $loader;
public $twig;
public $pageInfo;
public $menu;
public $background;
public function __construct() public function __construct()
{ {
$config = new Settings();
$this->loader = new \Twig\Loader\FilesystemLoader("../content/themes");
$this->twig = new \Twig\Environment($this->loader, []);
$settings = $config->getSettings();
$this->menu = $settings["menu"];
$this->pageInfo = [
"keywords" => $settings["global"]["keywords"],
"description" => $settings["global"]["descriptions"],
"image" => $settings["global"]["background"],
];
}
public function renderTags()
{
$list = Sorting::tags();
foreach ($list as $item) {
$template = "fipamo-default/tags.twig";
$pageOptions = [
"title" => "Pages Tagged as " . $item["tag_name"],
"background" => $this->pageInfo["image"],
"tag_list" => $item["pages"],
"info" => $this->pageInfo,
"menu" => $this->menu,
];
$html = $this->twig->render($template, $pageOptions);
$location = "../public/tags/" . $item["slug"] . ".html";
if (!is_file($location)) {
file_put_contents($location, $html);
} else {
($new = fopen($location, "w")) or die("Unable to open file!");
fwrite($new, $html);
fclose($new);
}
}
} }
} }

View file

@ -164,4 +164,10 @@ class Settings
} }
DocTools::writeSettings("../config/settings.json", $settings); DocTools::writeSettings("../config/settings.json", $settings);
} }
public static function updateTags()
{
$tags = Sorting::tags();
DocTools::writeSettings("../config/tags.json", $tags);
}
} }

View file

@ -13,7 +13,6 @@ class Sorting
public static function tags() public static function tags()
{ {
$pages = (new Book("../content/pages"))->getContents(); $pages = (new Book("../content/pages"))->getContents();
foreach ($pages as $page) { foreach ($pages as $page) {
$temp = []; $temp = [];
$temp = explode(",", $page["tags"]); $temp = explode(",", $page["tags"]);
@ -23,13 +22,8 @@ class Sorting
array_push(self::$_tags, [ array_push(self::$_tags, [
"tag_name" => $label, "tag_name" => $label,
"slug" => StringTools::safeString($label), "slug" => StringTools::safeString($label),
"count" => 1, "pages" => self::tagPages($label, $pages),
]); ]);
} else {
$item = find(self::$_tags, ["tag_name" => $label]);
//echo "TAG: " . $item["tag_name"] . "\n";
$count = $item["count"];
self::$_tags[$label]["count"] = $count + 1;
} }
} }
} }
@ -37,18 +31,38 @@ class Sorting
return self::$_tags; return self::$_tags;
} }
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;
}
public static function archive() public static function archive()
{ {
$pages = (new Book("../content/pages"))->getContents(); $pages = (new Book("../content/pages"))->getContents();
$years = []; $years = [];
$archive = []; $archive = [];
foreach ($pages as $page) { foreach ($pages as $page) {
$year = date("Y", date($page["rawCreated"])); //$year = date("Y", date($page["rawCreated"]));
$date = explode("/", $page["path"]);
//echo $page["title"] . " : " . $year . "\n"; //echo $page["title"] . " : " . $year . "\n";
if (!find($years, ["year" => $year])) { if (!find($years, ["year" => trim($date[0])])) {
$findPages = filter($pages, ["createdYear" => $year]); $findPages = filter($pages, ["createdYear" => trim($date[0])]);
//var_dump($findPages); //var_dump($findPages);
array_push($years, ["year" => $year, "count" => count($findPages)]); array_push($years, [
"year" => trim($date[0]),
"count" => count($findPages),
]);
} }
} }
foreach ($years as $year) { foreach ($years as $year) {
@ -59,8 +73,7 @@ class Sorting
$month = date("m", date($obj["rawCreated"])); $month = date("m", date($obj["rawCreated"]));
if (!find($sorted, ["month" => $month])) { if (!find($sorted, ["month" => $month])) {
$perMonth = filter($pages, [ $perMonth = filter($pages, [
"createdYear" => $year["year"], "path" => $year["year"] . "/" . $month,
"createdMonth" => $month,
"deleted" => false, "deleted" => false,
"published" => true, "published" => true,
"layout" => "page", "layout" => "page",

View file

@ -5,7 +5,7 @@
{% endblock %} {% endblock %}
{% block stylesheets %} {% block stylesheets %}
<link rel="stylesheet" type="text/css" href="/assets/css/dash.css?=adfafd"> <link rel="stylesheet" type="text/css" href="/assets/css/dash.css?=tyurtyuryu">
{% endblock %} {% endblock %}
{% block mainContent %} {% block mainContent %}

View file

@ -12,6 +12,7 @@ include "../brain/data/Settings.inc.php";
include "../brain/data/Session.inc.php"; include "../brain/data/Session.inc.php";
include "../brain/data/Member.inc.php"; include "../brain/data/Member.inc.php";
include "../brain/data/Auth.inc.php"; include "../brain/data/Auth.inc.php";
include "../brain/data/Render.inc.php";
include "../brain/utility/StringTools.inc.php"; include "../brain/utility/StringTools.inc.php";
include "../brain/utility/FileUploader.inc.php"; include "../brain/utility/FileUploader.inc.php";
include "../brain/utility/DocTools.inc.php"; include "../brain/utility/DocTools.inc.php";