Skip to content

Commit e4a8438

Browse files
author
Zab
committed
Modify hugo conditions to check for available content before displaying the ra section
1 parent ac51c23 commit e4a8438

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

layouts/partials/default.html

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -75,40 +75,39 @@ <h2 class="mb-5" id="title">{{ .Title }}</h2>
7575
</nav>
7676

7777
<!-- Related Articles Section -->
78-
{{if .Content}}
79-
<section class="my-3 py-3" id="related-articles">
80-
{{ $c := .Section }}
81-
{{ $p := .Params.Categories }}
82-
{{ $t := .Params.Title }}
83-
{{ $ignore := "alert"}}
84-
<h5 class="text-center">Related Articles</h5>
85-
<div class="row">
86-
{{ range $key, $taxonomy := .Site.Taxonomies.categories }}
87-
{{ if eq $key $p }}
88-
{{ if ne $key $ignore}}
89-
{{ range shuffle ($taxonomy.Pages) | first $.Site.Params.article_count }}
90-
{{ if ne .Title $t }}
91-
<div class="col-sm-4 my-2">
92-
<a href="{{ .Permalink }}">
93-
<div class="card text-center">
94-
{{ if isset .Params "image" }}
95-
<img class="card-img-top" {{ with .Params.image }} src="{{ . }}"{{ end }} alt="{{ .Params.Title }}">
96-
{{ end }}
97-
<div class="card-body">
98-
<h5 class="card-title">{{ .Title }}</h5>
99-
<p class="card-subtitle mb-2 text-muted">{{ .Params.Description }}</p>
100-
</div>
101-
</div>
102-
</a>
78+
{{ $c := .Section }}
79+
{{ $p := .Params.Categories }}
80+
{{ $t := .Params.Title }}
81+
{{ $ignore := "alert"}}
82+
83+
{{ range $key, $taxonomy := .Site.Taxonomies.categories }}
84+
{{ if eq $key $p }}
85+
{{ if ne $key $ignore}}
86+
{{ range shuffle ($taxonomy.Pages) | first $.Site.Params.article_count }}
87+
{{ if ne .Title $t }}
88+
<section class="my-3 py-3" id="related-articles">
89+
<h5 class="text-center">Related Articles</h5>
90+
<div class="row">
91+
<div class="col-sm-4 my-2">
92+
<a href="{{ .Permalink }}">
93+
<div class="card text-center">
94+
{{ if isset .Params "image" }}
95+
<img class="card-img-top" {{ with .Params.image }} src="{{ . }}"{{ end }} alt="{{ .Params.Title }}">
96+
{{ end }}
97+
<div class="card-body">
98+
<h5 class="card-title">{{ .Title }}</h5>
99+
<p class="card-subtitle mb-2 text-muted">{{ .Params.Description }}</p>
100+
</div>
103101
</div>
104-
{{ end }}
105-
{{ end }}
106-
{{ end }}
107-
{{ end }}
102+
</a>
103+
</div>
104+
</div>
105+
</section>
108106
{{ end }}
109-
</div>
110-
</section>
111-
{{end}}
107+
{{ end }}
108+
{{ end }}
109+
{{ end }}
110+
{{ end }}
112111
<!-- End of related articles section -->
113112

114113
</div>

0 commit comments

Comments
 (0)