generate anchors on images
authorEduardo <[email protected]>
Sun, 26 Nov 2023 13:45:59 +0000 (14:45 +0100)
committerEduardo <[email protected]>
Sun, 26 Nov 2023 13:45:59 +0000 (14:45 +0100)
page-generator/generator.php
page-generator/index.php
src/assets/css/style.css

index 8af9c2d5a4486200a6d3e31ca82f221d3604ae8f..1b919a7a2bcf3ff5ac8e31e223b840604629a09c 100644 (file)
@@ -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 .= "<a href='$url' id='$id'>";
+
+        $html .= "<img";
+
+        if (!is_null($class)) {
+            $html .= ' class="' . implode(' ', $class) . '"';
+            print_r($class);
+        }
+
+        $html .= " src='$src' alt='$alt'";
+        
+        if (!is_null($title))
+            $html .= " title='$title'";
+
+        if (is_null($url) && !is_null($id))
+            $html .= " id='$id'";
+
+        $html .= "/>";
+
+        if (!is_null($url)) {
+            $html .= "</a>";
+        }
+
+        return $html;
+    }
+
     /**
      * Forms the html for a given array of data
      * 
index fcecec7b80aebc5fa0461ea7e909394554cfd718..d1ea3e16b6a2b1a42071e1af84a40320cbf9b7f5 100644 (file)
@@ -62,6 +62,13 @@ foreach ($data['images'] as $key => $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, '<section id="header">');
 
 // logo (if any, else probably just a broken image with nothing inside)
 $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, $generator->img($logo['path'], $logo['description'], $logo['title'], $logo['url'], $logo['id'], $logo['class']));
 
 $generator->writeToFile($header_path, '<div></div>');
 
@@ -134,9 +141,11 @@ $generator->writeToFile($header_path, '<nav id="menu">');
 
 $generator->writeToFile($header_path, '<ul>');
 foreach ($data['menu'] as $item) {
-    $generator->writeToFile($header_path, '<li>');
-    $generator->writeToFile($header_path, $generator->a('../' . $item['path'], $item['item'], null, null));
-    $generator->writeToFile($header_path, '</li>');
+    if (boolval($item['active'])) {
+        $generator->writeToFile($header_path, '<li>');
+        $generator->writeToFile($header_path, $generator->a('../' . $item['path'], $item['item'], null, null));
+        $generator->writeToFile($header_path, '</li>');    
+    }
 }
 $generator->writeToFile($header_path, '</ul>');
 
index 554d88860d6b2aef59f345df84b2e3acf23f4a2c..c522beb9c070fe7c4b33bdc1ba693e3d08697705 100644 (file)
@@ -90,7 +90,7 @@ body {
   margin-bottom: 35px;
 }
 
-#header > img {
+#header > #logo {
   flex-grow: 2;
   align-self: center;
   padding-top: 1.3vh;