A Hugo theme component with caniuse shortcode.

来源:hugo-fixit/shortcode-caniuse
网站:https://caniuse-el.lruihao.cn/

目录

Hugo shortcode for CanIUse

在 Hugo 中使用 shortcode 方式内嵌 CanIUse 到你的文章中。

caniuse example

baseline example

依赖

FixIt 主题 v1.0.0 及以上版本。

安装组件

安装主题 一样,安装方式有多种,选择其一即可,例如通过 Hugo Modules 安装:

1
2
3
4
5
6
7
[module]

[[module.imports]]
path = "github.com/hugo-fixit/FixIt"

[[module.imports]]
path = "github.com/hugo-fixit/shortcode-caniuse"

配置

为了通过 FixIt 主题开放的 自定义块shortcode-caniuse.html 注入到 custom-assets 中,你需要填写以下必要配置:

1
2
3
4
5
6
[params]

[params.custom_partials]
# ... other partials
assets = [ "inject/shortcode-caniuse.html" ]
# ... other partials

组件配置:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
[params]

# CanIUse Embed Element Configuration
# See: https://github.com/Lruihao/caniuse-embed-element
[params.caniuse_embed]
# whether to show the feature support baseline, default is false
baseline = false
# show the past N versions that match the feature, range is 0 - 5, default is 2
past = 2
# show the future N versions that match the feature, range is 0 - 3, default is 1
future = 1
# the origin of the caniuse embed data source, default is "https://caniuse.lruihao.cn"
origin = "https://caniuse.lruihao.cn"
# loading strategy for the iframe (eager or lazy), default is lazy
loading = "lazy"
# only production environment effective
# e.g. https://unpkg.com/@cell-x/caniuse-embed-element/dist/caniuse-embed-element.iife.js
cdn = ""

使用 Shortcode

caniuse shortcode 有以下命名参数:

  • feature [必需](第一个位置参数)特性名称
  • baseline [可选](第二个位置参数)是否显示功能支持基线,默认为 false
  • past [可选](第三个位置参数)显示过去 N 个版本,范围是 0 - 5,默认为 2
  • future [可选](第四个位置参数)显示未来 N 个版本,范围是 0 - 3,默认为 1
  • origin [可选](第五个位置参数)caniuse embed 数据源,例如:https://caniuse-embed-x.vercel.app
  • loading [可选](第六个位置参数)iframe 的加载策略(eagerlazy),默认为 lazy

点击 caniuse.com 网站上功能左边 # 号,URL 中的 pathname 即为 feature 参数。

这是一个用法示例:

1
2
3
{{< caniuse feature="flexbox" >}}
或者
{{< caniuse "flexbox" >}}

参考

致谢

Buy me a coffee~
hugo-fixit 支付宝支付宝
hugo-fixit 微信微信

发现新版本

当前站点有新版本可用。