// create new folder (dont remove the old one yet)
mkdir(BASE_PATH_TEMP);
+#region load data
+
+function load_data(string $url): mixed
+{
+ $data = file_get_contents($url);
+ $data = json_decode($data, true);
+ return $data;
+}
+
+$data = [];
+$data['langs'] = load_data(URL . '?sheet=_langs');
+$data['images'] = load_data(URL . '?sheet=_images');
+$data['header'] = load_data(URL . '?sheet=_header');
+$data['footer'] = load_data(URL . '?sheet=_footer');
+$data['menu'] = load_data(URL . '?sheet=_menu');
+$data['pages'] = load_data(URL . '?sheet=_pages');
+
+#endregion
+
+#region assets and images
+
// copy assets
mkdir(BASE_PATH_TEMP . "/assets");
$generator->copyRecursive(SRC_PATH . "/assets", BASE_PATH_TEMP . "/assets");
-// get images sheet
-$image_list = file_get_contents(URL . '?sheet=_images');
-$image_list = json_decode($image_list, true);
-
// copy images from whatever they are (if this is in a docker container they may be mounted somewhere)
-foreach ($image_list as $key => $image) {
+foreach ($data['images'] as $key => $image) {
$old_path = SRC_PATH . $image['path'];
$new_path = BASE_PATH_TEMP . "/assets/img/" . $image['id'] . '.' . pathinfo($image['path'], PATHINFO_EXTENSION);
copy($old_path, $new_path);
- $image_list[$key]['path'] = "../../assets/img/" . $image['id'] . '.' . pathinfo($image['path'], PATHINFO_EXTENSION);
+ $data['images'][$key]['path'] = "../../assets/img/" . $image['id'] . '.' . pathinfo($image['path'], PATHINFO_EXTENSION);
}
// create partials:
$partialsPath = BASE_PATH_TEMP . "/partials";
mkdir($partialsPath);
+#endregion
#region head
-// get head data
-$head_data = file_get_contents(URL . '?sheet=_header');
-$head_data = json_decode($head_data, true);
-
$head_path = $partialsPath . "/head.html";
// generate head
<html lang="' . $generator->templateVar("lang-code") . '">
<head>');
-foreach ($head_data as $item) {
+foreach ($data['header'] as $item) {
switch ($item['type']) {
case 'meta':
$generator->writeToFile($head_path, '<meta ' . $item['value'] . '>');
#endregion
#region footer
-// get footer data
-$footer_data = file_get_contents(URL . '?sheet=_footer');
-$footer_data = json_decode($footer_data, true);
-
// generate footer
$footer_path = $partialsPath . "/footer.html";
$generator->writeToFile($footer_path, '<section id="footer"><p>');
$footer_line = 1;
-foreach ($footer_data as $item) {
+foreach ($data['footer'] as $item) {
if ($item['line'] != $footer_line) {
$footer_line = $item['line'];
$generator->writeToFile($footer_path, '<br>');
$generator->writeToFile($header_path, '<section id="header">');
// logo (if any, else probably just a broken image with nothing inside)
-$logo = $image_list[array_search("logo", array_column($image_list, "id"))];
+$logo = $data['images'][array_search("logo", array_column($data['images'], "id"))];
$generator->writeToFile($header_path, '<img src="' . $logo['path'] . '" alt="' . $logo['description'] . '" />');
$generator->writeToFile($header_path, '<nav id="menu">');
$generator->writeToFile($header_path, '<ul>');
-foreach ($menu_list as $item) {
+foreach ($data['menu'] as $item) {
$generator->writeToFile($header_path, '<li>');
$generator->writeToFile($header_path, $generator->a('../' . $item['path'], $item['item']));
$generator->writeToFile($header_path, '</li>');
// populate page array with paths
$page_array = [];
-foreach ($menu_list as $item)
+foreach ($data['menu'] as $item)
foreach ($item as $key => $value)
if ($key == 'path')
$page_array[] = $value;
foreach ($menu_list as $item)
$path_title[$item['path']] = $item['title'];
-// get page list
-$page_list = file_get_contents(URL . '?sheet=_pages');
-$page_list = json_decode($page_list, true);
-
-foreach ($page_list as $page) {
+foreach ($data['pages'] as $page) {
$page_path = BASE_PATH_TEMP . "/pages/" . $page['path'] . "/index.html";
// put page title in header
}
// get page data
- $page_data = file_get_contents(URL . '?sheet=' . $page['path']);
- $page_data = json_decode($page_data, true);
+
+ if (empty($data['pages'][$page['path']]))
+ $data['pages'][$page['path']] = load_data(URL . '?sheet=' . $page['path']);
+
+ $page_data = $data['pages'][$page['path']];
switch ($page["type"]) {
case '1-col':