Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide ElementTagProcessor to handle element tag in plugin #6670

Merged

Conversation

JohnNiang
Copy link
Member

@JohnNiang JohnNiang commented Sep 17, 2024

What type of PR is this?

/kind feature
/area plugin

What this PR does / why we need it:

This PR provides an interface ElementTagProcessor to make plugin handle element tag easily. e.g.:

public class ImgTagProcessor implements ElementTagPostProcessor {

    @Override
    public Mono<Void> process(ITemplateContext context, IProcessableElementTag tag,
        IElementTagStructureHandler structureHandler) {
        var elementName = tag.getElementDefinition().getElementName();
        if (!Objects.equals("img", elementName.getElementName())) {
            return Mono.empty();
        }
        var srcAttr = tag.getAttribute("src");
        if (srcAttr == null) {
            return Mono.empty();
        }
        var newSrc = srcAttr.getValue();
        // TODO rewrite src
        structureHandler.setAttribute("src", newSrc);
        return Mono.empty();
    }
    
}

After PR merged, plugins https://github.com/webp-sh/halo-plugin-webp-cloud and https://github.com/guqing/plugin-cloudinary can be refined with new method.

Does this PR introduce a user-facing change?

支持在插件中操作渲染结果

@f2c-ci-robot f2c-ci-robot bot added kind/feature Categorizes issue or PR as related to a new feature. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Sep 17, 2024
@f2c-ci-robot f2c-ci-robot bot requested review from LIlGG and wan92hen September 17, 2024 15:59
@f2c-ci-robot f2c-ci-robot bot added the area/plugin Issues or PRs related to the Plugin Provider label Sep 17, 2024
@guqing
Copy link
Member

guqing commented Sep 18, 2024

单元测试没过需要修复一下

@JohnNiang JohnNiang force-pushed the feat/provide-element-tag-processor branch from 421e1f6 to 3fd3df7 Compare September 18, 2024 02:35
Copy link

codecov bot commented Sep 18, 2024

Codecov Report

Attention: Patch coverage is 97.05882% with 1 line in your changes missing coverage. Please review.

Project coverage is 58.08%. Comparing base (6cd8dc8) to head (33a3230).
Report is 75 commits behind head on main.

Files with missing lines Patch % Lines
...n/halo/app/theme/dialect/HaloProcessorDialect.java 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #6670      +/-   ##
============================================
- Coverage     58.18%   58.08%   -0.10%     
- Complexity     3774     3935     +161     
============================================
  Files           651      675      +24     
  Lines         22125    23113     +988     
  Branches       1538     1578      +40     
============================================
+ Hits          12873    13426     +553     
- Misses         8641     9067     +426     
- Partials        611      620       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@JohnNiang
Copy link
Member Author

/hold

This processor cannot handle element tag in th:utext.

@f2c-ci-robot f2c-ci-robot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 18, 2024
@JohnNiang JohnNiang force-pushed the feat/provide-element-tag-processor branch from 3fd3df7 to 33a3230 Compare September 18, 2024 16:31
Copy link

@JohnNiang
Copy link
Member Author

/unhold

Now, the post-processor supports to handle element tags evaluated in th:utext.

@f2c-ci-robot f2c-ci-robot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 19, 2024
Copy link
Member

@guqing guqing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@f2c-ci-robot f2c-ci-robot bot added the lgtm Indicates that a PR is ready to be merged. label Sep 19, 2024
Copy link

f2c-ci-robot bot commented Sep 19, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: guqing

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 19, 2024
@f2c-ci-robot f2c-ci-robot bot merged commit 07077f7 into halo-dev:main Sep 19, 2024
8 checks passed
@JohnNiang JohnNiang added the sig/docs Categorizes an issue or PR as relevant to SIG Docs. label Sep 19, 2024
@JohnNiang JohnNiang added this to the 2.20.0 LTS milestone Sep 19, 2024
@JohnNiang JohnNiang deleted the feat/provide-element-tag-processor branch September 19, 2024 05:45
@JohnNiang
Copy link
Member Author

Current API has been published into Maven publicationrun.halo.tools.platform:plugin:2.20.0-SNAPSHOT.

@wenjing-xin
Copy link

wenjing-xin commented Nov 12, 2024

请问一下,ElementTagPostProcessor只能获取到文章元素标签,单页面的标签有没有新的处理方或者还是以前的ReactiveSinglePageContentHandler。 IProcessableElementTag 这个thymleaf 提供的对象可以处理主题里边所有的标签吗

IElementTagStructureHandler structureHandler 2.20.0提供的ElementTagPostProcessor接口中的方法没有这个对象呀,无法设置一些标签属性呀

@guqing
Copy link
Member

guqing commented Nov 12, 2024

/ping @JohnNiang

@JohnNiang
Copy link
Member Author

Hi @wenjing-xin , please refer to webp-sh/halo-plugin-webp-cloud#15.

@wenjing-xin
Copy link

Hi @wenjing-xin , please refer to webp-sh/halo-plugin-webp-cloud#15.
好的,谢谢,还有个问题请教一下佬大,这个对象是单例还是多例的?文档上没有声明

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/plugin Issues or PRs related to the Plugin Provider kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/docs Categorizes an issue or PR as relevant to SIG Docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants