Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle empty fields in friend shortcode properly #311

Merged
merged 3 commits into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/css/_partial/_single/_friend.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ $friend-link-hover-color-black: #ffffff;
width: 48%;
display: inline-block;
background: $friend-link-background-color;
vertical-align: top;
[theme="dark"] & {
background: $friend-link-background-color-dark;
}
Expand Down
2 changes: 1 addition & 1 deletion assets/js/theme.min.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions exampleSite/content/posts/tests/friend-link-tests/index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ hiddenFromSearch: true

{{< friend name="PCloud" url="https://github.com/HEIGE-PCloud/" avatar="https://avatars.githubusercontent.com/u/52968553?v=4" bio="This is PCloud as well~" >}}

{{< friend name="" url="" avatar="" bio="" >}}

{{< friend "PCloud" "https://github.com/HEIGE-PCloud/" "https://avatars.githubusercontent.com/u/52968553?v=4" "Awwwwww, toooooooo many PCloud🤔" >}}

{{< friend "this_is_a_long_long_long_long_name" "https://github.com/HEIGE-PCloud/" "https://avatars.githubusercontent.com/u/52968553?v=4" "this_is_a_long_long_long_long_long_long_long_bio" >}}

Large diffs are not rendered by default.

40 changes: 18 additions & 22 deletions layouts/shortcodes/friend.html
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
{{ if .IsNamedParams }}
{{- $avatar := .Get "avatar" -}}
<a target="_blank" href={{ .Get "url" }} title={{ .Get "name" }} class="friend-link">
<div class="friend-link-div">
<div class="friend-link-avatar">
{{- dict "Src" $avatar | partial "plugin/image.html" -}}
</div>
<div class="friend-link-info">
<div class="friend-name-div">
<i class="fas fa-user-circle fa-fw"></i>
<i class="friend-name">{{ .Get "name" }}</i>
</div>
<p class="friend-bio">{{ .Get "bio" }}</p>
</div>
</div>
</a>
{{- $title := "" -}}
{{- $link := "" -}}
{{- $avatar := "" -}}
{{- $bio := "" -}}
{{- if .IsNamedParams -}}
{{- $avatar = .Get "avatar" -}}
{{- $link = .Get "url" -}}
{{- $title = .Get "name" -}}
{{- $bio = .Get "bio" -}}
{{- else -}}
{{- $avatar := .Get 2 -}}
<a target="_blank" href={{ .Get 1 }} title={{ .Get 0 }} class="friend-link">
{{- $title = .Get 0 -}}
{{- $link = .Get 1 -}}
{{- $avatar = .Get 2 -}}
{{- $bio = .Get 3 -}}
{{- end -}}
<a target="_blank" href="{{- $link -}}" title="{{- $title -}}" class="friend-link">
<div class="friend-link-div">
<div class="friend-link-avatar">
{{- dict "Src" $avatar | partial "plugin/image.html" -}}
</div>
<div class="friend-link-info">
<div class="friend-name-div">
<i class="fas fa-user-circle fa-fw"></i>
<i class="friend-name">{{ .Get 0 }}</i>
<i class="friend-name">{{- $title -}}</i>
</div>
<p class="friend-bio">{{ .Get 3 }}</p>
<p class="friend-bio">{{- $bio -}}</p>
</div>
</div>
</a>
{{ end }}
</a>