Add request shortcode
This commit is contained in:
21
README.md
21
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:
|
||||
|
||||
<dl>
|
||||
<dt><code>method</code></dt>
|
||||
<dd>Optional. String. HTTP method. Default is <code>get</code>.</dd>
|
||||
<dt><code>url</code></dt>
|
||||
<dd>Required. String. URL.</dd>
|
||||
</dl>
|
||||
|
||||
Body: None.
|
||||
|
||||
### Tabs
|
||||
|
||||
The `paige/tabs` shortcode provides tab buttons and tab panes.
|
||||
|
79
exampleSite/content/shortcodes/request.md
Normal file
79
exampleSite/content/shortcodes/request.md
Normal file
@@ -0,0 +1,79 @@
|
||||
+++
|
||||
authors = ["author-demo"]
|
||||
categories = ["paige", "shortcodes"]
|
||||
description = "Demonstration of the request shortcode."
|
||||
tags = ["request", "figures"]
|
||||
title = "Request"
|
||||
+++
|
||||
|
||||
The `paige/request` shortcode displays the content for a URL.
|
||||
|
||||
<!--more-->
|
||||
|
||||
## Basic
|
||||
|
||||
Code:
|
||||
|
||||
```go-html-template
|
||||
<pre>
|
||||
{{</* paige/request "https://raw.githubusercontent.com/willfaught/paige/master/LICENSE" */>}}
|
||||
</pre>
|
||||
```
|
||||
|
||||
Result:
|
||||
|
||||
<pre>
|
||||
{{< paige/request "https://raw.githubusercontent.com/willfaught/paige/master/LICENSE" >}}
|
||||
</pre>
|
||||
|
||||
## Method parameter
|
||||
|
||||
Code:
|
||||
|
||||
```go-html-template
|
||||
<pre>
|
||||
{{</* paige/request method="get" url="https://raw.githubusercontent.com/willfaught/paige/master/LICENSE" */>}}
|
||||
</pre>
|
||||
```
|
||||
|
||||
Result:
|
||||
|
||||
<pre>
|
||||
{{< paige/request method="get" url="https://raw.githubusercontent.com/willfaught/paige/master/LICENSE" >}}
|
||||
</pre>
|
||||
|
||||
## Url parameter
|
||||
|
||||
Code:
|
||||
|
||||
```go-html-template
|
||||
<pre>
|
||||
{{</* paige/request url="https://raw.githubusercontent.com/willfaught/paige/master/LICENSE" */>}}
|
||||
</pre>
|
||||
```
|
||||
|
||||
Result:
|
||||
|
||||
<pre>
|
||||
{{< paige/request url="https://raw.githubusercontent.com/willfaught/paige/master/LICENSE" >}}
|
||||
</pre>
|
||||
|
||||
## Figure
|
||||
|
||||
Code:
|
||||
|
||||
```go-html-template
|
||||
{{</* paige/figure caption="License" */>}}
|
||||
<pre>
|
||||
{{</* paige/request "https://raw.githubusercontent.com/willfaught/paige/master/LICENSE" */>}}
|
||||
</pre>
|
||||
{{</* /paige/figure */>}}
|
||||
```
|
||||
|
||||
Result:
|
||||
|
||||
{{< paige/figure caption="License" >}}
|
||||
<pre>
|
||||
{{< paige/request "https://raw.githubusercontent.com/willfaught/paige/master/LICENSE" >}}
|
||||
</pre>
|
||||
{{< /paige/figure >}}
|
16
layouts/shortcodes/paige/request.html
Normal file
16
layouts/shortcodes/paige/request.html
Normal 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 -}}
|
Reference in New Issue
Block a user