github.com/choria-io/go-choria@v0.28.1-0.20240416190746-b3bf9c7d5a45/docs/themes/hugo-theme-relearn/layouts/partials/get-format.hugo (about)

     1  {{/*
     2    https://discourse.gohugo.io/t/question-about-printf-v/22923/4
     3  
     4    GetCurrentOutput
     5    Retrieves the OuputFormat of the page, from a list of predefined outputs
     6  
     7    @author @regisphilibert with modification by @McShelby
     8  
     9    @context Page (.)
    10  
    11    @access public
    12  
    13    @return A String among the predefined list
    14  
    15    @example - Go Template
    16      {{ $currentOutputFormat := partial "func/GetCurrentOutput" . }}
    17  
    18    @warning This partial cannot be cached.
    19  */}}
    20  
    21  {{/*  We create a slice listing the concerned output formats */}}
    22  {{- $outputs := slice }}
    23  {{- range .OutputFormats }}
    24  	{{- $outputs = $outputs | append .Name }}
    25  {{- end }}
    26  {{- $alt := slice }}
    27  {{/* We range on the page's Alternative Output Formats which returns all output formats
    28  except the current one.  */}}
    29  {{- range .AlternativeOutputFormats }}
    30  {{/* If an output format matches one in the concerned list, we add it to our slice of outputs */}}
    31    {{- if in $outputs .Name }}
    32      {{- $alt = $alt | append .Name }}
    33    {{- end }}
    34  {{- end }}
    35  {{- $current := "default" }}
    36  {{/* If any alternate output formats part of the "concerned" ones have been found, we range on them. */}}
    37  {{- range $outputs }}
    38    {{/* If the output format is not listed as an "alternate", it means it is the current one.  */}}
    39    {{- if not (in $alt .) }}
    40      {{- $current = . }}
    41    {{- end }}
    42  {{- end }}
    43  
    44  {{- return .OutputFormats.Get $current }}