{{- /* GitLab file content. @param {string} project Project ID on GitLab. @param {string} file Path to file on GitLab. @param {string} ref Branch, tag or commit. @param {string} lang Syntax highlighting. If not specified, the syntax is determined by the file extension. @returns {template.HTML} @examples {{< gl-file project="278964" file="README.md" ref="master" lang="md" >}} */ -}} {{- if (.IsNamedParams) -}} {{ $project := (.Get "project") }} {{ $file := (.Get "file") }} {{ $ref := ((.Get "ref") | default "main") }} {{ $lang := ((.Get "lang") | default "plaintext") }} {{ $api := (site.Params.api) }} {{ $ts := (now.Unix) }} {{ $headers := (dict "User-Agent" ($api.user_agent) "Authorization" (printf "Bearer %s" (($api.gitlab.token) | base64Decode)) ) }} {{ $file = (getJSON ($api.gitlab.url) "/projects/" ($project) "/repository/files/" ($file) "?ref=" ($ref) "&ts=" ($ts) ($headers)) }} {{ $cp := ((printf "clipboard-%s-%s" ($.Name) (delimit (shuffle (seq 11 99)) "")) | md5) }}
{{ ($file.file_name) }}
    {{ with ($file.size) }}
  • {{ (div . 1000) }} KB
  • {{ end }}
{{ (highlight ((($file.content) | base64Decode) | chomp) ($lang)) }}
{{- else -}} {{ (partial "alerts/no_params" .) }} {{- end -}}