fixed page listing for articles. Now single pages show up even if they're branches...
[theme-danix.xyz.git] / layouts / partials / breadcrumbs.html
diff --git a/layouts/partials/breadcrumbs.html b/layouts/partials/breadcrumbs.html
new file mode 100644 (file)
index 0000000..fd8cc6b
--- /dev/null
@@ -0,0 +1,28 @@
+<ol class="crumbs" itemscope itemtype="https://schema.org/BreadcrumbList">
+    {{- /* declare a 'variable' to store the each link position */}}
+    {{- $data := newScratch }}
+
+    {{- range $index, $value := .Ancestors.Reverse }}
+        <li class="crumb-item" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
+            {{- /* read the index from loop and add 'one', because it starts counting from zero */}}
+            {{- $data.Set "counter" $index }}
+            {{- $data.Add "counter" 1 }}
+            <a itemprop="item" href="{{.Permalink}}">
+                {{ if .IsHome }}
+                <span itemprop="name">home</span>
+                {{ else }}
+                <span itemprop="name">{{.Title}}</span>
+                {{ end }}
+            </a>
+            {{- /* pass the counter value into schema attribute */}}
+            <meta itemprop="position" content='{{ $data.Get "counter"}}' />
+        </li>         
+    {{- end }}
+        <li class="crumb-item active" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
+            {{- /* add 'one' one more time for the last link position */}}
+            {{- $data.Add "counter" 1 }}
+            <span itemprop="name">{{.Title}}</span>
+            {{- /* pass the counter value into schema attribute */}}
+            <meta itemprop="position" content='{{ $data.Get "counter"}}' />
+        </li>
+</ol>
\ No newline at end of file