Files
docs/versioned_docs/version-2.20/developer-guide/plugin/extension-points/server/post-content.md
guqing 717ee402f4 refactor: update permission control docs for plugin (#443)
### What this PR does?
重构权限控制部分文档并调整相应结构

```release-note
None
```
2024-10-25 08:01:56 +00:00

1.7 KiB

title, description
title description
主题端文章内容处理 提供扩展主题端文章内容处理的方法,干预文章内容的渲染。

主题端文章内容处理扩展点用于干预文章内容的渲染,例如:在文章内容中添加广告、添加版权信息等。

public interface ReactivePostContentHandler extends ExtensionPoint {

    Mono<PostContentContext> handle(@NonNull PostContentContext postContent);

    @Data
    @Builder
    class PostContentContext {
        private Post post;
        private String content;
        private String raw;
        private String rawType;
    }
}

handle 方法用于处理文章内容,参数 postContent 为文章内容上下文,包含文章自定义模型对象、文章 html 内容、原始内容、原始内容类型等信息。

ReactivePostContentHandler 对应的 ExtensionPointDefinition 如下:

apiVersion: plugin.halo.run/v1alpha1
kind: ExtensionPointDefinition
metadata:
  name: reactive-post-content-handler
spec:
  className: run.halo.app.theme.ReactivePostContentHandler
  displayName: ReactivePostContentHandler
  type: MULTI_INSTANCE
  description: "Provides a way to extend the post content to be displayed on the theme-side."

即声明 ExtensionDefinition 自定义模型对象时对应的 extensionPointNamereactive-post-content-handler

使用案例可以参考:WebP Cloud 插件 它的作用是处理主题端文章内容中的所有图片的地址,将其替换为一个 WebP Cloud 的代理地址,从而实现文章内容中的图片都使用 WebP 格式。