diff --git a/README.md b/README.md index a87619cf..ca9d4857 100644 --- a/README.md +++ b/README.md @@ -717,6 +717,27 @@ Parameters: Body: Required. String. Markdown. The quotation. +### Request + +The `paige/request` shortcode provides the content for a URL. + +``` +{{< paige/request + method="" + url="" >}} +``` + +Parameters: + +
method
get
.url
+{{* paige/request "https://raw.githubusercontent.com/willfaught/paige/master/LICENSE" */>}} ++``` + +Result: + +
+{{< paige/request "https://raw.githubusercontent.com/willfaught/paige/master/LICENSE" >}} ++ +## Method parameter + +Code: + +```go-html-template +
+{{* paige/request method="get" url="https://raw.githubusercontent.com/willfaught/paige/master/LICENSE" */>}} ++``` + +Result: + +
+{{< paige/request method="get" url="https://raw.githubusercontent.com/willfaught/paige/master/LICENSE" >}} ++ +## Url parameter + +Code: + +```go-html-template +
+{{* paige/request url="https://raw.githubusercontent.com/willfaught/paige/master/LICENSE" */>}} ++``` + +Result: + +
+{{< paige/request url="https://raw.githubusercontent.com/willfaught/paige/master/LICENSE" >}} ++ +## Figure + +Code: + +```go-html-template +{{* paige/figure caption="License" */>}} +
+{{* paige/request "https://raw.githubusercontent.com/willfaught/paige/master/LICENSE" */>}} ++{{* /paige/figure */>}} +``` + +Result: + +{{< paige/figure caption="License" >}} +
+{{< paige/request "https://raw.githubusercontent.com/willfaught/paige/master/LICENSE" >}} ++{{< /paige/figure >}} diff --git a/layouts/shortcodes/paige/request.html b/layouts/shortcodes/paige/request.html new file mode 100644 index 00000000..7758d651 --- /dev/null +++ b/layouts/shortcodes/paige/request.html @@ -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 -}}