Skip to content

Commit

Permalink
Improve author types icons operating
Browse files Browse the repository at this point in the history
Extract icon class type associations as parameters, reduces maintenance costs and the number of lines of code.
  • Loading branch information
clementbiron committed Jan 27, 2023
1 parent f5936ca commit aadaa8b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
12 changes: 12 additions & 0 deletions config/_default/params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,15 @@ homepage_featured:
- revenu_de_base
- rapu_ture
- nsw_legislation_explorer
showcase:
author:
types:
icons:
default: user
individual: user
collective: users
ngo: globe
research_center: graduation-ap
business: factory
local_government: building
national_government: landmark
2 changes: 1 addition & 1 deletion themes/OpenFisca-2022/layouts/_default/showcase.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="cards">
{{ range $.Site.Data.showcase }}
{{ $description := index .description $.Site.Language.Lang }}
{{ partial "card.html" (dict "title" .title "description" $description "country" .country "website" .website "author" .author) . }}
{{ partial "card.html" (dict "title" .title "description" $description "country" .country "website" .website "author" .author "Site" $.Site) }}
{{ end }}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion themes/OpenFisca-2022/layouts/_default/styleguide.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h2 class="grid_col-12 text-center">Built with OpenFisca</h2>
<div class="cards">
{{ range $.Site.Data.showcase }}
{{ $description := index .description $.Site.Language.Lang }}
{{ partial "card.html" (dict "title" .title "description" $description "country" .country "website" .website "author" .author) . }}
{{ partial "card.html" (dict "title" .title "description" $description "country" .country "website" .website "author" .author "Site" $.Site) }}
{{ end }}
{{ partial "card.html" (dict "title" "Laboris nisi ut aliquip" "description" "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." "country" "FR" "website" "https://www.openfisca.org" "tags" $tags) . }}
</div>
Expand Down
2 changes: 1 addition & 1 deletion themes/OpenFisca-2022/layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h2 class="grid_col-12 text-center">{{ .Params.build_with.title }}</h2>
{{ range $slug := .Param "homepage_featured" }}
{{ $showcase := index $.Site.Data.showcase $slug }}
{{ $description := index $showcase.description $.Site.Language.Lang }}
{{ partial "card.html" (dict "title" $showcase.title "description" $description "country" $showcase.country "website" $showcase.website "author" $showcase.author) . }}
{{ partial "card.html" (dict "title" $showcase.title "description" $description "country" $showcase.country "website" $showcase.website "author" $showcase.author "Site" $.Site) }}
{{ end }}
</div>
<div class="grid_col-12 text-center mt-xl2">
Expand Down
27 changes: 12 additions & 15 deletions themes/OpenFisca-2022/layouts/partials/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
{{ $imageSrc = $newImageSrc}}
{{ end }}

{{ $authorType := .Site.Params.showcase.author.types.icons.default }}
{{ with .author }}{{ with .type }}{{ $authorType = . }}{{ end }}{{ end }}
{{ $authorTypeIcon := index .Site.Params.showcase.author.types.icons $authorType }}

<div class="card {{ if .website }}card-hasLink{{ end }}">
<div class="card_image">
<img class="screenshot" src="{{ $imageSrc }}" alt="{{ .title }}" />
Expand All @@ -26,21 +30,14 @@ <h3 class="card_title">{{ .title }}</h3>
</div>
{{ end }}
<a class="card_link" target="_blank" href="{{ .website | safeURL }}">{{ .website | safeURL }}</a>
{{ with .author }}
{{ with .author }}{{ with .name }}
<div class="card_author">
<div class="card_author_icon iconWrapper iconWrapper-rounded">
{{ $iconClass := "user" }}
{{ with (eq $.author.type "collective") }} {{ $iconClass = "users" }} {{ end }}
{{ with (eq $.author.type "ngo") }} {{ $iconClass = "globe" }} {{ end }}
{{ with (eq $.author.type "research_center") }} {{ $iconClass = "graduation-cap" }} {{ end }}
{{ with (eq $.author.type "business") }} {{ $iconClass = "factory" }} {{ end }}
{{ with (eq $.author.type "local_government") }} {{ $iconClass = "building" }} {{ end }}
{{ with (eq $.author.type "national_government") }} {{ $iconClass = "landmark" }} {{ end }}
<i icon-name="{{ $iconClass }}"></i>
</div>
<div class="card_author_name">
{{ with $.author.name }}{{ . }}{{ end }}
</div>
<div class="card_author_icon iconWrapper iconWrapper-rounded">
<i icon-name="{{ $authorTypeIcon }}"></i>
</div>
<div class="card_author_name">
{{ . }}
</div>
</div>
{{ end }}
{{ end }}{{ end }}
</div>

0 comments on commit aadaa8b

Please sign in to comment.