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
+86 -19
View File
@@ -1,27 +1,94 @@
<?php <?php
require "vendor/blog-engine/php/Dictionary.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/"; // POBIERANIE ZAWARTOŚCI FOLDERU src
$html = scandir($src . "views"); $this->src = __DIR__ . "/src/";
$css = scandir($src . "css"); $this->htmls = scandir($src . "views");
$js = scandir($src . "js"); $this->csss = scandir($src . "css");
$this->jss = scandir($src . "js");
for($i = 2; $i < count($html); $i++){ //$this->version =
$site = file_get_contents($src . "views/" . $html[$i]); }
foreach (array_keys($dictionary->page_tags) as $page_tag){
if($page_tag = "{CSS}"){ public function main() : void{
for($j = 2; $j < count($css); $j++) $this->checkFolders();
$dictionary->page_tags[$page_tag] .= "<link rel='stylesheet' href='public/css/{$css[$j]}' />"; $this->compileFiles();
echo "Done";
}
/*
* 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");
}
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);
} }
if($page_tag = "{JS}"){ $site_file = fopen("public/" . $name, "w");
for($j = 2; $j < count($js); $j++) fwrite($site_file, $site);
$dictionary->page_tags[$page_tag] .= "<script src='public/js/{$js[$j]}'></script>"; fclose($site_file);
}
$site = str_replace($page_tag, $dictionary->page_tags[$page_tag], $site);
} }
echo $site;
} }
// 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
+15 -10
View File
@@ -1,13 +1,18 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="pl"> <html lang="pl">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Witaj świecie!</title> <title>Witaj świecie! - Kwiatowy Blog</title>
<link rel="stylesheet" href="vendor/blog-engine/blog.css"/> <link rel='stylesheet' href='vendor/blog-engine/blog.css' />
<script type="module" src="vendor/blog-engine/blog.js" defer></script> <link rel='stylesheet' href='public/css/style.css' />
</head> <meta name="author" content="Krzysiek Smaga">
<body> <meta name="keywords" content="nowy, pierwszy, super">
<h1>Witaj świecie!</h1> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<a href="be_login.php">Zaloguj się</a> </head>
</body> <body>
<h1>Kwiatowy Blog</h1>
<p>sdf</p>
</body>
<script src='vendor/blog-engine/blog.js'></script>
<script src='public/js/script.js'></script>
</html> </html>
View File
+3 -1
View File
@@ -4,11 +4,13 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Witaj świecie! - {TITLE}</title> <title>Witaj świecie! - {TITLE}</title>
{CSS} {CSS}
{JS}
<meta name="author" content="{AUTHOR}"> <meta name="author" content="{AUTHOR}">
<meta name="keywords" content="{KEYWORDS}">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head> </head>
<body> <body>
<h1>{TITLE}</h1> <h1>{TITLE}</h1>
<p>{DESCRIPTION}</p> <p>{DESCRIPTION}</p>
</body> </body>
{JS}
</html> </html>
+5 -4
View File
@@ -1,13 +1,14 @@
<?php <?php
namespace BlogEngine { namespace BlogEngine {
require "_config.php";
class Dictionary { class Dictionary {
public $page_tags = [ public $page_tags = [
"{POSTS}" => "", "{POSTS}" => "",
"{LINKS}" => "", "{LINKS}" => "",
"{TAGS}" => "", "{KEYWORDS}" => BLOG_TAGS,
"{TITLE}" => "Tytuł", "{TITLE}" => BLOG_TITLE,
"{AUTHOR}" => "lorem", "{AUTHOR}" => BLOG_AUTHOR,
"{DESCRIPTION}" => "", "{DESCRIPTION}" => BLOG_DESC,
"{JS}" => "", "{JS}" => "",
"{CSS}" => "" "{CSS}" => ""
]; ];
+1
View File
@@ -0,0 +1 @@
1.0