Kompilator

Took 59 minutes
This commit is contained in:
Krzysztof 'KrzysiekSiemv' Smaga
2023-04-30 21:23:20 +02:00
parent e9216f1710
commit 36302fbaf1
7 changed files with 112 additions and 36 deletions
+83 -16
View File
@@ -1,27 +1,94 @@
<?php
require "vendor/blog-engine/php/Dictionary.php";
$dictionary = new \BlogEngine\Dictionary();
class CompileIt{
public \BlogEngine\Dictionary $dictionary;
public function __construct(public $src = __DIR__ . "/src/", public $htmls = [], public $csss = [], public $jss = [], public $version = 0){
$this->dictionary = new BlogEngine\Dictionary();
$src = __DIR__ . "/src/";
$html = scandir($src . "views");
$css = scandir($src . "css");
$js = scandir($src . "js");
// POBIERANIE ZAWARTOŚCI FOLDERU src
$this->src = __DIR__ . "/src/";
$this->htmls = scandir($src . "views");
$this->csss = scandir($src . "css");
$this->jss = scandir($src . "js");
for($i = 2; $i < count($html); $i++){
$site = file_get_contents($src . "views/" . $html[$i]);
foreach (array_keys($dictionary->page_tags) as $page_tag){
if($page_tag = "{CSS}"){
for($j = 2; $j < count($css); $j++)
$dictionary->page_tags[$page_tag] .= "<link rel='stylesheet' href='public/css/{$css[$j]}' />";
//$this->version =
}
if($page_tag = "{JS}"){
for($j = 2; $j < count($js); $j++)
$dictionary->page_tags[$page_tag] .= "<script src='public/js/{$js[$j]}'></script>";
public function main() : void{
$this->checkFolders();
$this->compileFiles();
echo "Done";
}
$site = str_replace($page_tag, $dictionary->page_tags[$page_tag], $site);
/*
* SPRAWDZANIE CZY SĄ FOLDERY css I js
*/
function checkFolders() : void{
if(!file_exists("public/css"))
mkdir("public/css");
if(!file_exists("public/js"))
mkdir("public/js");
}
echo $site;
function compileFiles() : void{
// KOPIOWANIE PLIKÓW HTML DO PUBLICZNEGO FOLDERU
foreach ($this->htmls as $html) {
$file = $this->src . "views/" . $html;
if(pathinfo($file, PATHINFO_EXTENSION) == "html") {
$name = basename($file);
$site = file_get_contents($file);
foreach (array_keys($this->dictionary->page_tags) as $page_tag) {
echo $page_tag;
if ($page_tag == "{CSS}") {
$this->dictionary->page_tags[$page_tag] .= "<link rel='stylesheet' href='vendor/blog-engine/blog.css' />";
for ($j = 2; $j < count($this->csss); $j++)
$this->dictionary->page_tags[$page_tag] .= "\n <link rel='stylesheet' href='public/css/{$this->csss[$j]}' />";
}
if ($page_tag == "{JS}") {
$this->dictionary->page_tags[$page_tag] .= "<script src='vendor/blog-engine/blog.js'></script>";
for ($j = 2; $j < count($this->jss); $j++)
$this->dictionary->page_tags[$page_tag] .= "\n <script src='public/js/{$this->jss[$j]}'></script>";
}
$site = str_replace($page_tag, $this->dictionary->page_tags[$page_tag], $site);
}
$site_file = fopen("public/" . $name, "w");
fwrite($site_file, $site);
fclose($site_file);
}
}
// PRZENOSZENIE PLIKÓW CSS DO PUBLICZNEGO FOLDERU
foreach ($this->csss as $css){
$file = $this->src . "css/" . $css;
if(pathinfo($file, PATHINFO_EXTENSION) == "css" || pathinfo($file, PATHINFO_EXTENSION) == "scss"){
$name = basename($file);;
$style = file_get_contents($file);
$style_file = fopen("public/css/" . $name, "w");
fwrite($style_file, $style);
fclose($style_file);
}
}
// PRZENOSZENIE PLIKÓW JS DO PUBLICZNEGO FOLDERU
foreach ($this->jss as $js){
$file = $this->src . "js/" . $js;
if(pathinfo($file, PATHINFO_EXTENSION) == "js"){
$name = basename($file);
$script = file_get_contents($file);
$script_file = fopen("public/js/" . $name, "w");
fwrite($script_file, $script);
fclose($script_file);
}
}
}
}
$exec = new CompileIt();
$exec->main();
View File
+10 -5
View File
@@ -2,12 +2,17 @@
<html lang="pl">
<head>
<meta charset="UTF-8">
<title>Witaj świecie!</title>
<link rel="stylesheet" href="vendor/blog-engine/blog.css"/>
<script type="module" src="vendor/blog-engine/blog.js" defer></script>
<title>Witaj świecie! - Kwiatowy Blog</title>
<link rel='stylesheet' href='vendor/blog-engine/blog.css' />
<link rel='stylesheet' href='public/css/style.css' />
<meta name="author" content="Krzysiek Smaga">
<meta name="keywords" content="nowy, pierwszy, super">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>Witaj świecie!</h1>
<a href="be_login.php">Zaloguj się</a>
<h1>Kwiatowy Blog</h1>
<p>sdf</p>
</body>
<script src='vendor/blog-engine/blog.js'></script>
<script src='public/js/script.js'></script>
</html>
View File
+3 -1
View File
@@ -4,11 +4,13 @@
<meta charset="UTF-8">
<title>Witaj świecie! - {TITLE}</title>
{CSS}
{JS}
<meta name="author" content="{AUTHOR}">
<meta name="keywords" content="{KEYWORDS}">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>{TITLE}</h1>
<p>{DESCRIPTION}</p>
</body>
{JS}
</html>
+5 -4
View File
@@ -1,13 +1,14 @@
<?php
namespace BlogEngine {
require "_config.php";
class Dictionary {
public $page_tags = [
"{POSTS}" => "",
"{LINKS}" => "",
"{TAGS}" => "",
"{TITLE}" => "Tytuł",
"{AUTHOR}" => "lorem",
"{DESCRIPTION}" => "",
"{KEYWORDS}" => BLOG_TAGS,
"{TITLE}" => BLOG_TITLE,
"{AUTHOR}" => BLOG_AUTHOR,
"{DESCRIPTION}" => BLOG_DESC,
"{JS}" => "",
"{CSS}" => ""
];
+1
View File
@@ -0,0 +1 @@
1.0