|
41 | 41 | {{- if isset .Params "Title" -}} |
42 | 42 | {{- if ne .Params.Title "" -}} |
43 | 43 | {{- $.Scratch.Set "sharing_title" .Params.Title -}} |
| 44 | + {{- else -}} |
| 45 | + {{- $.Scratch.Set "sharing_title" .Title -}} |
44 | 46 | {{- end -}} |
45 | 47 | {{- else -}} |
46 | 48 | {{- if eq .Type "blog" -}} |
47 | | - {{- $.Scratch.Set "sharing_title" .Params.Title -}} |
| 49 | + {{- $.Scratch.Set "sharing_title" .Title -}} |
48 | 50 | {{- else -}} |
49 | 51 | {{- $.Scratch.Set "sharing_title" "devopsdays" -}} |
50 | 52 | {{- end -}} |
51 | 53 | {{- end -}} |
52 | 54 | {{- end -}} |
53 | 55 | {{- end -}} |
| 56 | +{{- /* Ensure sharing_title is always set */ -}} |
| 57 | +{{- if not ($.Scratch.Get "sharing_title") -}} |
| 58 | + {{- $.Scratch.Set "sharing_title" "devopsdays" -}} |
| 59 | +{{- end -}} |
| 60 | +{{- /* Build shares array as JavaScript string before script tag */ -}} |
| 61 | +{{- $shares := $.Scratch.Get "social_shares" -}} |
| 62 | +{{- if not $shares -}} |
| 63 | + {{- /* Default for non-event pages */ -}} |
| 64 | + {{- $shares = slice "email" (dict "share" "twitter" "via" ($.Scratch.Get "twitter_handle")) "facebook" "linkedin" -}} |
| 65 | +{{- end -}} |
| 66 | +{{- $shares_js := "" -}} |
| 67 | +{{- $first := true -}} |
| 68 | +{{- range $shares -}} |
| 69 | + {{- if not $first -}} |
| 70 | + {{- $shares_js = printf "%s, " $shares_js -}} |
| 71 | + {{- end -}} |
| 72 | + {{- if isset . "share" -}} |
| 73 | + {{- $shares_js = printf "%s{share: \"%s\", via: '%s'}" $shares_js .share ($.Scratch.Get "twitter_handle") -}} |
| 74 | + {{- else -}} |
| 75 | + {{- $shares_js = printf "%s\"%s\"" $shares_js . -}} |
| 76 | + {{- end -}} |
| 77 | + {{- $first = false -}} |
| 78 | +{{- end -}} |
| 79 | +{{- $.Scratch.Set "shares_js" $shares_js -}} |
54 | 80 |
|
55 | 81 | <script> |
56 | 82 | //shares |
|
59 | 85 | $(document).ready(function () { |
60 | 86 | //YOUR JQUERY CODE |
61 | 87 |
|
62 | | - {{- $shares := $.Scratch.Get "social_shares" -}} |
63 | | - {{- if not $shares -}} |
64 | | - {{- /* Default for non-event pages */ -}} |
65 | | - {{- $shares = slice "email" (dict "share" "twitter" "via" ($.Scratch.Get "twitter_handle")) "facebook" "linkedin" -}} |
66 | | - {{- end -}} |
67 | 88 | $("#share").jsSocials({ |
68 | | - shares: {{ $shares | jsonify }}, |
| 89 | + shares: [{{ $.Scratch.Get "shares_js" }}], |
69 | 90 | text: '{{ ($.Scratch.Get "sharing_title") }}', |
70 | 91 | showLabel: false, |
71 | 92 | showCount: false |
|
0 commit comments