Skip to content

Commit

Permalink
兼容 2.17.0 版本
Browse files Browse the repository at this point in the history
  • Loading branch information
wenjing-xin committed Jul 2, 2024
1 parent 4d40313 commit 797ddc3
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 171 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ build {
}

halo {
version = '2.15.0'
version = '2.17.0'
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.0.0
version=1.0.1
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +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.theme.dialect.TemplateHeadProcessor;
import xin.wenjing.blogHao.entity.Settings;
import xin.wenjing.blogHao.util.InferStream;
import xin.wenjing.blogHao.util.ScriptContentUtils;

/**
Expand All @@ -24,26 +21,16 @@
@AllArgsConstructor
public class BlogHaoTagProcessor implements TemplateHeadProcessor {

private final SettingFetcher settingFetcher;

private final PluginWrapper pluginWrapper;

@Override
public Mono<Void> process(ITemplateContext context, IModel model,
IElementModelStructureHandler structureHandler) {
final IModelFactory modelFactory = context.getModelFactory();

return InferStream.<Void>infer(true)
.success(() -> settingFetcher
.fetch("miniTools", Settings.MiniTool.class)
.map(config -> {
model.add(modelFactory.createText(
ScriptContentUtils.blogHaoEle(pluginWrapper.getDescriptor().getVersion()
)));
return Mono.empty();
})
.orElse(Mono.empty()).then()).last();
String version = pluginWrapper.getDescriptor().getVersion();
return Mono.just(modelFactory.createText(ScriptContentUtils.blogHaoEle(version)))
.doOnNext(model::add)
.then();
}


}
43 changes: 23 additions & 20 deletions src/main/java/xin/wenjing/blogHao/processor/ColorlessProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.thymeleaf.model.IModelFactory;
import org.thymeleaf.processor.element.IElementModelStructureHandler;
import reactor.core.publisher.Mono;
import run.halo.app.plugin.ReactiveSettingFetcher;
import run.halo.app.plugin.SettingFetcher;
import run.halo.app.theme.dialect.TemplateHeadProcessor;
import xin.wenjing.blogHao.entity.Settings;
Expand All @@ -24,30 +25,32 @@
@AllArgsConstructor
public class ColorlessProcessor implements TemplateHeadProcessor {

private final SettingFetcher settingFetcher;
private final ReactiveSettingFetcher settingFetcher;

@Override
public Mono<Void> process(ITemplateContext context, IModel model, IElementModelStructureHandler structureHandler) {

Settings.MiniTool miniTool =settingFetcher.fetch(Settings.MiniTool.GROUP_NAME, Settings.MiniTool.class)
.orElse(new Settings.MiniTool());
LocalDate selfCloseAt = miniTool.getColorless().getSelfCloseAt();

if(!miniTool.getColorless().isEnableColorless()){
return Mono.empty();
}

if (selfCloseAt != null && selfCloseAt.isBefore(LocalDate.now())) {
return Mono.empty();
}

String templateId = ScriptContentUtils.getTemplateId(context);
boolean onlyIndex = BooleanUtils.isNotTrue(miniTool.getColorless().isColorlessScope());
if(onlyIndex && !StringUtils.equals("index", templateId)){
return Mono.empty();
}
final IModelFactory modelFactory = context.getModelFactory();
return Mono.just(modelFactory.createText(ScriptContentUtils.colorlessStyle())).doOnNext(model::add).then();
return settingFetcher.fetch(Settings.MiniTool.GROUP_NAME, Settings.MiniTool.class)
.doOnNext( miniTool -> {
LocalDate selfCloseAt = miniTool.getColorless().getSelfCloseAt();

if(!miniTool.getColorless().isEnableColorless()){
return;
}

if (selfCloseAt != null && selfCloseAt.isBefore(LocalDate.now())) {
return;
}

String templateId = ScriptContentUtils.getTemplateId(context);
boolean onlyIndex = BooleanUtils.isNotTrue(miniTool.getColorless().isColorlessScope());
if(onlyIndex && !StringUtils.equals("index", templateId)){
return;
}
final IModelFactory modelFactory = context.getModelFactory();
model.add(modelFactory.createText(ScriptContentUtils.colorlessStyle()));
}).then();

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package xin.wenjing.blogHao.processor;

import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
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.plugin.ReactiveSettingFetcher;
import run.halo.app.theme.dialect.TemplateHeadProcessor;
import xin.wenjing.blogHao.entity.Settings;
import xin.wenjing.blogHao.util.ScriptContentUtils;

/**
* 功能描述
* 复制追加功能
* @author: dreamChaser
* @date: 2024年06月16日 00:21
*/
@Component
@AllArgsConstructor
public class CopyAddHeadProcessor implements TemplateHeadProcessor {

private final ReactiveSettingFetcher settingFetcher;

@Override
public Mono<Void> process( ITemplateContext context, IModel model, IElementModelStructureHandler structureHandler) {
return settingFetcher.fetch(Settings.CopyAdd.GROUP_NAME, Settings.CopyAdd.class)
.doOnNext( copyAdd -> {
// 复制内容追加
if (copyAdd.isContentPageOnly() && ScriptContentUtils.notContentTemplate(context)) {
return;
}
String copyAddScript = ScriptContentUtils.copyAddScrProcess(copyAdd.getCopyAddContent(), copyAdd.getDivideType(), copyAdd.getCopyMinLength());
final IModelFactory modelFactory = context.getModelFactory();
model.add(modelFactory.createText(copyAddScript));
}).then();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,64 +7,49 @@
import org.thymeleaf.model.IModelFactory;
import org.thymeleaf.processor.element.IElementModelStructureHandler;
import reactor.core.publisher.Mono;
import run.halo.app.plugin.ReactiveSettingFetcher;
import run.halo.app.plugin.SettingFetcher;
import run.halo.app.theme.dialect.TemplateHeadProcessor;
import xin.wenjing.blogHao.entity.Settings;
import xin.wenjing.blogHao.util.ScriptContentUtils;

/**
* 功能描述
* 全局脚本注入
* 小工具脚本注入
* @author: dreamChaser
* @date: 2024年06月16日 00:21
*/
@Component
@AllArgsConstructor
public class GlobalInjectProcessor implements TemplateHeadProcessor {
public class MiniToolsProcessor implements TemplateHeadProcessor {

private final SettingFetcher settingFetcher;
private final ReactiveSettingFetcher settingFetcher;

@Override
public Mono<Void> process(ITemplateContext context, IModel model, IElementModelStructureHandler structureHandler) {

String scriptRes = finalScript(context);

if(scriptRes == null && scriptRes.length() == 0){
return Mono.empty();
}

final IModelFactory modelFactory = context.getModelFactory();
return Mono.just(modelFactory.createText(scriptRes)).doOnNext(model::add).then();
return settingFetcher.fetch(Settings.MiniTool.GROUP_NAME, Settings.MiniTool.class)
.doOnNext( miniTool -> {
String scriptRes = miniToolsScript( miniTool);
if(scriptRes == null && scriptRes.length() == 0){
return;
}
final IModelFactory modelFactory = context.getModelFactory();
model.add(modelFactory.createText(scriptRes));
}).then();
}

private String finalScript(ITemplateContext context) {
private String miniToolsScript(Settings.MiniTool miniTool) {

StringBuilder injectCode = new StringBuilder();
Settings.CopyAdd copyAdd = settingFetcher.fetch(Settings.CopyAdd.GROUP_NAME, Settings.CopyAdd.class)
.orElse(new Settings.CopyAdd());
Settings.MiniTool miniTool =settingFetcher.fetch(Settings.MiniTool.GROUP_NAME, Settings.MiniTool.class)
.orElse(new Settings.MiniTool());

// 复制内容追加
if(copyAdd.isContentPageOnly() && ScriptContentUtils.notContentTemplate(context)){
injectCode.append("");
}else{
String copyAddScript = ScriptContentUtils.copyAddScrProcess(copyAdd.getCopyAddContent(), copyAdd.getDivideType(), copyAdd.getCopyMinLength());
injectCode.append(copyAddScript);
}

// 中英文空格脚本
if(miniTool.getContentSpace().isEnableContentSpace()){
injectCode.append(ScriptContentUtils.panguScript(miniTool));
}

// 段落内容首行缩进
if(miniTool.getContentIndent().isEnableContentIndent()){
injectCode.append("""
<style type="text/css"> %s p:not(li>p):not(blockquote>p){text-indent: 2em;} </style>
""".formatted(miniTool.getContentIndent().getIndentNodeName()));
}

return injectCode.toString();
}

Expand Down
21 changes: 11 additions & 10 deletions src/main/java/xin/wenjing/blogHao/processor/SlideProcessor.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.blogHao.entity.Settings;
import xin.wenjing.blogHao.util.ScriptContentUtils;
Expand All @@ -23,21 +23,22 @@
@AllArgsConstructor
public class SlideProcessor 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.SlideConfig slideConfig =settingFetcher.fetch(Settings.SlideConfig.GROUP_NAME, Settings.SlideConfig.class)
.orElse(new Settings.SlideConfig());
return settingFetcher.fetch(Settings.SlideConfig.GROUP_NAME, Settings.SlideConfig.class)
.doOnNext( slideConfig -> {
if(!slideConfig.isEnableSlide()){
return;
}
final IModelFactory modelFactory = context.getModelFactory();
String version = pluginWrapper.getDescriptor().getVersion();
model.add(modelFactory.createText(ScriptContentUtils.slideScript(slideConfig, version)));
}).then();

if(!slideConfig.isEnableSlide()){
return Mono.empty();
}

final IModelFactory modelFactory = context.getModelFactory();
return Mono.just(modelFactory.createText(ScriptContentUtils.slideScript(slideConfig, pluginWrapper.getDescriptor().getVersion()))).doOnNext(model::add).then();
}
}
92 changes: 0 additions & 92 deletions src/main/java/xin/wenjing/blogHao/util/InferStream.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ScriptContentUtils {
public static String copyAddScrProcess(String copyAddContent, String divideType, String copyMinLength) {

String processContent = switch (divideType) {
case "line" -> "\\n---\\n" + copyAddContent;
case "line" -> "\\n------\\n" + copyAddContent;
case "emptyLine" -> "\\n \\n" + copyAddContent;
default -> " " + copyAddContent;
};
Expand Down

0 comments on commit 797ddc3

Please sign in to comment.