From: Eduardo Date: Sun, 12 Nov 2023 19:34:02 +0000 (+0100) Subject: move all data loaded from server to the same region X-Git-Url: http://git.edufdez.es/?a=commitdiff_plain;h=b08d90684c155d1937feb6c4b505ab02ae9ab37b;p=thericegoat.com.git move all data loaded from server to the same region --- diff --git a/page-generator/index.php b/page-generator/index.php index 2b68714..a4b35b6 100644 --- a/page-generator/index.php +++ b/page-generator/index.php @@ -13,33 +13,47 @@ $generator = new CodeGenerator(); // 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 @@ -48,7 +62,7 @@ $generator->writeToFile($head_path, ' '); -foreach ($head_data as $item) { +foreach ($data['header'] as $item) { switch ($item['type']) { case 'meta': $generator->writeToFile($head_path, ''); @@ -73,16 +87,12 @@ $generator->writeToFile($head_path, ' #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, '