|
21 | 21 | {{- $sharing_title := (printf "devopsdays %s - %s" $e.city $e.year) -}} |
22 | 22 | {{- $.Scratch.Set "sharing_title" $sharing_title -}} |
23 | 23 | {{- end -}} |
| 24 | + {{- /* Build social shares array based on event configuration or use defaults */ -}} |
| 25 | + {{- $shares := slice -}} |
| 26 | + {{- if $e.social_shares -}} |
| 27 | + {{- range $e.social_shares -}} |
| 28 | + {{- if eq . "twitter" -}} |
| 29 | + {{- $shares = $shares | append (dict "share" "twitter" "via" ($.Scratch.Get "twitter_handle")) -}} |
| 30 | + {{- else -}} |
| 31 | + {{- $shares = $shares | append . -}} |
| 32 | + {{- end -}} |
| 33 | + {{- end -}} |
| 34 | + {{- else -}} |
| 35 | + {{- /* Default: all social share buttons */ -}} |
| 36 | + {{- $shares = slice "email" (dict "share" "twitter" "via" ($.Scratch.Get "twitter_handle")) "facebook" "linkedin" -}} |
| 37 | + {{- end -}} |
| 38 | + {{- $.Scratch.Set "social_shares" $shares -}} |
24 | 39 | {{- else -}} |
25 | 40 | {{- $.Scratch.Set "twitter_handle" "devopsdays" -}} |
26 | 41 | {{- if isset .Params "Title" -}} |
27 | 42 | {{- if ne .Params.Title "" -}} |
28 | 43 | {{- $.Scratch.Set "sharing_title" .Params.Title -}} |
| 44 | + {{- else -}} |
| 45 | + {{- $.Scratch.Set "sharing_title" .Title -}} |
29 | 46 | {{- end -}} |
30 | 47 | {{- else -}} |
31 | 48 | {{- if eq .Type "blog" -}} |
32 | | - {{- $.Scratch.Set "sharing_title" .Params.Title -}} |
| 49 | + {{- $.Scratch.Set "sharing_title" .Title -}} |
33 | 50 | {{- else -}} |
34 | 51 | {{- $.Scratch.Set "sharing_title" "devopsdays" -}} |
35 | 52 | {{- end -}} |
36 | 53 | {{- end -}} |
| 54 | + {{- /* Set default shares for non-event pages */ -}} |
| 55 | + {{- $default_shares := slice "email" (dict "share" "twitter" "via" "devopsdays") "facebook" "linkedin" -}} |
| 56 | + {{- $.Scratch.Set "social_shares" $default_shares -}} |
37 | 57 | {{- end -}} |
38 | 58 | {{- end -}} |
| 59 | +{{- /* Ensure sharing_title is always set */ -}} |
| 60 | +{{- if not ($.Scratch.Get "sharing_title") -}} |
| 61 | + {{- $.Scratch.Set "sharing_title" "devopsdays" -}} |
| 62 | +{{- end -}} |
| 63 | +{{- /* Build shares array as JavaScript string before script tag */ -}} |
| 64 | +{{- $shares := $.Scratch.Get "social_shares" -}} |
| 65 | +{{- if or (not $shares) (eq (len $shares) 0) -}} |
| 66 | + {{- /* Default for non-event pages */ -}} |
| 67 | + {{- $shares = slice "email" (dict "share" "twitter" "via" ($.Scratch.Get "twitter_handle")) "facebook" "linkedin" -}} |
| 68 | +{{- end -}} |
| 69 | +{{- $shares_js_parts := slice -}} |
| 70 | +{{- range $shares -}} |
| 71 | + {{- $share_str := "" -}} |
| 72 | + {{- $current_item := . -}} |
| 73 | + {{- if eq $current_item "email" -}} |
| 74 | + {{- $share_str = "\"email\"" -}} |
| 75 | + {{- else if eq $current_item "facebook" -}} |
| 76 | + {{- $share_str = "\"facebook\"" -}} |
| 77 | + {{- else if eq $current_item "linkedin" -}} |
| 78 | + {{- $share_str = "\"linkedin\"" -}} |
| 79 | + {{- else -}} |
| 80 | + {{- $twitter_share_val := index $current_item "share" -}} |
| 81 | + {{- if $twitter_share_val -}} |
| 82 | + {{- $share_str = printf "{share: \"%s\", via: '%s'}" $twitter_share_val ($.Scratch.Get "twitter_handle") -}} |
| 83 | + {{- end -}} |
| 84 | + {{- end -}} |
| 85 | + {{- if $share_str -}} |
| 86 | + {{- $shares_js_parts = $shares_js_parts | append $share_str -}} |
| 87 | + {{- end -}} |
| 88 | +{{- end -}} |
| 89 | +{{- $shares_js_str := delimit $shares_js_parts ", " -}} |
| 90 | +{{- if not $shares_js_str -}} |
| 91 | + {{- $shares_js_str = "\"email\", {share: \"twitter\", via: 'devopsdays'}, \"facebook\", \"linkedin\"" -}} |
| 92 | +{{- end -}} |
| 93 | +{{- $sharing_title_final := $.Scratch.Get "sharing_title" -}} |
| 94 | +{{- if not $sharing_title_final -}} |
| 95 | + {{- $sharing_title_final = "devopsdays" -}} |
| 96 | +{{- end -}} |
| 97 | +{{- $full_script := printf "$(document).ready(function () {\n //YOUR JQUERY CODE\n\n $(\"#share\").jsSocials({\n shares: [%s],\n text: '%s',\n showLabel: false,\n showCount: false\n });\n});" $shares_js_str $sharing_title_final -}} |
39 | 98 |
|
40 | 99 | <script> |
41 | 100 | //shares |
42 | 101 |
|
43 | 102 |
|
44 | | -$(document).ready(function () { |
45 | | - //YOUR JQUERY CODE |
46 | | - |
47 | | - $("#share").jsSocials({ |
48 | | - shares: ["email", {share: "twitter", via: '{{ $.Scratch.Get "twitter_handle" }}'}, "facebook", "linkedin"], |
49 | | - text: '{{ ($.Scratch.Get "sharing_title") }}', |
50 | | - showLabel: false, |
51 | | - showCount: false |
52 | | - }); |
53 | | -}); |
| 103 | +{{ $full_script | safeJS }} |
54 | 104 |
|
55 | 105 | </script> |
0 commit comments