{{- /* GitHub file content. @param {string} file Path to file on GitHub. @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 {{< gh-file file="github/docs/README.md" lang="md" >}} */ -}} {{- if (.IsNamedParams) -}} {{ $file := (.Get "file") }} {{ $ref := ((.Get "ref") | default "main") }} {{ $lang := (.Get "lang") }} {{ $api := (site.Params.api) }} {{ $ts := (now.Unix) }} {{ $headers := (dict "User-Agent" ($api.user_agent) "Authorization" (printf "Bearer %s" (($api.github.token) | base64Decode)) ) }} {{ $data := (newScratch) }} {{ range ((split $file "/") | first 2) }}{{ ($data.Add "repo" (slice .)) }}{{ end }} {{ range ((split $file "/") | after 2) }}{{ ($data.Add "path" (slice .)) }}{{ end }} {{ $file = (getJSON ($api.github.url) "/repos/" (delimit ($data.Get "repo") "/") "/contents/" (delimit ($data.Get "path") "/") "?ref=" ($ref) "&ts=" ($ts) ($headers)) }} {{ $cp := ((printf "clipboard-%s-%s" ($.Name) (delimit (shuffle (seq 11 99)) "")) | md5) }}