Skip to content

Commit

Permalink
feat: add plugin version param for static resources (#29)
Browse files Browse the repository at this point in the history
为插件的静态资源添加插件版本号参数,防止更新插件之后不能及时使用新的资源。

/kind feature

```release-note
为插件的静态资源添加插件版本号参数,防止更新插件之后不能及时使用新的资源。
```
  • Loading branch information
ruibaby authored Sep 13, 2024
1 parent 1f7af04 commit bb0db2a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main/java/run/halo/highlightjs/HighlightJSHeadProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.thymeleaf.spring6.SpringTemplateEngine;
import org.thymeleaf.web.IWebRequest;
import reactor.core.publisher.Mono;
import run.halo.app.plugin.PluginContext;
import run.halo.app.plugin.ReactiveSettingFetcher;
import run.halo.app.theme.dialect.TemplateHeadProcessor;

Expand All @@ -38,6 +39,8 @@ public class HighlightJSHeadProcessor implements TemplateHeadProcessor {

private final ReactiveSettingFetcher reactiveSettingFetcher;

private final PluginContext pluginContext;

private final RouteMatcher routeMatcher = createRouteMatcher();

private final TemplateEngine templateEngine = new SpringTemplateEngine();
Expand Down Expand Up @@ -68,18 +71,19 @@ public Mono<Void> process(ITemplateContext context, IModel model, IElementModelS
private String highlightJsScript(BasicConfig basicConfig) {
var context = new Context();
context.setVariable("config", basicConfig);
context.setVariable("version", pluginContext.getVersion());
var code = templateEngine.process(
"""
<!-- PluginHighlightJS start -->
<link th:href="|/plugins/PluginHighlightJS/assets/static/styles/${config.style}|" rel="stylesheet"/>
<script defer src="/plugins/PluginHighlightJS/assets/static/highlight.min.js"></script>
<link th:href="|/plugins/PluginHighlightJS/assets/static/styles/${config.style}?version=${version}|" rel="stylesheet"/>
<script defer th:src="|/plugins/PluginHighlightJS/assets/static/highlight.min.js?version=${version}|"></script>
<th:block th:if="${config.showCopyButton}">
<link href="/plugins/PluginHighlightJS/assets/static/plugins/highlightjs-copy.css" rel="stylesheet"/>
<script defer src="/plugins/PluginHighlightJS/assets/static/plugins/highlightjs-copy.js"></script>
<link th:href="|/plugins/PluginHighlightJS/assets/static/plugins/highlightjs-copy.css?version=${version}|" rel="stylesheet"/>
<script defer th:src="|/plugins/PluginHighlightJS/assets/static/plugins/highlightjs-copy.js?version=${version}|"></script>
</th:block>
<link href="/plugins/PluginHighlightJS/assets/static/plugins/override.css" rel="stylesheet"/>
<link th:href="|/plugins/PluginHighlightJS/assets/static/plugins/override.css?version=${version}|" rel="stylesheet"/>
<script th:inline="javascript">
document.addEventListener("DOMContentLoaded", function () {
Expand Down

0 comments on commit bb0db2a

Please sign in to comment.