Bootstrap 配置切換短代碼

從單個配置代碼生成多個語言代碼塊,支持 TOML、JSON 和 YAML。

語法

1{{< bs/config-toggle >}}
2PUT YAML/TOML/JSON CODE HERE.
3{{< /bs/config-toggle >}}

參數

filename

索引名稱類型必填默認值版本示例
#0filenamestring----

文件名。

langs

索引名稱類型必填默認值版本示例
#1langsstring-toml,yaml,json--

逗號分隔的目標語言,可用於排除語言或重新排序。

style

索引名稱類型必填默認值版本示例
-stylestring-tabs--

樣式:tabspillsunderline.

fill

索引名稱類型必填默認值版本示例
-fillboolean-false--

true 時,佔用全寬。

title

索引名稱類型必填默認值版本示例
-titlestring----

配置標題。

delimiter

索引名稱類型必填默認值版本示例
-delimiterboolean----

true 時,用分隔符包裹代碼。

站點參數

langs

名稱上下文類型必填默認值版本示例
langs-array-[&#34;toml&#34;, &#34;yaml&#34;, &#34;json&#34;]--

目標語言,可用於排除語言和重新排序。

hugo.yaml

1params:
2  bootstrap:
3    config_toggle:
4      langs:
5      - yaml
6      - toml
7      - json

hugo.toml

1[params]
2  [params.bootstrap]
3    [params.bootstrap.config_toggle]
4      langs = ['yaml', 'toml', 'json']

hugo.json

 1{
 2   "params": {
 3      "bootstrap": {
 4         "config_toggle": {
 5            "langs": [
 6               "yaml",
 7               "toml",
 8               "json"
 9            ]
10         }
11      }
12   }
13}

示例

文件示例

源碼
1{{< bs/config-toggle hello >}}
2{
3  "hello": "world"
4}
5{{< /bs/config-toggle >}}
結果

hello.yaml

1hello: world

hello.toml

1hello = 'world'

hello.json

1{
2   "hello": "world"
3}

排除語言並重新排序

源碼
1{{< bs/config-toggle langs=json,toml >}}
2langs = ["toml", "json"]
3{{< /bs/config-toggle >}}
結果
1{
2   "langs": [
3      "toml",
4      "json"
5   ]
6}
1langs = ['toml', 'json']

Hugo 配置示例

源碼
1{{< bs/config-toggle filename=hugo title="Configuration" style=pills fill=true >}}
2module:
3  imports:
4    - path: github.com/hugomods/bootstrap
5{{< /bs/config-toggle >}}
結果

hugo.yaml

1module:
2  imports:
3  - path: github.com/hugomods/bootstrap

hugo.toml

1[module]
2  [[module.imports]]
3    path = 'github.com/hugomods/bootstrap'

hugo.json

1{
2   "module": {
3      "imports": [
4         {
5            "path": "github.com/hugomods/bootstrap"
6         }
7      ]
8   }
9}

Hugo 前言示例

源碼
1{{< bootstrap/config-toggle title="Front Matter" delimiter=true >}}
2title: Hello World!
3{{< /bootstrap/config-toggle >}}
結果
1---
2title: Hello World!
3---
1+++
2title = 'Hello World!'
3+++
1{
2   "title": "Hello World!"
3}