mirror of https://github.com/theNewDynamic/gohugo-theme-ananke.git

Velimir Đurković
2 days ago 55120c7e8981919aa51d57a8e0abe1b1f50d6c66
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
{{- $main_style := dict -}}
{{- $assets_to_concat := collections.Slice -}}
 
{{/* Custom CSS configuration with backwards-compatible deprecated fallback. */}}
{{- $custom_css := collections.Slice -}}
{{- $has_ananke_custom_css := false -}}
 
{{- with site.Params.ananke -}}
  {{- $has_ananke_custom_css = collections.IsSet . "custom_css" -}}
  {{- if $has_ananke_custom_css -}}
    {{- $custom_css = .custom_css | default collections.Slice -}}
  {{- end -}}
{{- end -}}
 
{{- if not $has_ananke_custom_css -}}
  {{- if collections.IsSet site.Params "custom_css" -}}
    {{- fmt.Warnf "[ananke] %s" "Parameter site.Params.custom_css is deprecated. Use site.Params.ananke.custom_css instead." -}}
    {{- $custom_css = site.Params.custom_css | default collections.Slice -}}
  {{- end -}}
{{- end -}}
 
{{/* Tachyons Base Stylesheet */}}
{{- with resources.Get "ananke/css/_tachyons.css" -}}
  {{- $assets_to_concat = $assets_to_concat | collections.Append . -}}
{{- end -}}
 
{{/* Theme CSS files */}}
{{- range collections.Slice "_code.css" "_hugo-internal-templates.css" "_social-icons.css" "_styles.css" -}}
  {{- with partials.IncludeCached "AnankeGetResource.html" . . -}}
    {{- $assets_to_concat = $assets_to_concat | collections.Append . -}}
  {{- end -}}
{{- end -}}
 
{{/* Generated social network hover colours */}}
{{- with site.Params.ananke.social -}}
  {{- $config := . -}}
 
  {{/* Cover both the follow and the share links, since either can render an
       icon that should pick up its configured brand colour on hover. */}}
  {{- $follow_networks := collections.Slice -}}
  {{- with $config.follow -}}
    {{- $follow_networks = .networks | default collections.Slice -}}
  {{- end -}}
  {{- $share_networks := collections.Slice -}}
  {{- with $config.share -}}
    {{- $share_networks = .networks | default collections.Slice -}}
  {{- end -}}
  {{- $networks := collections.Union $follow_networks $share_networks -}}
 
  {{- with $networks -}}
    {{- $socials_rules := collections.Slice -}}
 
    {{- range $slug := . -}}
      {{- with collections.Index $config.networks $slug -}}
        {{- with .color -}}
          {{- $color := . -}}
          {{/* Set both `color` and `fill` so monochrome SVG icons (which inherit
               `fill: currentColor`) and any other markup react to the hover. */}}
          {{- $rule := fmt.Printf ".ananke-socials a.%s:hover {\n  color: %s !important;\n  fill: %s !important;\n}" $slug $color $color -}}
          {{- $socials_rules = $socials_rules | collections.Append $rule -}}
        {{- end -}}
      {{- end -}}
    {{- end -}}
 
    {{- with $socials_rules -}}
      {{- $socials_css := collections.Delimit . "\n\n" | resources.FromString "ananke/css/generated_socials.css" -}}
      {{- $assets_to_concat = $assets_to_concat | collections.Append $socials_css -}}
    {{- end -}}
  {{- end -}}
{{- end -}}
 
