From 55c9ecf052b548fdd2a5beea6d5d3a5931dca503 Mon Sep 17 00:00:00 2001 From: Eduardo Date: Sun, 26 Nov 2023 20:23:24 +0100 Subject: [PATCH] image generation in pages --- page-generator/generator.php | 29 ++++++++++++++++++++++------- page-generator/index.php | 12 ++++++++++++ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/page-generator/generator.php b/page-generator/generator.php index 713e7ed..4a1129b 100644 --- a/page-generator/generator.php +++ b/page-generator/generator.php @@ -144,34 +144,38 @@ class CodeGenerator * @param string | null $id - id for the image, if $url is not null used for the anchor tag else for the image tag * @param array | null $class - array of classes for the image */ - public function img(string $src, string $alt, string | null $title, string | null $url, string | null $id, array | null $class): string + public function img(string $src, string | null $alt, string | null $title, string | null $url, string | null $id, array | null $class): string { $html = ""; - if (!is_null($url)) { + if (!empty($url)) { $html .= ""; } $html .= "str_val_or_empty($line, 'url'); $title = $this->str_val_or_empty($line, 'title'); $class = array_map('trim', explode(",", $this->str_val_or_empty($line, 'class'))); + $image = null; + + if (!empty($line['image'])) { + $image = $line['image']; + } // if new-col close p and ul and open div with col class if (in_array("new-col", $class)) { @@ -219,6 +228,12 @@ class CodeGenerator $is_div_closed = false; } + // if image is set add image and skipt switch + if (!is_null($image)) { + $html .= $this->img($image['path'], $image['description'], $image['title'], $image['url'], $image['id'], $image['class']); + continue; + } + switch ($class) { case in_array("list", $class): // if previous iteration was diferent section close li diff --git a/page-generator/index.php b/page-generator/index.php index 8c884c2..ec85636 100644 --- a/page-generator/index.php +++ b/page-generator/index.php @@ -209,6 +209,18 @@ foreach ($data['pages'] as $page) { $page_data = $data['pages'][$page['path']]; + // put image object in page_data + foreach ($page_data as $dKey => $line) { + if (!empty($line['image'])) { + foreach ($data['images'] as $image) { + if ($image['id'] == $line['image']) { + $page_data[$dKey]['image'] = $image; + break; + } + } + } + } + // generate page $generator->writeToFile($page_path, $generator->form_html($page_data, "en")); $generator->writeToFile($page_path, ''); -- 2.30.2