removed hard coded theme paths

This commit is contained in:
Are0h 2021-06-03 13:08:01 -07:00
parent ca843773cd
commit ad763bf95f

View file

@ -7,12 +7,14 @@ class ThemeEngine
public $data = []; public $data = [];
public $loader; public $loader;
public $twig; public $twig;
public function __construct() public function __construct(string $themePath, string $themeAssetPath)
{ {
$this->themePath = $themePath;
$this->themeAssetPath = $themeAssetPath;
$path = explode("/", $themeAssetPath);
$this->themeFolder = $path[4];
$this->data = json_decode(file_get_contents("./config.json"), true); $this->data = json_decode(file_get_contents("./config.json"), true);
$this->loader = new \Twig\Loader\FilesystemLoader( $this->loader = new \Twig\Loader\FilesystemLoader($themePath);
"src/themes/theme-fipamo-default/"
);
$this->twig = new \Twig\Environment($this->loader, []); $this->twig = new \Twig\Environment($this->loader, []);
$this->router($_SERVER["REQUEST_URI"]); $this->router($_SERVER["REQUEST_URI"]);
} }
@ -22,8 +24,7 @@ class ThemeEngine
$pageInfo = [ $pageInfo = [
"keywords" => $this->data["keywords"], "keywords" => $this->data["keywords"],
"description" => $this->data["description"], "description" => $this->data["description"],
"image" => "image" => $this->themeAssetPath . "/assets/images/global/default-bg.jpg",
"/src/themes/theme-fipamo-default/fipamo-default/assets/images/global/default-bg.jpg",
]; ];
$menu = $this->data["menu"]; $menu = $this->data["menu"];
@ -31,13 +32,13 @@ class ThemeEngine
case "/": case "/":
$recent = $this->data["recent_posts"]; $recent = $this->data["recent_posts"];
$featured = $this->data["featured_posts"]; $featured = $this->data["featured_posts"];
$template = "fipamo-default/index.twig"; $template = $this->themeFolder . "/index.twig";
$pageOptions = [ $pageOptions = [
"debug" => true, "debug" => true,
"title" => "This is Fipamo", "title" => "This is Fipamo",
"background" => "background" =>
"/src/themes/theme-fipamo-default/fipamo-default/assets/images/global/default-bg.jpg", $this->themeAssetPath . "/assets/images/global/default-bg.jpg",
"recent" => $recent, "recent" => $recent,
"featured" => $featured, "featured" => $featured,
"info" => $pageInfo, "info" => $pageInfo,
@ -47,12 +48,12 @@ class ThemeEngine
case "/page": case "/page":
$content = $this->data["content"]; $content = $this->data["content"];
$meta = $this->data["meta"]; $meta = $this->data["meta"];
$template = "fipamo-default/page.twig"; $template = $this->themeFolder . "/page.twig";
$pageOptions = [ $pageOptions = [
"debug" => true, "debug" => true,
"title" => "Page Title", "title" => "Page Title",
"background" => "background" =>
"/src/themes/theme-fipamo-default/fipamo-default/assets/images/global/default-bg.jpg", $this->themeAssetPath . "/assets/images/global/default-bg.jpg",
"content" => $content, "content" => $content,
"meta" => $meta, "meta" => $meta,
"info" => $pageInfo, "info" => $pageInfo,
@ -61,12 +62,12 @@ class ThemeEngine
break; break;
case "/tags": case "/tags":
$tags = $this->data["tag_list"]; $tags = $this->data["tag_list"];
$template = "fipamo-default/tags.twig"; $template = $this->themeFolder . "/tags.twig";
$pageOptions = [ $pageOptions = [
"debug" => true, "debug" => true,
"title" => "Pages Tagged as Tag", "title" => "Pages Tagged as Tag",
"background" => "background" =>
"/src/themes/theme-fipamo-default/fipamo-default/assets/images/global/default-bg.jpg", $this->themeAssetPath . "/assets/images/global/default-bg.jpg",
"tag_list" => $tags, "tag_list" => $tags,
"info" => $pageInfo, "info" => $pageInfo,
"menu" => $menu, "menu" => $menu,
@ -74,12 +75,12 @@ class ThemeEngine
break; break;
case "/archive": case "/archive":
$archive = $this->data["archives"]; $archive = $this->data["archives"];
$template = "fipamo-default/archive.twig"; $template = $this->themeFolder . "/archive.twig";
$pageOptions = [ $pageOptions = [
"debug" => true, "debug" => true,
"title" => "Archive", "title" => "Archive",
"background" => "background" =>
"/src/themes/theme-fipamo-default/fipamo-default/assets/images/global/default-bg.jpg", $this->themeAssetPath . "/assets/images/global/default-bg.jpg",
"archives" => $archive, "archives" => $archive,
"info" => $pageInfo, "info" => $pageInfo,
"menu" => $menu, "menu" => $menu,
@ -95,4 +96,7 @@ class ThemeEngine
} }
} }
new ThemeEngine(); new ThemeEngine(
"src/themes/theme-fipamo-default",
"/src/themes/theme-fipamo-default/fipamo-default"
);