Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Halo version variable to theme model #6677

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import reactor.core.publisher.Mono;
import run.halo.app.infra.ExternalUrlSupplier;
import run.halo.app.infra.SystemConfigurableEnvironmentFetcher;
import run.halo.app.infra.SystemVersionSupplier;
import run.halo.app.theme.finders.vo.SiteSettingVo;

/**
Expand All @@ -21,14 +22,16 @@ public class SiteSettingVariablesAcquirer implements ViewContextBasedVariablesAc

private final SystemConfigurableEnvironmentFetcher environmentFetcher;
private final ExternalUrlSupplier externalUrlSupplier;
private final SystemVersionSupplier systemVersionSupplier;

@Override
public Mono<Map<String, Object>> acquire(ServerWebExchange exchange) {
return environmentFetcher.getConfigMap()
.filter(configMap -> configMap.getData() != null)
.map(configMap -> {
SiteSettingVo siteSettingVo = SiteSettingVo.from(configMap)
.withUrl(externalUrlSupplier.getURL(exchange.getRequest()));
.withUrl(externalUrlSupplier.getURL(exchange.getRequest()))
.withVersion(systemVersionSupplier.get().toString());
return Map.of("site", siteSettingVo);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class SiteSettingVo {
@With
URL url;

@With
String version;

String subtitle;

String logo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import com.github.zafarkhaja.semver.Version;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
Expand All @@ -20,6 +21,7 @@
import run.halo.app.extension.ConfigMap;
import run.halo.app.infra.ExternalUrlSupplier;
import run.halo.app.infra.SystemConfigurableEnvironmentFetcher;
import run.halo.app.infra.SystemVersionSupplier;
import run.halo.app.theme.finders.vo.SiteSettingVo;

/**
Expand All @@ -32,6 +34,10 @@
public class SiteSettingVariablesAcquirerTest {
@Mock
private ExternalUrlSupplier externalUrlSupplier;

@Mock
private SystemVersionSupplier systemVersionSupplier;

@Mock
private SystemConfigurableEnvironmentFetcher environmentFetcher;

Expand All @@ -45,16 +51,21 @@ void acquireWhenExternalUrlSet() throws MalformedURLException {

var url = new URL("https://halo.run");
when(externalUrlSupplier.getURL(any())).thenReturn(url);
when(systemVersionSupplier.get()).thenReturn(Version.parse("0.0.0-alpha.1"));
when(environmentFetcher.getConfigMap()).thenReturn(Mono.just(configMap));

siteSettingVariablesAcquirer.acquire(mock(ServerWebExchange.class))
.as(StepVerifier::create)
.consumeNextWith(result -> {
assertThat(result).containsKey("site");
assertThat(result.get("site")).isInstanceOf(SiteSettingVo.class);
assertThat((SiteSettingVo) result.get("site"))
var site = (SiteSettingVo) result.get("site");
assertThat(site)
.extracting(SiteSettingVo::getUrl)
.isEqualTo(url);
assertThat(site)
.extracting(SiteSettingVo::getVersion)
.isEqualTo("0.0.0-alpha.1");
})
.verifyComplete();
verify(externalUrlSupplier).getURL(any());
Expand Down
Loading