From 9e123521d19ce54fa59d989038eacf12b7950fe5 Mon Sep 17 00:00:00 2001 From: Eduardo Date: Sun, 26 Nov 2023 14:45:59 +0100 Subject: [PATCH] generate anchors on images --- page-generator/generator.php | 41 ++++++++++++++++++++++++++++++++++++ page-generator/index.php | 17 +++++++++++---- src/assets/css/style.css | 2 +- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/page-generator/generator.php b/page-generator/generator.php index 8af9c2d..1b919a7 100644 --- a/page-generator/generator.php +++ b/page-generator/generator.php @@ -126,6 +126,47 @@ class CodeGenerator return $html; } + /** + * Returns a string with an image tag + * + * @param string $src - path to the image + * @param string $alt - alt text for the image + * @param string | null $title - title for the image + * @param string | null $url - url to link the image to + * @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 + */ + function img(string $src, string $alt, string | null $title, string | null $url, string | null $id, array | null $class): string + { + $html = ""; + + if (!is_null($url)) + $html .= ""; + + $html .= " $image) { $data['images'][$key]['path'] = "../../assets/img/" . $image['id'] . '.' . pathinfo($image['path'], PATHINFO_EXTENSION); } +// format image classes +foreach ($data['images'] as $key => $image) { + if (empty($image['class'])) + $data['images'][$key]['class'] = null; + else + $data['images'][$key]['class'] = array_map('trim', explode(",", $image['class'])); +} // create partials: $partialsPath = BASE_PATH_TEMP . "/partials"; @@ -126,7 +133,7 @@ $generator->writeToFile($header_path, '