{{/* Custom CSS files and CSS-generating partials */}}
{{- with $custom_css -}}
  {{- range . -}}
    {{- $custom_css_entry := . -}}
    {{- $custom_css_entry_ext := path.Ext $custom_css_entry -}}
 
    {{- if compare.Eq $custom_css_entry_ext ".html" -}}
      {{- $partial_template_path := fmt.Print "_partials/" $custom_css_entry -}}
 
      {{- if templates.Exists $partial_template_path -}}
        {{- $partial_css := partials.Include $custom_css_entry site -}}
 
        {{- with $partial_css -}}
          {{- $partial_css_resource_path := printf "ananke/css/generated/%s.css" (replace $custom_css_entry "/" "-") -}}
          {{- $partial_css_resource := printf "%s" . | resources.FromString $partial_css_resource_path -}}
          {{- $assets_to_concat = $assets_to_concat | collections.Append $partial_css_resource -}}
        {{- else -}}
          {{- fmt.Warnf "[ananke] %s" (fmt.Printf "Stylesheet partial %q returned an empty value and was skipped." $custom_css_entry) -}}
        {{- end -}}
      {{- else -}}
        {{- fmt.Warnf "[ananke] %s" (fmt.Printf "Stylesheet partial %q was skipped because layouts/partials/%s does not exist." $custom_css_entry $custom_css_entry) -}}
      {{- end -}}
    {{- else -}}
      {{- with partials.IncludeCached "AnankeGetResource.html" $custom_css_entry $custom_css_entry -}}
        {{- $subtype := .MediaType.SubType -}}
        {{- if in (collections.Slice "x-scss" "x-sass" "scss" "sass") $subtype -}}
         {{- fmt.Warnf "[ananke] %s" (fmt.Printf "Stylesheet %q has type %q and was skipped. Sass/SCSS is no longer compiled by this template. Precompile it to CSS or replace it with a .css file." .Name $subtype) -}}
        {{- else -}}
          {{- $assets_to_concat = $assets_to_concat | collections.Append . -}}
        {{- end -}}
      {{- end -}}
    {{- end -}}
  {{- end -}}
{{- end -}}
 
{{/* Build, optionally minify, and fingerprint the concatenated CSS bundle. */}}
{{- with $assets_to_concat -}}
  {{- $style := . | resources.Concat "ananke/css/theme.css" -}}
  {{- $build_options := dict
    "minify" (cond hugo.IsDevelopment false true)
    "sourceMap" (cond hugo.IsDevelopment "linked" "none")
    "targetPath" "ananke/css/main.css"
  -}}
  {{- $style = $style | css.Build $build_options -}}
 
  {{- if hugo.IsProduction -}}
    {{- $style = $style | resources.Fingerprint -}}
  {{- end -}}
 
  {{- $main_style = $style -}}
{{- end -}}
 
{{- with $main_style -}}
  <link rel="stylesheet" href="{{ .RelPermalink }}"{{ with .Data.Integrity }} integrity="{{ . }}" crossorigin="anonymous"{{ end }}>
{{- end -}}
 
{{/*
  Fallback custom CSS links.
 
  If an ananke.custom_css entry is not found in assets/ananke/css/, it is
  assumed to be a static file or external URL and emitted as a separate
  stylesheet link.
 
  HTML entries are treated as CSS-generating partials and are never emitted as
  fallback stylesheet links.
*/}}
{{- range $custom_css -}}
  {{- $custom_css_entry := . -}}
  {{- $custom_css_entry_ext := path.Ext $custom_css_entry -}}
 
  {{- if compare.Eq $custom_css_entry_ext ".html" -}}
    {{/* CSS-generating partials are handled above. */}}
  {{- else -}}
    {{- with partials.IncludeCached "AnankeGetResource.html" $custom_css_entry $custom_css_entry -}}
      {{/* Already handled in the asset bundle above, or skipped if unsupported. */}}
    {{- else -}}
      <link rel="stylesheet" href="{{ urls.RelURL . }}">
    {{- end -}}
  {{- end -}}
{{- end -}}
 
{{ define "_partials/AnankeGetResource.html" }}
  {{- $resource := false -}}
  {{- with resources.Get (fmt.Print "ananke/css/" .) -}}
    {{- $resource = . -}}
  {{- end -}}
  {{- return $resource -}}
{{ end }}