Files
docs/versioned_docs/version-2.19/developer-guide/theme/finder-apis/plugin.md
Ryan Wang e431bdc99b docs: update documentation for Halo 2.18 (#407)
Signed-off-by: Ryan Wang <i@ryanc.cc>
2024-09-02 14:14:00 +08:00

64 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: 插件
description: 插件 - PluginFinder
---
## available(pluginName)
```js
pluginFinder.available(pluginName)
```
### 描述
判断一个插件是否可用,会同时判断插件是否安装和启用。
### 参数
1. `pluginName:string` - 插件的唯一标识 `metadata.name`
### 返回值
`boolean` - 插件是否可用
### 示例
```html
<!-- https://github.com/halo-sigs/plugin-search-widget -->
<li th:if="${pluginFinder.available('PluginSearchWidget')}">
<a href="javascript:SearchWidget.open()" title="搜索">
搜索
</a>
</li>
```
## available(pluginName, requiresVersion)
```js
pluginFinder.available('fake-plugin', '>=2.3.0')
```
### 描述
判断一个插件是否可用,会同时判断插件是否安装和启用且插件的版本符合 `requiresVersion` 要求,
### 参数
1. `pluginName:string` - 插件的唯一标识 `metadata.name`,不能为空。
2. `requiresVersion:string` - 插件的版本要求,不能为空,例如:`>1.2.0``requiresVersion` 的格式遵循 [Semantic Range Expressions](https://github.com/zafarkhaja/jsemver#range-expressions)。
### 返回值
`boolean` - 插件是否可用
### 示例
```html
<!-- https://github.com/halo-sigs/plugin-search-widget -->
<li th:if="${pluginFinder.available('PluginSearchWidget', '>=2.3.0')}">
<a href="javascript:SearchWidget.open()" title="搜索">
搜索
</a>
</li>
```