-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release-2.2] fix: route for the tag is not registered when halo star…
…ts (#3323) This is an automated cherry-pick of #3322 /assign guqing ```release-note 修复 #3316 引入的 tags 标签的路由没有注册的问题 ```
- Loading branch information
1 parent
3ae174c
commit a227341
Showing
3 changed files
with
61 additions
and
51 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
56 changes: 56 additions & 0 deletions
56
src/main/java/run/halo/app/core/extension/reconciler/TagRouteReconciler.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,56 @@ | ||
package run.halo.app.core.extension.reconciler; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.stereotype.Component; | ||
import run.halo.app.content.permalinks.TagPermalinkPolicy; | ||
import run.halo.app.core.extension.content.Tag; | ||
import run.halo.app.extension.ExtensionClient; | ||
import run.halo.app.extension.controller.Controller; | ||
import run.halo.app.extension.controller.ControllerBuilder; | ||
import run.halo.app.extension.controller.Reconciler; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class TagRouteReconciler implements Reconciler<Reconciler.Request> { | ||
private final ExtensionClient client; | ||
private final TagPermalinkPolicy tagPermalinkPolicy; | ||
|
||
@Override | ||
public Result reconcile(Request request) { | ||
client.fetch(Tag.class, request.name()) | ||
.ifPresent(tag -> { | ||
if (tag.getMetadata().getDeletionTimestamp() != null) { | ||
// TagReconciler already did it, so there is no need to remove permalink | ||
return; | ||
} | ||
|
||
reconcilePermalinkRoute(request.name()); | ||
}); | ||
return new Result(false, null); | ||
} | ||
|
||
private void reconcilePermalinkRoute(String tagName) { | ||
client.fetch(Tag.class, tagName) | ||
.ifPresent(tag -> { | ||
final String oldPermalink = tag.getStatusOrDefault().getPermalink(); | ||
|
||
tagPermalinkPolicy.onPermalinkDelete(tag); | ||
|
||
String permalink = tagPermalinkPolicy.permalink(tag); | ||
tag.getStatusOrDefault().setPermalink(permalink); | ||
tagPermalinkPolicy.onPermalinkAdd(tag); | ||
|
||
if (!StringUtils.equals(permalink, oldPermalink)) { | ||
client.update(tag); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public Controller setupWith(ControllerBuilder builder) { | ||
return builder | ||
.extension(new Tag()) | ||
.build(); | ||
} | ||
} |
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