Skip to content

Commit

Permalink
兼容 halo 2.17 版本
Browse files Browse the repository at this point in the history
  • Loading branch information
wenjing-xin committed Jul 2, 2024
1 parent c22f68f commit 0e2c600
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ build {
}

halo {
version = '2.14.0'
version = '2.17.0'
debug = true
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.2.0
version=1.2.1
2 changes: 1 addition & 1 deletion src/main/java/xin/wenjing/halo/artalk/ArtalkComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private String ldTemplateResolve(String siteTitle, String artalkUrl, String priv
</div>
<div id="artalk-comment"></div>
</div>
<script type="text/javascript" data-pjax>
<script type="text/javascript" data-pjax defer>
document.addEventListener("DOMContentLoaded",()=>{
if(document.querySelectorAll("#artalk-comment").length){
Artalk.init({
Expand Down
37 changes: 18 additions & 19 deletions src/main/java/xin/wenjing/halo/artalk/ArtalkStaticInject.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.thymeleaf.model.IModelFactory;
import org.thymeleaf.processor.element.IElementModelStructureHandler;
import reactor.core.publisher.Mono;
import run.halo.app.plugin.SettingFetcher;
import run.halo.app.plugin.ReactiveSettingFetcher;
import run.halo.app.theme.dialect.TemplateHeadProcessor;
import xin.wenjing.halo.entity.Settings;

Expand All @@ -22,30 +22,29 @@
@RequiredArgsConstructor
public class ArtalkStaticInject implements TemplateHeadProcessor {

private final SettingFetcher settingFetcher;
private final ReactiveSettingFetcher settingFetcher;

private final PluginWrapper pluginWrapper;

@Override
public Mono<Void> process(ITemplateContext context, IModel model, IElementModelStructureHandler structureHandler) {
Settings baseConf = settingFetcher.fetch(Settings.GROUP, Settings.class).orElse(new Settings());
return settingFetcher.fetch(Settings.GROUP, Settings.class)
.doOnNext( baseConf ->{
String injectContent = "";

String injectContent = "";
// 开启明暗模式后自定义css加入
if(baseConf.isEnableCustomCss() && baseConf.isEnableLightDark()){
injectContent = customCssResolve(baseConf.getCustomCss());
}
// 明暗模式关闭且没有自定义Css的时候,注入默认样式
if(!baseConf.isEnableLightDark() && !baseConf.isEnableCustomCss()){
injectContent = normalStatic();
}

// 开启明暗模式后自定义css加入
if(baseConf.isEnableCustomCss() && baseConf.isEnableLightDark()){
injectContent = customCssResolve(baseConf.getCustomCss());
}
// 明暗模式关闭且没有自定义Css的时候,注入默认样式
if(!baseConf.isEnableLightDark() && !baseConf.isEnableCustomCss()){
injectContent = normalStatic();
}

String pubInjectContent = pubScriptInject(baseConf.isEnableLatex(), baseConf.getCssUrl(), baseConf.getJsUrl());
final IModelFactory modelFactory = context.getModelFactory();
return Mono.just(modelFactory.createText(injectContent + pubInjectContent))
.doOnNext(model::add)
.then();
String pubInjectContent = pubScriptInject(baseConf.isEnableLatex(), baseConf.getCssUrl(), baseConf.getJsUrl());
final IModelFactory modelFactory = context.getModelFactory();
model.add(modelFactory.createText(injectContent + pubInjectContent));
}).then();
}

/**
Expand Down Expand Up @@ -89,7 +88,7 @@ private static String customCssResolve(String cssContent){
}

/**
* 无明暗模式下的中等样式
* 无明暗模式下的中性样式
* @return
*/
private String normalStatic() {
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/extensions/extension-definitions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: plugin.halo.run/v1alpha1
kind: ExtensionDefinition
metadata:
name: artalk-comment
spec:
className: xin.wenjing.halo.artalk.ArtalkComment
extensionPointName: comment-widget
displayName: "artalk评论组件"
description: "由作者 dreamChaser的小屋 提供的第三方评论组件"
2 changes: 1 addition & 1 deletion src/main/resources/extensions/roleTemplate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
rbac.authorization.halo.run/aggregate-to-anonymous: "true"
annotations:
rbac.authorization.halo.run/module: "Config Management"
rbac.authorization.halo.run/display-name: "DataList Manage"
rbac.authorization.halo.run/display-name: "ArtalkData Operation"

rules:
- apiGroups: ["halo.wenjing.xin"]
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/extensions/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ spec:
name: customCss
if: $get(enableCustomCss).value
label: css样式
value:
value: a{display:inline-block;}
language: css
help: 支持css语法样式,无需包裹style标签
height: 350px
Expand Down

0 comments on commit 0e2c600

Please sign in to comment.