diff --git a/exampleSite/content/posts/tests/bilibili-tests/index.en.md b/exampleSite/content/posts/tests/bilibili-tests/index.en.md index 22b87a295..8651372e8 100644 --- a/exampleSite/content/posts/tests/bilibili-tests/index.en.md +++ b/exampleSite/content/posts/tests/bilibili-tests/index.en.md @@ -12,6 +12,18 @@ hiddenFromSearch: true +Simple case `{{}}` + {{< bilibili BV1Sx411T7QQ >}} +Play the 3rd page `{{}}` + {{< bilibili id=BV1TJ411C7An p=3 >}} + +Enable autoplay with annoying unmute `{{}}` + +{{< bilibili id=BV1TJ411C7An p=3 autoplay=true muted=false >}} + +A player with everything diabled `{{}}` (Looks like only `autoplay`, `muted`, `danmaku` and `t` are working) + +{{< bilibili id=BV1TJ411C7An p=3 autoplay=0 muted=1 danmaku=0 t=100 hasMuteButton=0 hideCoverInfo=1 hideDanmakuButton=1 noFullScreenButton=1 fjw=1 >}} \ No newline at end of file diff --git a/exampleSite/content/posts/theme-documentation-extended-shortcodes/index.en.md b/exampleSite/content/posts/theme-documentation-extended-shortcodes/index.en.md index 64dce1c45..3917113c6 100644 --- a/exampleSite/content/posts/theme-documentation-extended-shortcodes/index.en.md +++ b/exampleSite/content/posts/theme-documentation-extended-shortcodes/index.en.md @@ -1251,6 +1251,43 @@ The rendered output looks like this: {{< bilibili id=BV1TJ411C7An p=3 >}} +### Advanced Usage + +The `bilibili` shortcode supports all named parameters shown in [this blog post](https://zyc420.com/6143.html) + +Here is a list of all named parameters: + +| Parameter Name | Position | Purpose | How to Use | +|---|---|---|---| +| id | 0 | Video BVID, required | BV1TJ411C7An | +| p | 1 | Video part (default 1) | Enter a number | +| autoplay | 2 | Auto-play (default no) | `1` or `true`: Enable, `0` or `false`: Disable | +| danmaku | 3 | Default danmaku switch (default on) | `1` or `true`: Enable, `0` or `false`: Disable | +| muted | 4 | Default muted (default no) | `1` or `true`: Enable, `0` or `false`: Disable | +| t | 5 | Default start time (default 0) | Enter the value directly, in seconds | + +The following options seems not to work, but these are still added to the shortcode in case if they work in the future: + +| Parameter Name | Position | Purpose | How to Use | +|---|---|---|---| +| hasMuteButton | 6 | Whether the mute button is displayed (default not displayed) | `1` or `true`: Enable, `0` or `false`: Disable | +| hideCoverInfo | 7 | Whether the information under the video cover like play count and danmaku count is displayed (default displayed) | `1` or `true`: Enable, `0` or `false`: Disable | +| hideDanmakuButton | 8 | Whether to hide the danmaku button (default not hidden) | `1` or `true`: Enable, `0` or `false`: Disable | +| noFullScreenButton | 9 | Whether to hide the full screen button (default displayed) | `1` or `true`: Enable, `0` or `false`: Disable | +| fjw | 10 | Whether to start memory play (default on) | `1` or `true`: Enable, `0` or `false`: Disable | + +Example `bilibili` input with all named parameters: + +```markdown +{{}} +or +{{}} +``` + +The rendered output looks like this: + +{{< bilibili id=BV1TJ411C7An p=3 autoplay=0 danmaku=0 muted=1 t=30 hasMuteButton=0 hideCoverInfo=1 hideDanmakuButton=1 noFullScreenButton=1 fjw=1 >}} + ## typeit The `typeit` shortcode provides typing animation based on [TypeIt](https://typeitjs.com/). diff --git a/exampleSite/content/posts/theme-documentation-extended-shortcodes/index.zh-cn.md b/exampleSite/content/posts/theme-documentation-extended-shortcodes/index.zh-cn.md index bbf70c872..ca2696e37 100644 --- a/exampleSite/content/posts/theme-documentation-extended-shortcodes/index.zh-cn.md +++ b/exampleSite/content/posts/theme-documentation-extended-shortcodes/index.zh-cn.md @@ -1253,6 +1253,43 @@ https://www.bilibili.com/video/BV1TJ411C7An?p=3 {{< bilibili id=BV1TJ411C7An p=3 >}} +### 高级用法 + +`bilibili` shortcode 支持[此博客文章](https://zyc420.com/6143.html)中展示的所有命名参数。 + +以下是所有命名参数的列表: + +| 参数名 | 参数位置 | 参数用途 | 使用方法 | +|---|---|---|---| +| id | 0 | 视频BVID,必须项 | BV1TJ411C7An | +| p | 1 | 视频分P(默认为1) | 输入数字 | +| autoplay | 2 | 是否自动播放(默认为否) | `1`或`true`:启用,`0`或`false`:关闭 | +| danmaku | 3 | 默认弹幕开关(默认为开启) | `1`或`true`:启用,`0`或`false`:关闭 | +| muted | 4 | 是否默认静音(默认为否) | `1`或`true`:启用,`0`或`false`:关闭 | +| t | 5 | 默认开始时间(默认为0) | 直接输入数值,单位为秒 | + +以下选项目前似乎不起作用,但仍然被加进shortcode中,以希望未来这些选项能够被正常使用: + +| 参数名 | 参数位置 | 参数用途 | 使用方法 | +|---|---|---|---| +| hasMuteButton | 6 | 一键静音按钮是否显示(默认不显示) | `1`或`true`:启用,`0`或`false`:关闭 | +| hideCoverInfo | 7 | 视频封面下方是否显示播放量弹幕量等信息(默认显示) | `1`或`true`:启用,`0`或`false`:关闭 | +| hideDanmakuButton | 8 | 是否隐藏弹幕按钮(默认不隐藏) | `1`或`true`:启用,`0`或`false`:关闭 | +| noFullScreenButton | 9 | 是否隐藏全屏按钮(默认显示) | `1`或`true`:启用,`0`或`false`:关闭 | +| fjw | 10 | 是否启用记忆播放(默认开启) | `1`或`true`:启用,`0`或`false`:关闭 | + +一个带有所有命名参数的`bilibili`示例: + +```markdown +{{}} +或者 +{{}} +``` + +呈现的输出效果如下: + +{{< bilibili id=BV1TJ411C7An p=3 autoplay=0 danmaku=0 muted=1 t=30 hasMuteButton=0 hideCoverInfo=1 hideDanmakuButton=1 noFullScreenButton=1 fjw=1 >}} + ## typeit `typeit` shortcode 基于 [TypeIt](https://typeitjs.com/) 提供了打字动画. diff --git a/layouts/partials/function/convertBoolToNum.html b/layouts/partials/function/convertBoolToNum.html new file mode 100644 index 000000000..83c427579 --- /dev/null +++ b/layouts/partials/function/convertBoolToNum.html @@ -0,0 +1,11 @@ +{{- $value := .value -}} +{{- if or (eq .value 1) (eq .value 0) -}} + {{/* Do nothing */}} +{{- else if eq (lower .value) "true" -}} + {{- $value = 1 -}} +{{- else if eq (lower .value) "false" -}} + {{- $value = 0 -}} +{{- else -}} + {{- errorf "Invalid value: %s. Expected true, false, 1, or 0." .value -}} +{{- end -}} +{{- return $value -}} \ No newline at end of file diff --git a/layouts/shortcodes/bilibili.html b/layouts/shortcodes/bilibili.html index f1827e117..18e8d92de 100644 --- a/layouts/shortcodes/bilibili.html +++ b/layouts/shortcodes/bilibili.html @@ -1,7 +1,79 @@ +{{- $bvid := cond .IsNamedParams (.Get "id") (.Get 0) -}} +{{- $page := cond .IsNamedParams (.Get "p") (.Get 1) | default 1 -}} + +{{- $autoplayRaw := cond .IsNamedParams (.Get "autoplay") (.Get 2) -}} +{{- $autoplayPara := "" -}} +{{- if not (eq $autoplayRaw "") -}} + {{- $autoplay := partial "function/convertBoolToNum.html" (dict "value" $autoplayRaw) -}} + {{- $autoplayPara = printf "&autoplay=%d" $autoplay -}} + {{/* {{- warnf "The 'autoplay' parameter is set." -}} */}} +{{- else -}} + {{- $autoplayPara = "&autoplay=0" -}} + {{/* {{- warnf "The 'autoplay' parameter is not set. Default to 0." -}} */}} +{{- end -}} + +{{/* Optional parameters */}} +{{- $danmakuRaw := cond .IsNamedParams (.Get "danmaku") (.Get 3) -}} +{{- $danmakuPara := "" -}} +{{- if not (eq $danmakuRaw "") -}} + {{- $danmaku := partial "function/convertBoolToNum.html" (dict "value" $danmakuRaw) -}} + {{- $danmakuPara = printf "&danmaku=%d" $danmaku -}} +{{- end -}} + +{{- $mutedRaw := cond .IsNamedParams (.Get "muted") (.Get 4) -}} +{{- $mutedPara := "" -}} +{{- if not (eq $mutedRaw "") -}} + {{/* {{- warnf "The 'muted' parameter is set." -}} */}} + {{- $muted := partial "function/convertBoolToNum.html" (dict "value" $mutedRaw) -}} + {{- $mutedPara = printf "&muted=%d" $muted -}} +{{- end -}} + +{{- $t := cond .IsNamedParams (.Get "t") (.Get 5) -}} +{{- $tPara := "" -}} +{{- if not (eq $t "") -}} + {{- $tPara = printf "&t=%d" $t -}} +{{- end -}} + +{{/* These options seem not working anymore, but we added in case if these options works again */}} +{{- $hasMuteButtonRaw := cond .IsNamedParams (.Get "hasMuteButton") (.Get 6) -}} +{{- $hasMuteButtonPara := "" -}} +{{- if not (eq $hasMuteButtonRaw "") -}} + {{- $hasMuteButton := partial "function/convertBoolToNum.html" (dict "value" $hasMuteButtonRaw) -}} + {{- $hasMuteButtonPara = printf "&hasMuteButton=%d" $hasMuteButton -}} +{{- end -}} + +{{- $hideCoverInfoRaw := cond .IsNamedParams (.Get "hideCoverInfo") (.Get 7) -}} +{{- $hideCoverInfoPara := "" -}} +{{- if not (eq $hideCoverInfoRaw "") -}} + {{- $hideCoverInfo := partial "function/convertBoolToNum.html" (dict "value" $hideCoverInfoRaw) -}} + {{- $hideCoverInfoPara = printf "&hideCoverInfo=%d" $hideCoverInfo -}} +{{- end -}} + +{{- $hideDanmakuButtonRaw := cond .IsNamedParams (.Get "hideDanmakuButton") (.Get 8) -}} +{{- $hideDanmakuButtonPara := "" -}} +{{- if not (eq $hideDanmakuButtonRaw "") -}} + {{- $hideDanmakuButton := partial "function/convertBoolToNum.html" (dict "value" $hideDanmakuButtonRaw) -}} + {{- $hideDanmakuButtonPara = printf "&hideDanmakuButton=%d" $hideDanmakuButton -}} +{{- end -}} + +{{- $noFullScreenButtonRaw := cond .IsNamedParams (.Get "noFullScreenButton") (.Get 9) -}} +{{- $noFullScreenButtonPara := "" -}} +{{- if not (eq $noFullScreenButtonRaw "") -}} + {{- $noFullScreenButton := partial "function/convertBoolToNum.html" (dict "value" $noFullScreenButtonRaw) -}} + {{- $noFullScreenButtonPara = printf "&noFullScreenButton=%d" $noFullScreenButton -}} +{{- end -}} + +{{- $fjwRaw := cond .IsNamedParams (.Get "fjw") (.Get 10) -}} +{{- $fjwPara := "" -}} +{{- if not (eq $fjwRaw "") -}} + {{- $fjw := partial "function/convertBoolToNum.html" (dict "value" $fjwRaw) -}} + {{- $fjwPara = printf "&fjw=%d" $fjw -}} +{{- end -}} + +{{/* TODO: make the 'player.bilibili.com/player.html' part configurable. This URL can be replaced by '//www.bilibili.com/blackboard/html5mobileplayer.html' to get a mobile version of the iframe player, which is even cleaner. See https://blog.zezeshe.com/archives/use-bilibili-iframe-player.html */}} + +{{- $url := printf "//player.bilibili.com/player.html?bvid=%s&page=%v%s%s%s%s%s%s%s%s%s" $bvid $page $autoplayPara $danmakuPara $mutedPara $tPara $hasMuteButtonPara $hideCoverInfoPara $hideDanmakuButtonPara $noFullScreenButtonPara $fjwPara -}} +
- {{- if .IsNamedParams -}} - - {{- else -}} - - {{- end -}} -
+ + \ No newline at end of file