diff --git a/src/main/java/run/halo/comment/widget/CommentWidgetHeadProcessor.java b/src/main/java/run/halo/comment/widget/CommentWidgetHeadProcessor.java new file mode 100644 index 0000000..4407ea9 --- /dev/null +++ b/src/main/java/run/halo/comment/widget/CommentWidgetHeadProcessor.java @@ -0,0 +1,44 @@ +package run.halo.comment.widget; + +import lombok.RequiredArgsConstructor; +import org.pf4j.PluginWrapper; +import org.springframework.stereotype.Component; +import org.springframework.util.PropertyPlaceholderHelper; +import org.thymeleaf.context.ITemplateContext; +import org.thymeleaf.model.IModel; +import org.thymeleaf.model.IModelFactory; +import org.thymeleaf.processor.element.IElementModelStructureHandler; +import reactor.core.publisher.Mono; +import run.halo.app.theme.dialect.TemplateHeadProcessor; + +import java.util.Properties; + +@Component +@RequiredArgsConstructor +public class CommentWidgetHeadProcessor implements TemplateHeadProcessor { + + static final PropertyPlaceholderHelper PROPERTY_PLACEHOLDER_HELPER = new PropertyPlaceholderHelper("${", "}"); + + private final PluginWrapper pluginWrapper; + + @Override + public Mono process(ITemplateContext context, IModel model, + IElementModelStructureHandler structureHandler) { + final IModelFactory modelFactory = context.getModelFactory(); + model.add(modelFactory.createText(commentWidgetScript())); + return Mono.empty(); + } + + private String commentWidgetScript() { + + final Properties properties = new Properties(); + properties.setProperty("version", pluginWrapper.getDescriptor().getVersion()); + + return PROPERTY_PLACEHOLDER_HELPER.replacePlaceholders(""" + + + + + """, properties); + } +} diff --git a/src/main/java/run/halo/comment/widget/DefaultCommentWidget.java b/src/main/java/run/halo/comment/widget/DefaultCommentWidget.java index 133736b..5eb0f5e 100644 --- a/src/main/java/run/halo/comment/widget/DefaultCommentWidget.java +++ b/src/main/java/run/halo/comment/widget/DefaultCommentWidget.java @@ -65,8 +65,6 @@ private String commentHtml(IAttribute groupAttribute, IAttribute kindAttribute, return PROPERTY_PLACEHOLDER_HELPER.replacePlaceholders("""
- -