mirror of https://github.com/halo-dev/halo
feat: add location for theme (#2484)
#### What type of PR is this? /kind improvement /area core /milestone 2.0 #### What this PR does / why we need it: 主题支持展示绝对路径位置 #### Which issue(s) this PR fixes: Fixes #2461 #### Special notes for your reviewer: /cc @halo-dev/sig-halo #### Does this PR introduce a user-facing change? ```release-note None ```pull/2493/head
parent
fe3860a8b2
commit
27e151a574
|
@ -25,6 +25,8 @@ public class Theme extends AbstractExtension {
|
|||
@Schema(required = true)
|
||||
private ThemeSpec spec;
|
||||
|
||||
private ThemeStatus status;
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
public static class ThemeSpec {
|
||||
|
@ -69,6 +71,11 @@ public class Theme extends AbstractExtension {
|
|||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class ThemeStatus {
|
||||
private String location;
|
||||
}
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
public static class Author {
|
||||
|
|
|
@ -47,10 +47,25 @@ public class ThemeReconciler implements Reconciler<Request> {
|
|||
reconcileThemeDeletion(theme);
|
||||
}
|
||||
themeSettingDefaultConfig(theme);
|
||||
reconcileStatus(request.name());
|
||||
});
|
||||
return new Result(false, null);
|
||||
}
|
||||
|
||||
private void reconcileStatus(String name) {
|
||||
client.fetch(Theme.class, name).ifPresent(theme -> {
|
||||
Theme oldTheme = JsonUtils.deepCopy(theme);
|
||||
if (theme.getStatus() == null) {
|
||||
theme.setStatus(new Theme.ThemeStatus());
|
||||
}
|
||||
Path themePath = themePathPolicy.generate(theme);
|
||||
theme.getStatus().setLocation(themePath.toAbsolutePath().toString());
|
||||
if (!oldTheme.equals(theme)) {
|
||||
client.update(theme);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void themeSettingDefaultConfig(Theme theme) {
|
||||
if (StringUtils.isBlank(theme.getSpec().getSettingName())) {
|
||||
return;
|
||||
|
|
|
@ -102,7 +102,7 @@ class ThemeReconcilerTest {
|
|||
|
||||
themeReconciler.reconcile(new Reconciler.Request(metadata.getName()));
|
||||
|
||||
verify(extensionClient, times(2)).fetch(eq(Theme.class), eq(metadata.getName()));
|
||||
verify(extensionClient, times(3)).fetch(eq(Theme.class), eq(metadata.getName()));
|
||||
verify(extensionClient, times(2)).fetch(eq(Setting.class), eq(themeSpec.getSettingName()));
|
||||
|
||||
assertThat(Files.exists(testWorkDir)).isTrue();
|
||||
|
@ -133,7 +133,7 @@ class ThemeReconcilerTest {
|
|||
Reconciler.Result reconcile =
|
||||
themeReconciler.reconcile(new Reconciler.Request(metadata.getName()));
|
||||
assertThat(reconcile.reEnqueue()).isFalse();
|
||||
verify(extensionClient, times(1)).fetch(eq(Theme.class), eq(metadata.getName()));
|
||||
verify(extensionClient, times(2)).fetch(eq(Theme.class), eq(metadata.getName()));
|
||||
|
||||
// setting exists
|
||||
themeSpec.setSettingName("theme-test-setting");
|
||||
|
@ -142,9 +142,9 @@ class ThemeReconcilerTest {
|
|||
assertThat(theme.getSpec().getConfigMapName()).isNull();
|
||||
ArgumentCaptor<Theme> captor = ArgumentCaptor.forClass(Theme.class);
|
||||
themeReconciler.reconcile(new Reconciler.Request(metadata.getName()));
|
||||
verify(extensionClient, times(3))
|
||||
verify(extensionClient, times(5))
|
||||
.fetch(eq(Theme.class), eq(metadata.getName()));
|
||||
verify(extensionClient, times(1))
|
||||
verify(extensionClient, times(2))
|
||||
.update(captor.capture());
|
||||
Theme value = captor.getValue();
|
||||
assertThat(value.getSpec().getConfigMapName()).isNotNull();
|
||||
|
|
Loading…
Reference in New Issue