Skip to content

Commit

Permalink
fix: render links only if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
reuixiy committed Mar 4, 2020
1 parent 075c8d2 commit fc0fae8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
28 changes: 15 additions & 13 deletions layouts/partials/pages/home-footage.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ <h1>{{ .Site.Params.homeTitle }}</h1>
<div class="description">{{ .Site.Params.homeDescription }}</div>
<div class="keywords">{{ .Site.Params.homeKeywords }}</div>
</div>
<div class="links">
{{ $length := sub (len .Site.Menus.home) 1 }}
{{ range $index, $value := .Site.Menus.home }}
{{- $linkType := (string .Pre) -}}
{{- $iconName := (string .Post) -}}
{{- $icon := (index $.Site.Data.SVG $iconName) -}}
<a href="{{ .URL }}"{{ if eq $linkType "external" }} target="_blank" rel="external noopener"{{ end }}>{{ replace $icon "icon" (printf `icon %s` .Identifier) | safeHTML }}{{ .Name }}</a>
{{- if lt $index $length -}}
{{- $.Site.Params.homeLinksDelimiter -}}
{{- end -}}
{{ end }}
</div>
{{ with .Site.Menus.home }}
<div class="links">
{{ $length := sub (len .) 1 }}
{{ range $index, $value := . }}
{{- $linkType := (string .Pre) -}}
{{- $iconName := (string .Post) -}}
{{- $icon := (index $.Site.Data.SVG $iconName) -}}
<a href="{{ .URL }}"{{ if eq $linkType "external" }} target="_blank" rel="external noopener"{{ end }}>{{ replace $icon "icon" (printf `icon %s` .Identifier) | safeHTML }}{{ .Name }}</a>
{{- if lt $index $length -}}
{{- $.Site.Params.homeLinksDelimiter -}}
{{- end -}}
{{ end }}
</div>
{{ end }}
</div>
</main>
</main>
20 changes: 11 additions & 9 deletions layouts/partials/pages/home-poetry.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
<p>{{ $Content | safeHTML }}</p>
{{ end }}
</div>
<div class="links">
{{ range .Site.Menus.home }}
{{- $linkType := (string .Pre) -}}
{{- $iconName := (string .Post) -}}
{{- $icon := (index $.Site.Data.SVG $iconName) -}}
<a href="{{ .URL }}" class="links-item"{{ if eq $linkType "external" }} target="_blank" rel="noopener"{{ end }}>{{ replace $icon "icon" (printf `icon %s` .Identifier) | safeHTML }}{{ .Name }}</a>
{{ end }}
</div>
</main>
{{ with .Site.Menus.home }}
<div class="links">
{{ range . }}
{{- $linkType := (string .Pre) -}}
{{- $iconName := (string .Post) -}}
{{- $icon := (index $.Site.Data.SVG $iconName) -}}
<a href="{{ .URL }}" class="links-item"{{ if eq $linkType "external" }} target="_blank" rel="noopener"{{ end }}>{{ replace $icon "icon" (printf `icon %s` .Identifier) | safeHTML }}{{ .Name }}</a>
{{ end }}
</div>
{{ end }}
</main>

0 comments on commit fc0fae8

Please sign in to comment.