mirror of https://github.com/lxndrblz/anatole.git

Tom S
21.54.2021 9a491fbd75952b7b06183dfee7937ef80be43321
Tweak to taxonomy partials to reduce code duplication and add single point of change (#165)

2 files modified
1 files added
28 ■■■■ changed files
layouts/partials/taxonomy/categories.html 8 ●●●● patch | view | raw | blame | history
layouts/partials/taxonomy/tags.html 8 ●●●● patch | view | raw | blame | history
layouts/partials/taxonomy/template.html 12 ●●●●● patch | view | raw | blame | history
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>
{{ partial "taxonomy/template.html" (dict "items" . "linkClass" "category" "linkBase" "categories") }}
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>
{{ partial "taxonomy/template.html" (dict "items" . "linkClass" "tag" "linkBase" "tags") }}
layouts/partials/taxonomy/template.html
New file
@@ -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>