From 9a491fbd75952b7b06183dfee7937ef80be43321 Mon Sep 17 00:00:00 2001
From: Tom S <67518109+Xen-Echo@users.noreply.github.com>
Date: Sun, 21 Mar 2021 10:54:27 +0000
Subject: [PATCH] Tweak to taxonomy partials to reduce code duplication and add single point of change (#165)

---
 layouts/partials/taxonomy/template.html   |   12 ++++++++++++
 layouts/partials/taxonomy/tags.html       |    8 +-------
 layouts/partials/taxonomy/categories.html |    8 +-------
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/layouts/partials/taxonomy/categories.html b/layouts/partials/taxonomy/categories.html
index 1643f71..e27db5d 100644
--- a/layouts/partials/taxonomy/categories.html
+++ b/layouts/partials/taxonomy/categories.html
@@ -1,7 +1 @@
-<span class="separator">
-    {{- range $index, $el := . -}}
-        {{- $category := replace . "#" "%23" -}}
-        {{- $category = replace $category "." "%2e" -}}
-        <a class="category" href="{{ ( printf "categories/%s/" ( $category | urlize ) ) | relLangURL }}">{{ . }}</a>
-    {{- end -}}
-</span>
\ No newline at end of file
+{{ partial "taxonomy/template.html" (dict "items" . "linkClass" "category" "linkBase" "categories") }}
\ No newline at end of file
diff --git a/layouts/partials/taxonomy/tags.html b/layouts/partials/taxonomy/tags.html
index 231edb4..9e9a380 100644
--- a/layouts/partials/taxonomy/tags.html
+++ b/layouts/partials/taxonomy/tags.html
@@ -1,7 +1 @@
-<span class="separator">
-    {{- range $index, $el := . -}}
-    {{- $tag := replace . "#" "%23" -}}
-    {{- $tag = replace $tag "." "%2e" -}}
-    <a class="tag" href="{{ ( printf "tags/%s/" ( $tag | urlize ) ) | relLangURL }}">{{- . -}}</a>
-    {{- end -}}
-</span>
\ No newline at end of file
+{{ partial "taxonomy/template.html" (dict "items" . "linkClass" "tag" "linkBase" "tags") }}
\ No newline at end of file
diff --git a/layouts/partials/taxonomy/template.html b/layouts/partials/taxonomy/template.html
new file mode 100644
index 0000000..a94d51b
--- /dev/null
+++ b/layouts/partials/taxonomy/template.html
@@ -0,0 +1,12 @@
+{{- $linkClass := .linkClass -}}
+{{- $linkBase := .linkBase -}}
+
+<span class="separator">
+    {{- range $index, $el := .items -}}
+        <!-- Replace certain special characters with their URL encoded counterparts -->
+        {{- $item := replace . "#" "%23" -}}
+        {{- $item = replace $item "." "%2e" -}}
+        {{- $link := ( printf "%s/%s/" $linkBase ( $item | urlize ) ) | relLangURL -}}
+        <a class="{{$linkClass}}" href="{{$link}}">{{- . -}}</a>
+    {{- end -}}
+</span>
\ No newline at end of file

--
Gitblit v1.10.0