Skip to content

Commit

Permalink
feat: add verison parameter for component resources (#22)
Browse files Browse the repository at this point in the history
为搜索组件资源添加版本号,防止升级之后无法及时更新缓存。

/kind improvement

```release-note
为搜索组件资源添加版本号,防止升级之后无法及时更新缓存。
```
  • Loading branch information
ruibaby committed Oct 30, 2023
1 parent 53af4d9 commit 7390bfa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions build.gradle
@@ -1,5 +1,6 @@
plugins {
id 'java'
id "io.freefair.lombok" version "8.0.1"
id "com.github.node-gradle.node" version "3.3.0"
id "run.halo.plugin.devtools" version "0.0.4"
}
Expand Down
@@ -1,18 +1,25 @@
package run.halo.search.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 SearchWidgetHeadProcessor implements TemplateHeadProcessor {

public SearchWidgetHeadProcessor() {
}
static final PropertyPlaceholderHelper PROPERTY_PLACEHOLDER_HELPER = new PropertyPlaceholderHelper("${", "}");

private final PluginWrapper pluginWrapper;

@Override
public Mono<Void> process(ITemplateContext context, IModel model,
Expand All @@ -23,11 +30,15 @@ public Mono<Void> process(ITemplateContext context, IModel model,
}

private String searchWidgetScript() {
return """

final Properties properties = new Properties();
properties.setProperty("version", pluginWrapper.getDescriptor().getVersion());

return PROPERTY_PLACEHOLDER_HELPER.replacePlaceholders("""
<!-- PluginSearchWidget start -->
<script src="/plugins/PluginSearchWidget/assets/static/search-widget.iife.js" async></script>
<link rel="stylesheet" href="/plugins/PluginSearchWidget/assets/static/style.css" />
<script src="/plugins/PluginSearchWidget/assets/static/search-widget.iife.js?version=${version}" async></script>
<link rel="stylesheet" href="/plugins/PluginSearchWidget/assets/static/style.css?version=${version}" />
<!-- PluginSearchWidget end -->
""";
""", properties);
}
}

0 comments on commit 7390bfa

Please sign in to comment.