generated from halo-dev/plugin-starter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
16 changed files
with
892 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
reviewers: | ||
- ruibaby | ||
- guqing | ||
- JohnNiang | ||
- wangzhen-fit2cloud | ||
- Carol | ||
|
||
approvers: | ||
- ruibaby | ||
- guqing | ||
- JohnNiang | ||
- Carol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/site/xindu/afdian/finder/impl/AfdianFinderImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package site.xindu.afdian.finder.impl; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import org.apache.commons.lang3.time.DateUtils; | ||
import org.springframework.beans.BeanUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import reactor.core.publisher.Mono; | ||
import run.halo.app.infra.utils.JsonUtils; | ||
import run.halo.app.theme.finders.Finder; | ||
import site.xindu.afdian.entity.SponsorEntity; | ||
import site.xindu.afdian.finder.AfdianFinder; | ||
import site.xindu.afdian.service.SponsorService; | ||
import site.xindu.afdian.utils.DataUtils; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@Finder("afdianFinder") | ||
public class AfdianFinderImpl implements AfdianFinder { | ||
|
||
@Autowired | ||
private SponsorService sponsorService; | ||
|
||
/** | ||
* 获取全部赞助者信息 | ||
* | ||
* @return {@link SponsorEntity} | ||
*/ | ||
@Override | ||
public Mono<JsonNode> listSponsor(int pageNumber) { | ||
var mono = sponsorService.getSponsorList(pageNumber); | ||
return DataUtils.changePayTime(mono); | ||
} | ||
|
||
/** | ||
* 获取全部赞助者信息 | ||
* | ||
* @return {@link SponsorEntity} | ||
*/ | ||
@Override | ||
public Mono<JsonNode> listAllSponsor() { | ||
var mono = sponsorService.listAllSponsor(); | ||
return DataUtils.changePayTime(mono); | ||
} | ||
|
||
/** | ||
* 格式化时间 yyyy-MM-dd | ||
* | ||
* @param timestamp 时间戳 | ||
* @return time String | ||
*/ | ||
@Override | ||
public String parseTime(Long timestamp) { | ||
var length = timestamp.toString().length(); | ||
if (length == 10){ | ||
timestamp = timestamp * 1000; | ||
} | ||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); | ||
return simpleDateFormat.format(new Date(timestamp)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package site.xindu.afdian.service; | ||
|
||
import java.util.HashMap; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.reactive.function.server.RouterFunction; | ||
import org.springframework.web.reactive.function.server.RouterFunctions; | ||
import org.springframework.web.reactive.function.server.ServerRequest; | ||
import org.springframework.web.reactive.function.server.ServerResponse; | ||
import reactor.core.publisher.Mono; | ||
import run.halo.app.infra.utils.JsonUtils; | ||
import run.halo.app.plugin.ReactiveSettingFetcher; | ||
import run.halo.app.theme.TemplateNameResolver; | ||
import site.xindu.afdian.entity.SponsorEntity; | ||
import site.xindu.afdian.finder.AfdianFinder; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Configuration(proxyBeanMethods = false) | ||
public class AfdianRouter { | ||
|
||
private final TemplateNameResolver templateNameResolver; | ||
|
||
private final AfdianFinder afdianFinder; | ||
|
||
private final ReactiveSettingFetcher settingFetcher; | ||
|
||
@Bean | ||
RouterFunction<ServerResponse> momentRouterFunction() { | ||
return RouterFunctions.route().GET("/afdian", this::renderPage).build(); | ||
} | ||
|
||
Mono<ServerResponse> renderPage(ServerRequest request) { | ||
// 准备需要提供给模板的默认数据 | ||
var model = new HashMap<String, Object>(); | ||
Mono<String> sponsorUrl = this.settingFetcher.get("basic").map(setting -> | ||
setting.get("sponsorUrl").asText("https://afdian.net/a/carolcoral") | ||
) | ||
.defaultIfEmpty("https://afdian.net/a/carolcoral"); | ||
model.put("sponsorUrl", sponsorUrl); | ||
log.info(model.toString()); | ||
return templateNameResolver.resolveTemplateNameOrDefault(request.exchange(), "afdian") | ||
.flatMap(templateName -> ServerResponse.ok().render(templateName, model)); | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/site/xindu/afdian/service/CustomHeadProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package site.xindu.afdian.service; | ||
|
||
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 | ||
public class CustomHeadProcessor implements TemplateHeadProcessor { | ||
|
||
private final PropertyPlaceholderHelper | ||
PROPERTY_PLACEHOLDER_HELPER = new PropertyPlaceholderHelper("${", "}"); | ||
private final PluginWrapper pluginWrapper; | ||
|
||
@Override | ||
public Mono<Void> process(ITemplateContext context, IModel model, | ||
IElementModelStructureHandler structureHandler) { | ||
return Mono.just(this.contactFormHtml()).doOnNext((html) -> { | ||
IModelFactory modelFactory = context.getModelFactory(); | ||
model.add(modelFactory.createText(html)); | ||
}).then(); | ||
} | ||
|
||
private String contactFormHtml() { | ||
Properties properties = new Properties(); | ||
properties.setProperty("version", this.pluginWrapper.getDescriptor().getVersion()); | ||
properties.setProperty("pluginStaticPath", "/plugins/plugin-afdian/assets/static"); | ||
return this.PROPERTY_PLACEHOLDER_HELPER.replacePlaceholders("", properties); | ||
} | ||
|
||
public CustomHeadProcessor(PluginWrapper pluginWrapper) { | ||
this.pluginWrapper = pluginWrapper; | ||
} | ||
} |
34 changes: 0 additions & 34 deletions
34
src/main/java/site/xindu/afdian/service/DefaultSettingFetcher.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
src/main/java/site/xindu/afdian/service/impl/AfdianFinderServiceImpl.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.