For AI agents: the complete documentation index is available at https://docs.halo.run/llms.txt, the full documentation bundle is available at https://docs.halo.run/llms-full.txt, and this page is available as Markdown at https://docs.halo.run/developer-guide/theme/finder-apis/plugin.md.

插件

除另行注明外,本页 API 自 Halo 2.0.0 起可用。

available(pluginName)

pluginFinder.available(pluginName);

描述

判断插件是否处于 STARTED 状态。插件未安装、未启用、尚未启动或启动失败时均返回 false

参数

  1. pluginName:string - 插件的唯一标识 metadata.name

返回值

boolean - 插件是否可用

示例

<!-- https://github.com/halo-dev/plugin-search-widget -->
<li th:if="${pluginFinder.available('PluginSearchWidget')}">
  <a href="javascript:SearchWidget.open()" title="搜索"> 搜索 </a>
</li>

available(pluginName, requiresVersion)

pluginFinder.available("fake-plugin", ">=2.3.0");

描述

判断插件是否处于 STARTED 状态,且插件版本符合 requiresVersion 要求。

引入版本:2.17.0

参数

  1. pluginName:string - 插件的唯一标识 metadata.name,不能为空。
  2. requiresVersion:string - 插件的版本要求,不能为空,例如:>1.2.0requiresVersion 的格式遵循 Semantic Range Expressions

返回值

boolean - 插件是否可用

示例

<!-- https://github.com/halo-dev/plugin-search-widget -->
<li th:if="${pluginFinder.available('PluginSearchWidget', '>=1.0.0')}">
  <a href="javascript:SearchWidget.open()" title="搜索"> 搜索 </a>
</li>