diff --git a/src/main/java/run/halo/app/service/ThemeService.java b/src/main/java/run/halo/app/service/ThemeService.java index 41e3a5fee..5a4b15dfa 100644 --- a/src/main/java/run/halo/app/service/ThemeService.java +++ b/src/main/java/run/halo/app/service/ThemeService.java @@ -7,6 +7,7 @@ import run.halo.app.model.support.ThemeProperties; import java.io.File; import java.util.List; +import java.util.Map; /** * @author : RYAN0UP @@ -27,6 +28,7 @@ public interface ThemeService { * @param absolutePath absolutePath * @return List */ + @Deprecated List listThemeFolder(@NonNull String absolutePath); /** @@ -82,6 +84,7 @@ public interface ThemeService { * @param absolutePath absolute path * @return template content */ + @Deprecated String getTemplateContent(@NonNull String absolutePath); /** @@ -98,4 +101,13 @@ public interface ThemeService { * @param key theme key */ void deleteTheme(@NonNull String key); + + /** + * Fetchs theme configuration. + * + * @param themeName theme name must not be blank + * @return theme configuration + */ + @NonNull + Map fetchConfig(@NonNull String themeName); } diff --git a/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java b/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java index 31db76830..9802a8ff5 100644 --- a/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java @@ -7,6 +7,7 @@ import cn.hutool.core.text.StrBuilder; import cn.hutool.core.util.StrUtil; import cn.hutool.setting.dialect.Props; import org.springframework.stereotype.Service; +import org.springframework.util.Assert; import run.halo.app.config.properties.HaloProperties; import run.halo.app.exception.NotFoundException; import run.halo.app.model.support.HaloConst; @@ -20,6 +21,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import java.util.Map; /** * @author : RYAN0UP @@ -256,4 +258,12 @@ public class ThemeServiceImpl implements ThemeService { FileUtil.del(file); HaloConst.THEMES = this.getThemes(); } + + @Override + public Map fetchConfig(String themeName) { + Assert.hasText(themeName, "Theme name must not be blank"); + + + return null; + } } diff --git a/src/test/java/run/halo/app/utils/YamlTest.java b/src/test/java/run/halo/app/utils/YamlTest.java new file mode 100644 index 000000000..d9c4e882c --- /dev/null +++ b/src/test/java/run/halo/app/utils/YamlTest.java @@ -0,0 +1,46 @@ +package run.halo.app.utils; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import org.junit.Test; + +import java.io.IOException; + +/** + * Yaml test. + * + * @author johnniang + * @date 4/8/19 + */ +public class YamlTest { + + private final ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory()); + + private final ObjectMapper jsonMapper = new ObjectMapper(); + + @Test + public void readYamlTest() throws IOException { + + String yaml = "style:\n" + + " name: Style settings\n" + + " items:\n" + + " post_title_lower:\n" + + " name: post_title_lower\n" + + " description: Post title lower\n" + + " type: radio\n" + + " defaultValue: true\n" + + " options:\n" + + " - value: true\n" + + " label: Enabled\n" + + " - value: false\n" + + " label: Disabled\n" + + " custom_style:\n" + + " name: custom_style\n" + + " description: Custom style\n" + + " type: textarea\n"; + + Object config = yamlMapper.readValue(yaml, Object.class); + + System.out.println(jsonMapper.writeValueAsString(config)); + } +}