guoziyun 1 жил өмнө
parent
commit
8ca51105f1
2 өөрчлөгдсөн 9 нэмэгдсэн , 6 устгасан
  1. 4 3
      views/category.ejs
  2. 5 3
      views/tag.ejs

+ 4 - 3
views/category.ejs

@@ -14,6 +14,7 @@
     <link rel="stylesheet" href="/stylesheets/header.css">
     <link rel="stylesheet" href="/stylesheets/category.css">
 
+    <% if (data.length > 0) { %>
     <script type="application/ld+json">
       {
         "@context": "https://schema.org",
@@ -35,7 +36,7 @@
         "keywords": "coloring pages categories, animal coloring page, plant coloring page, people coloring page, fantasy coloring page, famous coloring page, printable, free coloring pages, art, color by number, paint by number",
         "contentRating": "General Audience",
         "hasPart": [
-          <% for(let i = 0; i < 6; i++) { %>
+          <% for(let i = 0; i < Math.min(6, data.length); i++) { %>
             {
               "@type": "ImageObject",
               "name": "<%= data[i].title %>",
@@ -44,12 +45,12 @@
               "thumbnailUrl": "<%= data[i].thumb %>",
               "height": "480",
               "width": "480"
-            }<%= i < 5 ? ',' : '' %>
+            }<%= i < Math.min(6, data.length) - 1 ? ',' : '' %>
           <% }; %>
         ]
       }
   </script>
-
+  <% } %>
 </head>
 <!-- Google tag (gtag.js) -->
 <script async src="https://www.googletagmanager.com/gtag/js?id=G-JBGGVGLHTP"></script>

+ 5 - 3
views/tag.ejs

@@ -14,6 +14,8 @@
     <link rel="stylesheet" href="/stylesheets/header.css">
     <link rel="stylesheet" href="/stylesheets/tag.css">
 
+
+    <% if (data.length > 0) { %>
     <script type="application/ld+json">
       {
         "@context": "https://schema.org",
@@ -35,7 +37,7 @@
         "keywords": "coloring pages tags, girl coloring page, animal coloring page, flower coloring page, fish coloring page, bird coloring page, printable, free coloring pages, art, color by number, paint by number",
         "contentRating": "General Audience",
         "hasPart": [
-          <% for(let i = 0; i < 6; i++) { %>
+          <% for(let i = 0; i < Math.min(6, data.length); i++) { %>
             {
               "@type": "ImageObject",
               "name": "<%= data[i].title %>",
@@ -44,12 +46,12 @@
               "thumbnailUrl": "<%= data[i].thumb %>",
               "height": "480",
               "width": "480"
-            }<%= i < 5 ? ',' : '' %>
+            }<%= i < Math.min(6, data.length) - 1 ? ',' : '' %>
           <% }; %>
         ]
       }
   </script>
-
+  <% } %>
 </head>
 <!-- Google tag (gtag.js) -->
 <script async src="https://www.googletagmanager.com/gtag/js?id=G-JBGGVGLHTP"></script>