encoding.Base64Decode
{{ "SHVnbw==" | base64Decode }} → Hugo
使用 base64Decode
函式來解碼來自 API 的回應。例如,這個呼叫 GitHub API 的結果包含了該倉庫 README 檔案的 base64 編碼表示:
https://api.github.com/repos/gohugoio/hugo/readme
要擷取並渲染內容:
{{ $u := "https://api.github.com/repos/gohugoio/hugo/readme" }}
{{ with resources.GetRemote $u }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else }}
{{ with . | transform.Unmarshal }}
{{ .content | base64Decode | markdownify }}
{{ end }}
{{ end }}
{{ else }}
{{ errorf "無法取得遠端資源 %q" $u }}
{{ end }}