Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby committed Mar 7, 2024
2 parents c33a91f + bf04243 commit e061aba
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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<Void> 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("""
<!-- plugin-comment-widget start -->
<script src="/plugins/PluginCommentWidget/assets/static/comment-widget.iife.js?version=${version}"></script>
<link rel="stylesheet" href="/plugins/PluginCommentWidget/assets/static/style.css?version=${version}" />
<!-- plugin-comment-widget end -->
""", properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ private String commentHtml(IAttribute groupAttribute, IAttribute kindAttribute,

return PROPERTY_PLACEHOLDER_HELPER.replacePlaceholders("""
<div id="${domId}"></div>
<script src="/plugins/PluginCommentWidget/assets/static/comment-widget.iife.js?version=${version}"></script>
<link rel="stylesheet" href="/plugins/PluginCommentWidget/assets/static/style.css?version=${version}" />
<script>
CommentWidget.init(
"#${domId}",
Expand Down

0 comments on commit e061aba

Please sign in to comment.