Skip to content

Commit

Permalink
Modify hugo conditions to check for available content before displayi…
Browse files Browse the repository at this point in the history
…ng the ra section
  • Loading branch information
Zab committed Mar 11, 2022
1 parent ac51c23 commit e4a8438
Showing 1 changed file with 31 additions and 32 deletions.
63 changes: 31 additions & 32 deletions layouts/partials/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,40 +75,39 @@ <h2 class="mb-5" id="title">{{ .Title }}</h2>
</nav>

<!-- Related Articles Section -->
{{if .Content}}
<section class="my-3 py-3" id="related-articles">
{{ $c := .Section }}
{{ $p := .Params.Categories }}
{{ $t := .Params.Title }}
{{ $ignore := "alert"}}
<h5 class="text-center">Related Articles</h5>
<div class="row">
{{ range $key, $taxonomy := .Site.Taxonomies.categories }}
{{ if eq $key $p }}
{{ if ne $key $ignore}}
{{ range shuffle ($taxonomy.Pages) | first $.Site.Params.article_count }}
{{ if ne .Title $t }}
<div class="col-sm-4 my-2">
<a href="{{ .Permalink }}">
<div class="card text-center">
{{ if isset .Params "image" }}
<img class="card-img-top" {{ with .Params.image }} src="{{ . }}"{{ end }} alt="{{ .Params.Title }}">
{{ end }}
<div class="card-body">
<h5 class="card-title">{{ .Title }}</h5>
<p class="card-subtitle mb-2 text-muted">{{ .Params.Description }}</p>
</div>
</div>
</a>
{{ $c := .Section }}
{{ $p := .Params.Categories }}
{{ $t := .Params.Title }}
{{ $ignore := "alert"}}

{{ range $key, $taxonomy := .Site.Taxonomies.categories }}
{{ if eq $key $p }}
{{ if ne $key $ignore}}
{{ range shuffle ($taxonomy.Pages) | first $.Site.Params.article_count }}
{{ if ne .Title $t }}
<section class="my-3 py-3" id="related-articles">
<h5 class="text-center">Related Articles</h5>
<div class="row">
<div class="col-sm-4 my-2">
<a href="{{ .Permalink }}">
<div class="card text-center">
{{ if isset .Params "image" }}
<img class="card-img-top" {{ with .Params.image }} src="{{ . }}"{{ end }} alt="{{ .Params.Title }}">
{{ end }}
<div class="card-body">
<h5 class="card-title">{{ .Title }}</h5>
<p class="card-subtitle mb-2 text-muted">{{ .Params.Description }}</p>
</div>
</div>
{{ end }}
{{ end }}
{{ end }}
{{ end }}
</a>
</div>
</div>
</section>
{{ end }}
</div>
</section>
{{end}}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
<!-- End of related articles section -->

</div>
Expand Down

0 comments on commit e4a8438

Please sign in to comment.