Add request shortcode

This commit is contained in:
Will Faught
2024-07-18 17:46:20 -07:00
parent 2e8c210119
commit 4eac14a0bb
3 changed files with 116 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
{{- $method := .Get "method" | default "get" -}}
{{- $url := .Get 0 | default (.Get "url") -}}
{{- if not $url -}}
{{- errorf "layouts/shortcodes/paige/request.html: no url" -}}
{{- end -}}
{{- with resources.GetRemote $url (dict "method" $method) -}}
{{- with .Err -}}
{{- errorf "layouts/shortcodes/paige/request.html: cannot request remote resource %q: %v" $url . -}}
{{- else -}}
{{- strings.TrimRight "\f\n\r\t\v " .Content -}}
{{- end -}}
{{- else -}}
{{- errorf "layouts/shortcodes/paige/request.html: cannot request remote resource %q" $url -}}
{{- end -}}