mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-13 12:45:52 -04:00
Update youtube shortcode args
This commit is contained in:
parent
961639dfa4
commit
66237fe12d
@ -380,7 +380,7 @@ Rendered:
|
|||||||
{{< vimeo 55073825 >}}
|
{{< vimeo 55073825 >}}
|
||||||
|
|
||||||
{{% note %}}
|
{{% note %}}
|
||||||
If you want to further customize the visual styling of the YouTube or Vimeo output, add a `class` parameter when calling the shortcode. The new `class` will be added to the `<div>` that wraps the `<iframe>` *and* will remove the inline styles. Note that you will need to call the `id` as a named parameter as well. You can also give the vimeo video a descriptive title with `title`.
|
If you want to further customize the visual styling, add a `class` parameter when calling the shortcode. The new `class` will be added to the `<div>` that wraps the `<iframe>` *and* will remove the inline styles. Note that you will need to call the `id` as a named parameter as well. You can also give the vimeo video a descriptive title with `title`.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
{{</* vimeo id="146022717" class="my-vimeo-wrapper-class" title="My vimeo video" */>}}
|
{{</* vimeo id="146022717" class="my-vimeo-wrapper-class" title="My vimeo video" */>}}
|
||||||
@ -390,50 +390,67 @@ If you want to further customize the visual styling of the YouTube or Vimeo outp
|
|||||||
### youtube
|
### youtube
|
||||||
|
|
||||||
{{% note %}}
|
{{% note %}}
|
||||||
To override Hugo's embedded `vimeo` shortcode, copy the [source code] to a file with the same name in the layouts/shortcodes directory.
|
To override Hugo's embedded `youtube` shortcode, copy the [source code] to a file with the same name in the layouts/shortcodes directory.
|
||||||
|
|
||||||
[source code]: {{% eturl youtube %}}
|
[source code]: {{% eturl youtube %}}
|
||||||
{{% /note %}}
|
{{% /note %}}
|
||||||
|
|
||||||
The `youtube` shortcode embeds a responsive video player for [YouTube videos]. Only the ID of the video is required, e.g.:
|
To display a YouTube video with this URL:
|
||||||
|
|
||||||
```txt
|
```text
|
||||||
https://www.youtube.com/watch?v=w7Ft2ymGmfc
|
https://www.youtube.com/watch?v=0RKpf3rK57I
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Example `youtube` input
|
Include this in your Markdown:
|
||||||
|
|
||||||
Copy the YouTube video ID that follows `v=` in the video's URL and pass it to the `youtube` shortcode:
|
```text
|
||||||
|
{{</* youtube 0RKpf3rK57I */>}}
|
||||||
|
```
|
||||||
|
|
||||||
{{< code file=example-youtube-input.md >}}
|
Rendered:
|
||||||
{{</* youtube w7Ft2ymGmfc */>}}
|
|
||||||
{{< /code >}}
|
|
||||||
|
|
||||||
Furthermore, you can automatically start playback of the embedded video by setting the `autoplay` parameter to `true`. Remember that you can't mix named and unnamed parameters, so you'll need to assign the yet unnamed video ID to the parameter `id`:
|
{{< youtube 0RKpf3rK57I >}}
|
||||||
|
|
||||||
{{< code file=example-youtube-input-with-autoplay.md >}}
|
The youtube shortcode accepts these named parameters:
|
||||||
{{</* youtube id="w7Ft2ymGmfc" autoplay="true" */>}}
|
|
||||||
{{< /code >}}
|
|
||||||
|
|
||||||
For [accessibility reasons](https://dequeuniversity.com/tips/provide-iframe-titles), it's best to provide a title for your YouTube video. You can do this using the shortcode by providing a `title` parameter. If no title is provided, a default of "YouTube Video" will be used.
|
id
|
||||||
|
: (`string`) The video `id`. Optional if the `id` is provided as a positional argument as shown in the example above.
|
||||||
|
|
||||||
{{< code file=example-youtube-input-with-title.md >}}
|
allowFullScreen {{< new-in 0.125.0 >}}
|
||||||
{{</* youtube id="w7Ft2ymGmfc" title="A New Hugo Site in Under Two Minutes" */>}}
|
: (`bool`) Whether the `iframe` element can activate full screen mode. Default is `true`.
|
||||||
{{< /code >}}
|
|
||||||
|
|
||||||
#### Example `youtube` output
|
autoplay {{< new-in 0.125.0 >}}
|
||||||
|
: (`bool`) Whether to automatically play the video. Forces `mute` to `true`. Default is `false`.
|
||||||
|
|
||||||
Using the preceding `youtube` example, the following HTML will be added to your rendered website's markup:
|
class
|
||||||
|
: (`string`) The `class` attribute of the wrapping `div` element. When specified, removes the `style` attributes from the `iframe` element and its wrapping `div` element.
|
||||||
|
|
||||||
{{< code file=example-youtube-output.html >}}
|
controls {{< new-in 0.125.0 >}}
|
||||||
{{< youtube id="w7Ft2ymGmfc" autoplay="true" >}}
|
: (`bool`) Whether to display the video controls. Default is `true`.
|
||||||
{{< /code >}}
|
|
||||||
|
|
||||||
#### Example `youtube` display
|
end {{< new-in 0.125.0 >}}
|
||||||
|
: (`int`) The time, measured in seconds from the start of the video, when the player should stop playing the video.
|
||||||
|
|
||||||
Using the preceding `youtube` example (without `autoplay="true"`), the following simulates the displayed experience for visitors to your website. Naturally, the final display will be contingent on your style sheets and surrounding markup. The video is also include in the [Quick Start of the Hugo documentation][quickstart].
|
loading {{< new-in 0.125.0 >}}
|
||||||
|
: (`string`) The loading attribute of the `iframe` element, either `eager` or `lazy`. Default is `eager`.
|
||||||
|
|
||||||
{{< youtube w7Ft2ymGmfc >}}
|
loop {{< new-in 0.125.0 >}}
|
||||||
|
: (`bool`) Whether to indefinitely repeat the video. Ignores the `start` and `end` arguments after the first play. Default is `false`.
|
||||||
|
|
||||||
|
mute {{< new-in 0.125.0 >}}
|
||||||
|
: (`bool`) Whether to mute the video. Always `true` when `autoplay` is `true`. Default is `false`.
|
||||||
|
|
||||||
|
start {{< new-in 0.125.0 >}}
|
||||||
|
: (`int`) The time, measured in seconds from the start of the video, when the player should start playing the video.
|
||||||
|
|
||||||
|
title
|
||||||
|
: (`string`) The `title` attribute of the `iframe` element. Defaults to the title returned by the YouTube oEmbed API.
|
||||||
|
|
||||||
|
Example using some of the above:
|
||||||
|
|
||||||
|
```text
|
||||||
|
{{</* youtube id=0RKpf3rK57I start=30 end=60 loading=lazy */>}}
|
||||||
|
```
|
||||||
|
|
||||||
## Privacy configuration
|
## Privacy configuration
|
||||||
|
|
||||||
|
34
layouts/shortcodes/new-in.html
Normal file
34
layouts/shortcodes/new-in.html
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
{{- /*
|
||||||
|
Renders a "new in" button indicating the version in which a feature was added.
|
||||||
|
|
||||||
|
When comparing the current version to the specified version, the "new in"
|
||||||
|
button will be hidden if any of the following conditions is true:
|
||||||
|
|
||||||
|
- The major version difference exceeds the majorVersionDiffThreshold
|
||||||
|
- The minor version difference exceeds the minorVersionDiffThreshold
|
||||||
|
|
||||||
|
@param {string} version The semantic version string, with or without a leading v.
|
||||||
|
@returns {template.HTML}
|
||||||
|
|
||||||
|
@example {{< new-in 0.100.0 >}}
|
||||||
|
*/}}
|
||||||
|
|
||||||
|
{{- /* Set defaults. */}}
|
||||||
|
{{- $majorVersionDiffThreshold := 0 }}
|
||||||
|
{{- $minorVersionDiffThreshold := 30 }}
|
||||||
|
{{- $displayExpirationWarning := true }}
|
||||||
|
|
||||||
|
{{- /* Render. */}}
|
||||||
|
{{- with $version := .Get 0 | strings.TrimPrefix "v" }}
|
||||||
|
{{- $majorVersionDiff := sub (index (split hugo.Version ".") 0 | int) (index (split $version ".") 0 | int) }}
|
||||||
|
{{- $minorVersionDiff := sub (index (split hugo.Version ".") 1 | int) (index (split $version ".") 1 | int) }}
|
||||||
|
{{- if or (gt $majorVersionDiff $majorVersionDiffThreshold) (gt $minorVersionDiff $minorVersionDiffThreshold) }}
|
||||||
|
{{- if $displayExpirationWarning }}
|
||||||
|
{{- warnf "This call to the %q shortcode should be removed: %s. The button is now hidden because the specified version (%s) is older than the display threshold." $.Name $.Position $version }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
<a class="f5 fw6 ba bw1 b--gray ph2 mr2 mt2" href="{{ printf "https://github.com/gohugoio/hugo/releases/tag/v%s" $version }}">New in v{{ $version }}</a>
|
||||||
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
{{- errorf "The %q shortcode requires a positional parameter (version). See %s" .Name .Position }}
|
||||||
|
{{- end -}}
|
Loading…
x
Reference in New Issue
Block a user