mirror of https://github.com/halo-dev/halo
代码优化
parent
cb4519a3ed
commit
0530171e5f
|
@ -16,9 +16,9 @@ public class Theme implements Serializable {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Theme dir
|
* Theme key,is theme folder name.
|
||||||
*/
|
*/
|
||||||
private String themeDir;
|
private String key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is support setting options
|
* Is support setting options
|
||||||
|
|
|
@ -26,7 +26,16 @@ import java.util.List;
|
||||||
@Service
|
@Service
|
||||||
public class ThemeServiceImpl implements ThemeService {
|
public class ThemeServiceImpl implements ThemeService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of file that can be modified.
|
||||||
|
*/
|
||||||
private static String[] CAN_EDIT_SUFFIX = {"ftl", "css", "js"};
|
private static String[] CAN_EDIT_SUFFIX = {"ftl", "css", "js"};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* These file names cannot be displayed.
|
||||||
|
*/
|
||||||
|
private static String[] FILTER_FILES = {".git", ".DS_Store", "theme.properties"};
|
||||||
|
|
||||||
private final HaloProperties haloProperties;
|
private final HaloProperties haloProperties;
|
||||||
|
|
||||||
public ThemeServiceImpl(HaloProperties haloProperties) {
|
public ThemeServiceImpl(HaloProperties haloProperties) {
|
||||||
|
@ -50,13 +59,9 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
theme = new Theme();
|
theme = new Theme();
|
||||||
theme.setThemeDir(file.getName());
|
theme.setKey(file.getName());
|
||||||
File optionsPath = new File(getThemeBasePath().getAbsolutePath(), file.getName() + "/module/options.ftl");
|
File optionsPath = new File(file.getAbsolutePath(), "module/options.ftl");
|
||||||
if (optionsPath.exists()) {
|
theme.setHasOptions(optionsPath.exists());
|
||||||
theme.setHasOptions(true);
|
|
||||||
} else {
|
|
||||||
theme.setHasOptions(false);
|
|
||||||
}
|
|
||||||
theme.setProperties(getProperties(new File(getThemeBasePath(), file.getName())));
|
theme.setProperties(getProperties(new File(getThemeBasePath(), file.getName())));
|
||||||
themes.add(theme);
|
themes.add(theme);
|
||||||
}
|
}
|
||||||
|
@ -80,7 +85,13 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
File absolutePathFile = new File(absolutePath);
|
File absolutePathFile = new File(absolutePath);
|
||||||
File[] baseFiles = absolutePathFile.listFiles();
|
File[] baseFiles = absolutePathFile.listFiles();
|
||||||
if (null != baseFiles) {
|
if (null != baseFiles) {
|
||||||
|
baseFileFor:
|
||||||
for (File base : baseFiles) {
|
for (File base : baseFiles) {
|
||||||
|
for (String filterFile : FILTER_FILES) {
|
||||||
|
if (filterFile.equals(base.getName())) {
|
||||||
|
continue baseFileFor;
|
||||||
|
}
|
||||||
|
}
|
||||||
ThemeFile file = new ThemeFile();
|
ThemeFile file = new ThemeFile();
|
||||||
if (base.isDirectory()) {
|
if (base.isDirectory()) {
|
||||||
file.setName(base.getName());
|
file.setName(base.getName());
|
||||||
|
|
|
@ -54,6 +54,11 @@ public class AdminController {
|
||||||
this.linkService = linkService;
|
this.linkService = linkService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get some statistics about the count of posts, the count of comments, etc.
|
||||||
|
*
|
||||||
|
* @return counts
|
||||||
|
*/
|
||||||
@GetMapping("counts")
|
@GetMapping("counts")
|
||||||
@ApiOperation("Gets count info")
|
@ApiOperation("Gets count info")
|
||||||
public CountOutputDTO getCount() {
|
public CountOutputDTO getCount() {
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
package run.halo.app.web.controller.admin.api;
|
package run.halo.app.web.controller.admin.api;
|
||||||
|
|
||||||
import run.halo.app.model.dto.CategoryOutputDTO;
|
|
||||||
import run.halo.app.model.entity.Category;
|
|
||||||
import run.halo.app.model.params.CategoryParam;
|
|
||||||
import run.halo.app.model.vo.CategoryVO;
|
|
||||||
import run.halo.app.service.CategoryService;
|
|
||||||
import run.halo.app.service.PostCategoryService;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.data.web.SortDefault;
|
import org.springframework.data.web.SortDefault;
|
||||||
|
@ -41,6 +35,12 @@ public class CategoryController {
|
||||||
this.postCategoryService = postCategoryService;
|
this.postCategoryService = postCategoryService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
@ApiOperation("List all categories")
|
||||||
|
public List<Category> listAll() {
|
||||||
|
return categoryService.listAll();
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("tree_view")
|
@GetMapping("tree_view")
|
||||||
@ApiOperation("List as category tree")
|
@ApiOperation("List as category tree")
|
||||||
public List<CategoryVO> listAsTree(@SortDefault(sort = "name", direction = ASC) Sort sort) {
|
public List<CategoryVO> listAsTree(@SortDefault(sort = "name", direction = ASC) Sort sort) {
|
||||||
|
|
|
@ -81,18 +81,18 @@ public class ThemeController {
|
||||||
/**
|
/**
|
||||||
* Active theme
|
* Active theme
|
||||||
*
|
*
|
||||||
* @param themeName theme name
|
* @param theme theme name
|
||||||
* @throws TemplateModelException TemplateModelException
|
* @throws TemplateModelException TemplateModelException
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "active")
|
@GetMapping(value = "active")
|
||||||
@ApiOperation("Active theme")
|
@ApiOperation("Active theme")
|
||||||
public void active(@RequestParam(name = "themeName", defaultValue = "anatole") String themeName) throws TemplateModelException {
|
public void active(@RequestParam(name = "theme", defaultValue = "anatole") String theme) throws TemplateModelException {
|
||||||
Map<PropertyEnum, String> properties = new HashMap<>(1);
|
Map<PropertyEnum, String> properties = new HashMap<>(1);
|
||||||
properties.put(PrimaryProperties.THEME, themeName);
|
properties.put(PrimaryProperties.THEME, theme);
|
||||||
// TODO Refactor: saveProperties => saveProperty
|
// TODO Refactor: saveProperties => saveProperty
|
||||||
optionService.saveProperties(properties, OptionSource.SYSTEM);
|
optionService.saveProperties(properties, OptionSource.SYSTEM);
|
||||||
HaloConst.ACTIVATED_THEME_NAME = themeName;
|
HaloConst.ACTIVATED_THEME_NAME = theme;
|
||||||
configuration.setSharedVariable("themeName", themeName);
|
configuration.setSharedVariable("themeName", theme);
|
||||||
configuration.setSharedVariable("options", optionService.listOptions());
|
configuration.setSharedVariable("options", optionService.listOptions());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue