From 109c2e099d1c238680f74d5d3657e8d506671507 Mon Sep 17 00:00:00 2001 From: ruibaby Date: Wed, 5 Jun 2019 21:24:39 +0800 Subject: [PATCH 01/19] Support war package. --- build.gradle | 1 + src/main/java/run/halo/app/Application.java | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 4ece1a6f8..e868015fe 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ plugins { id 'org.springframework.boot' version '2.1.3.RELEASE' id "io.freefair.lombok" version "3.1.4" id 'java' + id 'war' } apply plugin: 'io.spring.dependency-management' diff --git a/src/main/java/run/halo/app/Application.java b/src/main/java/run/halo/app/Application.java index b4e6fb4f9..28ec81d22 100755 --- a/src/main/java/run/halo/app/Application.java +++ b/src/main/java/run/halo/app/Application.java @@ -2,6 +2,8 @@ package run.halo.app; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.scheduling.annotation.EnableAsync; @@ -21,7 +23,7 @@ import run.halo.app.repository.base.BaseRepositoryImpl; @EnableScheduling @EnableAsync @EnableJpaRepositories(basePackages = "run.halo.app.repository", repositoryBaseClass = BaseRepositoryImpl.class) -public class Application { +public class Application extends SpringBootServletInitializer { public static void main(String[] args) { // Customize the spring config location @@ -30,4 +32,10 @@ public class Application { // Run application SpringApplication.run(Application.class, args); } + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + System.setProperty("spring.config.additional-location", "file:${user.home}/.halo/,file:${user.home}/halo-dev/"); + return application.sources(Application.class); + } } From bb17d15b2570d6f3303fd4878450a1de7b8b0e8f Mon Sep 17 00:00:00 2001 From: ruibaby Date: Thu, 6 Jun 2019 01:01:12 +0800 Subject: [PATCH 02/19] Fixed commentTag variable. --- .../run/halo/app/model/freemarker/tag/CommentTagDirective.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/run/halo/app/model/freemarker/tag/CommentTagDirective.java b/src/main/java/run/halo/app/model/freemarker/tag/CommentTagDirective.java index 8c6b15d01..9b01c571b 100644 --- a/src/main/java/run/halo/app/model/freemarker/tag/CommentTagDirective.java +++ b/src/main/java/run/halo/app/model/freemarker/tag/CommentTagDirective.java @@ -34,7 +34,7 @@ public class CommentTagDirective implements TemplateDirectiveModel { switch (method) { case "latest": int top = Integer.parseInt(params.get("top").toString()); - env.setVariable("categories", builder.build().wrap(postCommentService.pageLatest(top))); + env.setVariable("comments", builder.build().wrap(postCommentService.pageLatest(top))); break; case "count": env.setVariable("count", builder.build().wrap(postCommentService.count())); From 9849fe65cb6c9901445e12995ac28a314275a1af Mon Sep 17 00:00:00 2001 From: ruibaby Date: Fri, 7 Jun 2019 00:54:17 +0800 Subject: [PATCH 03/19] Change listDtos method to listTeamVos. --- .../run/halo/app/model/freemarker/tag/PhotoTagDirective.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/run/halo/app/model/freemarker/tag/PhotoTagDirective.java b/src/main/java/run/halo/app/model/freemarker/tag/PhotoTagDirective.java index fc5ad3c14..16e55b374 100644 --- a/src/main/java/run/halo/app/model/freemarker/tag/PhotoTagDirective.java +++ b/src/main/java/run/halo/app/model/freemarker/tag/PhotoTagDirective.java @@ -39,7 +39,7 @@ public class PhotoTagDirective implements TemplateDirectiveModel { env.setVariable("photos", builder.build().wrap(photoService.listAll())); break; case "listTeams": - env.setVariable("teams", builder.build().wrap(photoService.listDtos(Sort.by(DESC, "createTime")))); + env.setVariable("teams", builder.build().wrap(photoService.listTeamVos(Sort.by(DESC, "createTime")))); break; case "listByTeam": String team = params.get("team").toString(); From 3dc0a4ea39717dc94c418c425d27a2cc8ee0428a Mon Sep 17 00:00:00 2001 From: johnniang Date: Fri, 7 Jun 2019 09:29:03 +0800 Subject: [PATCH 04/19] Fix #186 --- .../halo/app/controller/base/ControllerExceptionHandler.java | 2 +- .../java/run/halo/app/controller/core/CommonController.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/run/halo/app/controller/base/ControllerExceptionHandler.java b/src/main/java/run/halo/app/controller/base/ControllerExceptionHandler.java index bd756d1d4..5bd8474cd 100644 --- a/src/main/java/run/halo/app/controller/base/ControllerExceptionHandler.java +++ b/src/main/java/run/halo/app/controller/base/ControllerExceptionHandler.java @@ -27,7 +27,7 @@ import java.util.Map; * * @author johnniang */ -@RestControllerAdvice +@RestControllerAdvice({"run.halo.app.controller.admin.api", "run.halo.app.controller.content.api"}) @Slf4j public class ControllerExceptionHandler { diff --git a/src/main/java/run/halo/app/controller/core/CommonController.java b/src/main/java/run/halo/app/controller/core/CommonController.java index c56710cbd..06f28a76b 100644 --- a/src/main/java/run/halo/app/controller/core/CommonController.java +++ b/src/main/java/run/halo/app/controller/core/CommonController.java @@ -53,11 +53,11 @@ public class CommonController implements ErrorController { if (StringUtils.startsWithIgnoreCase(throwable.getMessage(), "Could not resolve view with name '")) { // TODO May cause unknown-reason problem // if Ftl was not found then redirect to /404 - return "redirect:/404"; + return contentNotFround(); } } - return statusCode == 500 ? "redirect:/500" : "redirect:/404"; + return statusCode == 500 ? contentInternalError() : contentNotFround(); } /** From 46954ec610a27bf0145cf37bbd42e5246eb14a2d Mon Sep 17 00:00:00 2001 From: johnniang Date: Fri, 7 Jun 2019 10:50:08 +0800 Subject: [PATCH 05/19] Fix #185 Desensitize the old password while logging --- .../app/service/impl/UserServiceImpl.java | 2 +- .../java/run/halo/app/utils/HaloUtils.java | 38 +++++++++++++++++++ .../run/halo/app/utils/HaloUtilsTest.java | 35 +++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/main/java/run/halo/app/service/impl/UserServiceImpl.java b/src/main/java/run/halo/app/service/impl/UserServiceImpl.java index 091cd22eb..96b49b401 100644 --- a/src/main/java/run/halo/app/service/impl/UserServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/UserServiceImpl.java @@ -124,7 +124,7 @@ public class UserServiceImpl extends AbstractCrudService implemen User updatedUser = update(user); // Log it - eventPublisher.publishEvent(new LogEvent(this, updatedUser.getId().toString(), LogType.PASSWORD_UPDATED, oldPassword)); + eventPublisher.publishEvent(new LogEvent(this, updatedUser.getId().toString(), LogType.PASSWORD_UPDATED, HaloUtils.desensitize(oldPassword, 2, 1))); return updatedUser; } diff --git a/src/main/java/run/halo/app/utils/HaloUtils.java b/src/main/java/run/halo/app/utils/HaloUtils.java index 93125eb49..37354f7c6 100755 --- a/src/main/java/run/halo/app/utils/HaloUtils.java +++ b/src/main/java/run/halo/app/utils/HaloUtils.java @@ -21,6 +21,44 @@ import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR; @Slf4j public class HaloUtils { + /** + * Desensitizes the plain text. + * + * @param plainText plain text must not be null + * @param leftSize left size + * @param rightSize right size + * @return desensitization + */ + public static String desensitize(@NonNull String plainText, int leftSize, int rightSize) { + Assert.hasText(plainText, "Plain text must not be blank"); + + if (leftSize < 0) { + leftSize = 0; + } + + if (leftSize > plainText.length()) { + leftSize = plainText.length(); + } + + if (rightSize < 0) { + rightSize = 0; + } + + if (rightSize > plainText.length()) { + rightSize = plainText.length(); + } + + if (plainText.length() < leftSize + rightSize) { + rightSize = plainText.length() - leftSize; + } + + int remainSize = plainText.length() - rightSize - leftSize; + + String left = StringUtils.left(plainText, leftSize); + String right = StringUtils.right(plainText, rightSize); + return StringUtils.rightPad(left, remainSize + leftSize, '*') + right; + } + /** * Changes file separator to url separator. * diff --git a/src/test/java/run/halo/app/utils/HaloUtilsTest.java b/src/test/java/run/halo/app/utils/HaloUtilsTest.java index 7d207211e..302e6d335 100644 --- a/src/test/java/run/halo/app/utils/HaloUtilsTest.java +++ b/src/test/java/run/halo/app/utils/HaloUtilsTest.java @@ -1,5 +1,6 @@ package run.halo.app.utils; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.RandomUtils; import org.junit.Test; @@ -14,6 +15,7 @@ import static org.junit.Assert.assertThat; * @author johnniang * @date 3/29/19 */ +@Slf4j public class HaloUtilsTest { @Test @@ -92,4 +94,37 @@ public class HaloUtilsTest { public void pluralizeLabelExceptionTest() { HaloUtils.pluralize(1, null, null); } + + @Test + public void desensitizeSuccessTest() { + String plainText = "12345678"; + + String desensitization = HaloUtils.desensitize(plainText, 1, 1); + assertThat(desensitization, equalTo("1******8")); + + desensitization = HaloUtils.desensitize(plainText, 2, 3); + assertThat(desensitization, equalTo("12***678")); + + desensitization = HaloUtils.desensitize(plainText, 2, 6); + assertThat(desensitization, equalTo("12345678")); + + desensitization = HaloUtils.desensitize(plainText, 2, 7); + assertThat(desensitization, equalTo("12345678")); + + desensitization = HaloUtils.desensitize(plainText, 0, 0); + assertThat(desensitization, equalTo("********")); + + desensitization = HaloUtils.desensitize(plainText, -1, -1); + assertThat(desensitization, equalTo("********")); + + plainText = " "; + desensitization = HaloUtils.desensitize(plainText, 1, 1); + assertThat(desensitization, equalTo("********")); + } + + @Test(expected = IllegalArgumentException.class) + public void desensitizeFailureTest() { + String plainText = " "; + HaloUtils.desensitize(plainText, 1, 1); + } } From 43bfa89dacb3c1e2d30d945d38427ce25f936cf1 Mon Sep 17 00:00:00 2001 From: johnniang Date: Fri, 7 Jun 2019 15:50:25 +0800 Subject: [PATCH 06/19] Fix test error of HaloUtilsTest --- src/test/java/run/halo/app/utils/HaloUtilsTest.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/test/java/run/halo/app/utils/HaloUtilsTest.java b/src/test/java/run/halo/app/utils/HaloUtilsTest.java index 302e6d335..64fe55bee 100644 --- a/src/test/java/run/halo/app/utils/HaloUtilsTest.java +++ b/src/test/java/run/halo/app/utils/HaloUtilsTest.java @@ -116,10 +116,6 @@ public class HaloUtilsTest { desensitization = HaloUtils.desensitize(plainText, -1, -1); assertThat(desensitization, equalTo("********")); - - plainText = " "; - desensitization = HaloUtils.desensitize(plainText, 1, 1); - assertThat(desensitization, equalTo("********")); } @Test(expected = IllegalArgumentException.class) From c3c0daf7edc74c1e7db75f08928371b30564907b Mon Sep 17 00:00:00 2001 From: ruibaby Date: Fri, 7 Jun 2019 16:59:14 +0800 Subject: [PATCH 07/19] Update anatole theme. --- .../java/run/halo/app/config/WebMvcAutoConfiguration.java | 6 ++++++ .../app/controller/content/ContentArchiveController.java | 6 +++--- .../app/controller/content/ContentCategoryController.java | 6 +++--- .../halo/app/controller/content/ContentIndexController.java | 4 ++-- .../app/controller/content/ContentJournalController.java | 4 ++-- .../app/controller/content/ContentSearchController.java | 4 ++-- .../halo/app/controller/content/ContentSheetController.java | 2 +- .../halo/app/controller/content/ContentTagController.java | 6 +++--- .../resources/templates/themes/anatole/module/comment.ftl | 2 +- src/main/resources/templates/themes/anatole/theme.yaml | 2 +- 10 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/main/java/run/halo/app/config/WebMvcAutoConfiguration.java b/src/main/java/run/halo/app/config/WebMvcAutoConfiguration.java index d46577754..6f26bcd2e 100644 --- a/src/main/java/run/halo/app/config/WebMvcAutoConfiguration.java +++ b/src/main/java/run/halo/app/config/WebMvcAutoConfiguration.java @@ -29,6 +29,7 @@ import run.halo.app.security.resolver.AuthenticationArgumentResolver; import java.io.IOException; import java.util.List; +import java.util.Properties; /** * Mvc configuration. @@ -120,6 +121,11 @@ public class WebMvcAutoConfiguration implements WebMvcConfigurer { configurer.setTemplateLoaderPaths(FILE_PROTOCOL + haloProperties.getWorkDir() + "templates/", "classpath:/templates/"); configurer.setDefaultEncoding("UTF-8"); + Properties properties = new Properties(); + properties.setProperty("auto_import","/common/macro/common_macro.ftl as common"); + + configurer.setFreemarkerSettings(properties); + // Predefine configuration freemarker.template.Configuration configuration = configurer.createConfiguration(); if (haloProperties.isProductionEnv()) { diff --git a/src/main/java/run/halo/app/controller/content/ContentArchiveController.java b/src/main/java/run/halo/app/controller/content/ContentArchiveController.java index 3af73e910..acb363232 100644 --- a/src/main/java/run/halo/app/controller/content/ContentArchiveController.java +++ b/src/main/java/run/halo/app/controller/content/ContentArchiveController.java @@ -66,7 +66,7 @@ public class ContentArchiveController { * Render post archives page. * * @param model model - * @return template path : theme/{theme}/archives.ftl + * @return template path : themes/{theme}/archives.ftl */ @GetMapping public String archives(Model model) { @@ -77,7 +77,7 @@ public class ContentArchiveController { * Render post archives page. * * @param model model - * @return template path : theme/{theme}/archives.ftl + * @return template path : themes/{theme}/archives.ftl */ @GetMapping(value = "page/{page}") public String archives(Model model, @@ -102,7 +102,7 @@ public class ContentArchiveController { * @param url post slug url. * @param cp comment page number * @param model model - * @return template path: theme/{theme}/post.ftl + * @return template path: themes/{theme}/post.ftl */ @GetMapping("{url}") public String post(@PathVariable("url") String url, diff --git a/src/main/java/run/halo/app/controller/content/ContentCategoryController.java b/src/main/java/run/halo/app/controller/content/ContentCategoryController.java index 582da8b7d..a922db198 100644 --- a/src/main/java/run/halo/app/controller/content/ContentCategoryController.java +++ b/src/main/java/run/halo/app/controller/content/ContentCategoryController.java @@ -49,7 +49,7 @@ public class ContentCategoryController { /** * Render category list page * - * @return template path: theme/{theme}/categories.ftl + * @return template path: themes/{theme}/categories.ftl */ @GetMapping public String categories() { @@ -61,7 +61,7 @@ public class ContentCategoryController { * * @param model model * @param slugName slugName - * @return template path: theme/{theme}/category.ftl + * @return template path: themes/{theme}/category.ftl */ @GetMapping(value = "{slugName}") public String categories(Model model, @@ -75,7 +75,7 @@ public class ContentCategoryController { * @param model model * @param slugName slugName * @param page current page number - * @return template path: theme/{theme}/category.ftl + * @return template path: themes/{theme}/category.ftl */ @GetMapping("{slugName}/page/{page}") public String categories(Model model, diff --git a/src/main/java/run/halo/app/controller/content/ContentIndexController.java b/src/main/java/run/halo/app/controller/content/ContentIndexController.java index ba19b65c1..c3ce7449a 100644 --- a/src/main/java/run/halo/app/controller/content/ContentIndexController.java +++ b/src/main/java/run/halo/app/controller/content/ContentIndexController.java @@ -51,7 +51,7 @@ public class ContentIndexController { * Render blog index * * @param model model - * @return template path: /{theme}/post.ftl + * @return template path: themes/{theme}/index.ftl */ @GetMapping public String index(Model model) { @@ -63,7 +63,7 @@ public class ContentIndexController { * * @param model model * @param page current page number - * @return template path: /{theme}/post.ftl + * @return template path: themes/{theme}/index.ftl */ @GetMapping(value = "page/{page}") public String index(Model model, diff --git a/src/main/java/run/halo/app/controller/content/ContentJournalController.java b/src/main/java/run/halo/app/controller/content/ContentJournalController.java index 513cb5999..925542cfc 100644 --- a/src/main/java/run/halo/app/controller/content/ContentJournalController.java +++ b/src/main/java/run/halo/app/controller/content/ContentJournalController.java @@ -53,7 +53,7 @@ public class ContentJournalController { * Render journal page. * * @param model model - * @return template path: theme/{theme}/journal.ftl + * @return template path: themes/{theme}/journals.ftl */ @GetMapping public String journals(Model model) { @@ -66,7 +66,7 @@ public class ContentJournalController { * * @param model model * @param page current page number - * @return template path: theme/{theme}/journal.ftl + * @return template path: themes/{theme}/journals.ftl */ @GetMapping(value = "page/{page}") public String journals(Model model, diff --git a/src/main/java/run/halo/app/controller/content/ContentSearchController.java b/src/main/java/run/halo/app/controller/content/ContentSearchController.java index 70c2c7610..016533211 100644 --- a/src/main/java/run/halo/app/controller/content/ContentSearchController.java +++ b/src/main/java/run/halo/app/controller/content/ContentSearchController.java @@ -48,7 +48,7 @@ public class ContentSearchController { * * @param model model * @param keyword keyword - * @return template path : themes/{theme}/search + * @return template path : themes/{theme}/search.ftl */ @GetMapping public String search(Model model, @@ -61,7 +61,7 @@ public class ContentSearchController { * * @param model model * @param keyword keyword - * @return template path :themes/{theme}/search + * @return template path :themes/{theme}/search.ftl */ @GetMapping(value = "page/{page}") public String search(Model model, diff --git a/src/main/java/run/halo/app/controller/content/ContentSheetController.java b/src/main/java/run/halo/app/controller/content/ContentSheetController.java index 38c7fb358..b7174fca2 100644 --- a/src/main/java/run/halo/app/controller/content/ContentSheetController.java +++ b/src/main/java/run/halo/app/controller/content/ContentSheetController.java @@ -34,7 +34,7 @@ public class ContentSheetController { /** * Render photo page * - * @return template path: themes/{theme}/gallery.ftl + * @return template path: themes/{theme}/photos.ftl */ @GetMapping(value = "/photos") public String photos() { diff --git a/src/main/java/run/halo/app/controller/content/ContentTagController.java b/src/main/java/run/halo/app/controller/content/ContentTagController.java index b506e5a20..40fa985fb 100644 --- a/src/main/java/run/halo/app/controller/content/ContentTagController.java +++ b/src/main/java/run/halo/app/controller/content/ContentTagController.java @@ -53,7 +53,7 @@ public class ContentTagController { /** * All of tags * - * @return template path: themes/{theme}/tags + * @return template path: themes/{theme}/tags.ftl */ @GetMapping public String tags() { @@ -65,7 +65,7 @@ public class ContentTagController { * * @param model model * @param slugName slug name - * @return template path: themes/{theme}/tag + * @return template path: themes/{theme}/tag.ftl */ @GetMapping(value = "{slugName}") public String tags(Model model, @@ -79,7 +79,7 @@ public class ContentTagController { * @param model model * @param slugName slug name * @param page current page - * @return template path: themes/{theme}/tag + * @return template path: themes/{theme}/tag.ftl */ @GetMapping(value = "{slugName}/page/{page}") public String tags(Model model, diff --git a/src/main/resources/templates/themes/anatole/module/comment.ftl b/src/main/resources/templates/themes/anatole/module/comment.ftl index 70cbbde08..6d10c96ac 100644 --- a/src/main/resources/templates/themes/anatole/module/comment.ftl +++ b/src/main/resources/templates/themes/anatole/module/comment.ftl @@ -1,7 +1,7 @@ <#macro comment post,type> <#if !post.disallowComment!false> - + \ No newline at end of file diff --git a/src/main/resources/templates/themes/anatole/theme.yaml b/src/main/resources/templates/themes/anatole/theme.yaml index 53cf5f148..235adea7e 100644 --- a/src/main/resources/templates/themes/anatole/theme.yaml +++ b/src/main/resources/templates/themes/anatole/theme.yaml @@ -7,4 +7,4 @@ description: A other Halo theme logo: https://avatars1.githubusercontent.com/u/1811819?s=460&v=4 website: https://github.com/halo-dev/halo-theme-anatole repo: https://github.com/halo-dev/halo-theme-anatole -version: 1.0 \ No newline at end of file +version: 1.0 From 83522f6a81206234dee82de31eff12326a8ec683 Mon Sep 17 00:00:00 2001 From: ruibaby Date: Sat, 8 Jun 2019 02:14:20 +0800 Subject: [PATCH 08/19] Update anatole theme. --- .../event/freemarker/FreemarkerConfigAwareListener.java | 2 ++ .../resources/templates/common/macro/common_macro.ftl | 9 ++++++--- .../resources/templates/themes/anatole/module/macro.ftl | 7 +++---- .../templates/themes/anatole/module/sidebar.ftl | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/run/halo/app/event/freemarker/FreemarkerConfigAwareListener.java b/src/main/java/run/halo/app/event/freemarker/FreemarkerConfigAwareListener.java index f1b8bbe5d..003ddf25c 100644 --- a/src/main/java/run/halo/app/event/freemarker/FreemarkerConfigAwareListener.java +++ b/src/main/java/run/halo/app/event/freemarker/FreemarkerConfigAwareListener.java @@ -12,6 +12,7 @@ import run.halo.app.event.options.OptionUpdatedEvent; import run.halo.app.event.theme.ThemeActivatedEvent; import run.halo.app.event.user.UserUpdatedEvent; import run.halo.app.handler.theme.config.support.ThemeProperty; +import run.halo.app.model.support.HaloConst; import run.halo.app.service.OptionService; import run.halo.app.service.ThemeService; import run.halo.app.service.ThemeSettingService; @@ -90,6 +91,7 @@ public class FreemarkerConfigAwareListener { private void loadOptionsConfig() throws TemplateModelException { configuration.setSharedVariable("options", optionService.listOptions()); configuration.setSharedVariable("context", optionService.getBlogBaseUrl()); + configuration.setSharedVariable("version", HaloConst.HALO_VERSION); log.debug("Loaded options"); } diff --git a/src/main/resources/templates/common/macro/common_macro.ftl b/src/main/resources/templates/common/macro/common_macro.ftl index 1df74279b..914e91931 100644 --- a/src/main/resources/templates/common/macro/common_macro.ftl +++ b/src/main/resources/templates/common/macro/common_macro.ftl @@ -12,7 +12,9 @@ <#-- favicon --> <#macro favicon> - + <#if options.blog_favicon?? && options.blog_favicon!=''> + + <#-- 站点验证代码 --> @@ -46,11 +48,12 @@ <#macro globalHeader> - <@favicon /> + <@verification /> + <@favicon /> <#macro globalFooter> - <@statistics /> <@footer_info /> + <@statistics /> \ No newline at end of file diff --git a/src/main/resources/templates/themes/anatole/module/macro.ftl b/src/main/resources/templates/themes/anatole/module/macro.ftl index 6d864f8ec..d91175955 100644 --- a/src/main/resources/templates/themes/anatole/module/macro.ftl +++ b/src/main/resources/templates/themes/anatole/module/macro.ftl @@ -1,4 +1,4 @@ -<#include "/common/macro/common_macro.ftl"> +<#import "/common/macro/common_macro.ftl" as common> <#macro head title,keywords,description> @@ -14,8 +14,7 @@ - <@verification /> - <@favicon /> + <@common.globalHeader /> @@ -77,7 +76,7 @@ xhr.send(); -<@statistics /> +<@common.statistics /> diff --git a/src/main/resources/templates/themes/anatole/module/sidebar.ftl b/src/main/resources/templates/themes/anatole/module/sidebar.ftl index fbd5a799d..91362ce1b 100644 --- a/src/main/resources/templates/themes/anatole/module/sidebar.ftl +++ b/src/main/resources/templates/themes/anatole/module/sidebar.ftl @@ -24,7 +24,7 @@ Proudly published with Halo! From 41806bef984de00821db6dfe9ce17798b28f51c6 Mon Sep 17 00:00:00 2001 From: wuzhi1234 Date: Sat, 8 Jun 2019 03:38:04 +0800 Subject: [PATCH 09/19] =?UTF-8?q?=E6=A0=87=E7=AD=BE=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E5=AE=8C=E6=B2=A1=E6=9C=89=E5=8A=A0break=EF=BC=8C=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E6=A0=87=E7=AD=BE=E4=BC=9A=E7=BB=A7=E7=BB=AD=E8=B5=B0?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/run/halo/app/service/impl/PostServiceImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/run/halo/app/service/impl/PostServiceImpl.java b/src/main/java/run/halo/app/service/impl/PostServiceImpl.java index 96666b825..ec3008ff2 100644 --- a/src/main/java/run/halo/app/service/impl/PostServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/PostServiceImpl.java @@ -330,6 +330,7 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe tag = tagService.create(tag); } tagIds.add(tag.getId()); + break; case "categories": Category category = categoryService.getByName(ele); if (null == category) { From 12483118af324cf85ec5520f0c04814f5c5942bd Mon Sep 17 00:00:00 2001 From: ruibaby Date: Sat, 8 Jun 2019 11:15:39 +0800 Subject: [PATCH 10/19] Support custom head #189 --- .../java/run/halo/app/model/properties/OtherProperties.java | 4 +++- src/main/resources/templates/common/macro/common_macro.ftl | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/run/halo/app/model/properties/OtherProperties.java b/src/main/java/run/halo/app/model/properties/OtherProperties.java index e2be5d420..e3b370925 100644 --- a/src/main/java/run/halo/app/model/properties/OtherProperties.java +++ b/src/main/java/run/halo/app/model/properties/OtherProperties.java @@ -12,7 +12,9 @@ public enum OtherProperties implements PropertyEnum { API_ACCESS_KEY("api_access_key", String.class, ""), - STATISTICS_CODE("statistics_code", String.class, ""), + CUSTOM_HEAD("blog_custom_head",String.class,""), + + STATISTICS_CODE("blog_statistics_code", String.class, ""), /** * 是否禁止爬虫 diff --git a/src/main/resources/templates/common/macro/common_macro.ftl b/src/main/resources/templates/common/macro/common_macro.ftl index 914e91931..e78fcae64 100644 --- a/src/main/resources/templates/common/macro/common_macro.ftl +++ b/src/main/resources/templates/common/macro/common_macro.ftl @@ -10,6 +10,10 @@ ${options.blog_footer_info!} +<#macro custom_head> + ${options.blog_custom_head!} + + <#-- favicon --> <#macro favicon> <#if options.blog_favicon?? && options.blog_favicon!=''> @@ -49,6 +53,7 @@ <#macro globalHeader> + <@custom_head /> <@verification /> <@favicon /> From 8176451e5a09b7a674986287aacd506a90498eb5 Mon Sep 17 00:00:00 2001 From: ruibaby Date: Sat, 8 Jun 2019 19:55:59 +0800 Subject: [PATCH 11/19] Fixed Controller model. --- .../app/controller/content/ContentCategoryController.java | 5 +++-- .../halo/app/controller/content/ContentSheetController.java | 1 - .../halo/app/controller/content/ContentTagController.java | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/run/halo/app/controller/content/ContentCategoryController.java b/src/main/java/run/halo/app/controller/content/ContentCategoryController.java index a922db198..da9b57085 100644 --- a/src/main/java/run/halo/app/controller/content/ContentCategoryController.java +++ b/src/main/java/run/halo/app/controller/content/ContentCategoryController.java @@ -52,7 +52,8 @@ public class ContentCategoryController { * @return template path: themes/{theme}/categories.ftl */ @GetMapping - public String categories() { + public String categories(Model model) { + model.addAttribute("is_categories", true); return themeService.render("categories"); } @@ -89,7 +90,7 @@ public class ContentCategoryController { Page posts = postCategoryService.pagePostBy(category.getId(), pageable); final int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3); - model.addAttribute("is_categories", true); + model.addAttribute("is_category", true); model.addAttribute("posts", posts); model.addAttribute("rainbow", rainbow); model.addAttribute("category", category); diff --git a/src/main/java/run/halo/app/controller/content/ContentSheetController.java b/src/main/java/run/halo/app/controller/content/ContentSheetController.java index b7174fca2..7a2e4693d 100644 --- a/src/main/java/run/halo/app/controller/content/ContentSheetController.java +++ b/src/main/java/run/halo/app/controller/content/ContentSheetController.java @@ -60,7 +60,6 @@ public class ContentSheetController { */ @GetMapping(value = "/s/{url}") public String sheet(@PathVariable(value = "url") String url, - @RequestParam(value = "cp", defaultValue = "1") Integer cp, Model model) { Sheet sheet = sheetService.getBy(PostStatus.PUBLISHED, url); diff --git a/src/main/java/run/halo/app/controller/content/ContentTagController.java b/src/main/java/run/halo/app/controller/content/ContentTagController.java index 40fa985fb..f68b5eef5 100644 --- a/src/main/java/run/halo/app/controller/content/ContentTagController.java +++ b/src/main/java/run/halo/app/controller/content/ContentTagController.java @@ -56,7 +56,8 @@ public class ContentTagController { * @return template path: themes/{theme}/tags.ftl */ @GetMapping - public String tags() { + public String tags(Model model) { + model.addAttribute("is_tags", true); return themeService.render("tags"); } @@ -93,7 +94,7 @@ public class ContentTagController { Page posts = postService.convertToListVo(postPage); final int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3); - model.addAttribute("is_tags", true); + model.addAttribute("is_tag", true); model.addAttribute("posts", posts); model.addAttribute("rainbow", rainbow); model.addAttribute("tag", tag); From cc5a3e87e0aca6241755c9488323fe2e8f065fc7 Mon Sep 17 00:00:00 2001 From: wuzhi1234 Date: Sat, 8 Jun 2019 23:14:46 +0800 Subject: [PATCH 12/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=BC=E5=85=A5markd?= =?UTF-8?q?own=E6=96=87=E4=BB=B6=E6=97=B6=EF=BC=8Cslug=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E6=97=B6=E5=88=9D=E5=A7=8B=E5=8C=96=E8=B5=8B=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/service/impl/PostServiceImpl.java | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/main/java/run/halo/app/service/impl/PostServiceImpl.java b/src/main/java/run/halo/app/service/impl/PostServiceImpl.java index ec3008ff2..2862bbfd0 100644 --- a/src/main/java/run/halo/app/service/impl/PostServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/PostServiceImpl.java @@ -19,7 +19,11 @@ import run.halo.app.event.logger.LogEvent; import run.halo.app.event.post.PostVisitEvent; import run.halo.app.model.dto.CategoryDTO; import run.halo.app.model.dto.TagDTO; -import run.halo.app.model.entity.*; +import run.halo.app.model.entity.Category; +import run.halo.app.model.entity.Post; +import run.halo.app.model.entity.PostCategory; +import run.halo.app.model.entity.PostTag; +import run.halo.app.model.entity.Tag; import run.halo.app.model.enums.LogType; import run.halo.app.model.enums.PostStatus; import run.halo.app.model.params.PostQuery; @@ -28,8 +32,15 @@ import run.halo.app.model.vo.ArchiveYearVO; import run.halo.app.model.vo.PostDetailVO; import run.halo.app.model.vo.PostListVO; import run.halo.app.repository.PostRepository; -import run.halo.app.service.*; +import run.halo.app.service.CategoryService; +import run.halo.app.service.OptionService; +import run.halo.app.service.PostCategoryService; +import run.halo.app.service.PostCommentService; +import run.halo.app.service.PostService; +import run.halo.app.service.PostTagService; +import run.halo.app.service.TagService; import run.halo.app.utils.DateUtils; +import run.halo.app.utils.HaloUtils; import run.halo.app.utils.MarkdownUtils; import run.halo.app.utils.ServiceUtils; import run.halo.app.utils.SlugUtils; @@ -37,7 +48,17 @@ import run.halo.app.utils.SlugUtils; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; import javax.persistence.criteria.Subquery; -import java.util.*; +import java.util.Calendar; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -327,6 +348,8 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe tag = new Tag(); tag.setName(ele); tag.setSlugName(SlugUtils.slugify(ele)); + String slugName = SlugUtils.slugify(ele); + tag.setSlugName(HaloUtils.initializeUrlIfBlank(slugName)); tag = tagService.create(tag); } tagIds.add(tag.getId()); From 852951073026c2d5169222ec3833bff2956b09ef Mon Sep 17 00:00:00 2001 From: ruibaby Date: Sat, 8 Jun 2019 23:27:16 +0800 Subject: [PATCH 13/19] Fixed import markdown cased bugs. --- .../app/service/impl/PostServiceImpl.java | 36 ++++--------------- 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/src/main/java/run/halo/app/service/impl/PostServiceImpl.java b/src/main/java/run/halo/app/service/impl/PostServiceImpl.java index 2862bbfd0..44014d0b2 100644 --- a/src/main/java/run/halo/app/service/impl/PostServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/PostServiceImpl.java @@ -19,11 +19,7 @@ import run.halo.app.event.logger.LogEvent; import run.halo.app.event.post.PostVisitEvent; import run.halo.app.model.dto.CategoryDTO; import run.halo.app.model.dto.TagDTO; -import run.halo.app.model.entity.Category; -import run.halo.app.model.entity.Post; -import run.halo.app.model.entity.PostCategory; -import run.halo.app.model.entity.PostTag; -import run.halo.app.model.entity.Tag; +import run.halo.app.model.entity.*; import run.halo.app.model.enums.LogType; import run.halo.app.model.enums.PostStatus; import run.halo.app.model.params.PostQuery; @@ -32,33 +28,13 @@ import run.halo.app.model.vo.ArchiveYearVO; import run.halo.app.model.vo.PostDetailVO; import run.halo.app.model.vo.PostListVO; import run.halo.app.repository.PostRepository; -import run.halo.app.service.CategoryService; -import run.halo.app.service.OptionService; -import run.halo.app.service.PostCategoryService; -import run.halo.app.service.PostCommentService; -import run.halo.app.service.PostService; -import run.halo.app.service.PostTagService; -import run.halo.app.service.TagService; -import run.halo.app.utils.DateUtils; -import run.halo.app.utils.HaloUtils; -import run.halo.app.utils.MarkdownUtils; -import run.halo.app.utils.ServiceUtils; -import run.halo.app.utils.SlugUtils; +import run.halo.app.service.*; +import run.halo.app.utils.*; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; import javax.persistence.criteria.Subquery; -import java.util.Calendar; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -347,7 +323,6 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe if (null == tag) { tag = new Tag(); tag.setName(ele); - tag.setSlugName(SlugUtils.slugify(ele)); String slugName = SlugUtils.slugify(ele); tag.setSlugName(HaloUtils.initializeUrlIfBlank(slugName)); tag = tagService.create(tag); @@ -359,7 +334,8 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe if (null == category) { category = new Category(); category.setName(ele); - category.setSlugName(SlugUtils.slugify(ele)); + String slugName = SlugUtils.slugify(ele); + category.setSlugName(HaloUtils.initializeUrlIfBlank(slugName)); category.setDescription(ele); category = categoryService.create(category); } From 19f88b2b092a110c5c91cf3a1b1168d42f12721a Mon Sep 17 00:00:00 2001 From: Tao Wei Date: Sun, 9 Jun 2019 10:46:58 +0800 Subject: [PATCH 14/19] Add email address validation --- src/main/java/run/halo/app/model/params/MailParam.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/run/halo/app/model/params/MailParam.java b/src/main/java/run/halo/app/model/params/MailParam.java index d106a8ad1..70dae944e 100644 --- a/src/main/java/run/halo/app/model/params/MailParam.java +++ b/src/main/java/run/halo/app/model/params/MailParam.java @@ -2,6 +2,7 @@ package run.halo.app.model.params; import lombok.Data; +import javax.validation.constraints.Email; import javax.validation.constraints.NotBlank; /** @@ -14,6 +15,7 @@ import javax.validation.constraints.NotBlank; public class MailParam { @NotBlank(message = "收件人不能为空") + @Email(message = "邮箱格式错误") private String to; @NotBlank(message = "主题不能为空") From 006edf13d77f1e616474b357e86fb06dcf08e7c2 Mon Sep 17 00:00:00 2001 From: ruibaby Date: Sun, 9 Jun 2019 12:08:02 +0800 Subject: [PATCH 15/19] Complete content api. --- .../content/ContentCategoryController.java | 14 ++-- .../content/ContentSearchController.java | 8 +-- .../content/ContentSheetController.java | 1 - .../content/ContentTagController.java | 3 +- .../content/api/CategoryController.java | 66 +++++++++++++++++++ .../content/api/LinkController.java | 13 ++++ .../content/api/MenuController.java | 8 +++ .../content/api/PostController.java | 8 +++ 8 files changed, 109 insertions(+), 12 deletions(-) create mode 100644 src/main/java/run/halo/app/controller/content/api/CategoryController.java diff --git a/src/main/java/run/halo/app/controller/content/ContentCategoryController.java b/src/main/java/run/halo/app/controller/content/ContentCategoryController.java index da9b57085..e85fb98be 100644 --- a/src/main/java/run/halo/app/controller/content/ContentCategoryController.java +++ b/src/main/java/run/halo/app/controller/content/ContentCategoryController.java @@ -13,10 +13,8 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import run.halo.app.model.entity.Category; import run.halo.app.model.entity.Post; -import run.halo.app.service.CategoryService; -import run.halo.app.service.OptionService; -import run.halo.app.service.PostCategoryService; -import run.halo.app.service.ThemeService; +import run.halo.app.model.vo.PostListVO; +import run.halo.app.service.*; import static org.springframework.data.domain.Sort.Direction.DESC; @@ -34,15 +32,18 @@ public class ContentCategoryController { private final PostCategoryService postCategoryService; + private final PostService postService; + private final OptionService optionService; public ContentCategoryController(CategoryService categoryService, ThemeService themeService, PostCategoryService postCategoryService, - OptionService optionService) { + PostService postService, OptionService optionService) { this.categoryService = categoryService; this.themeService = themeService; this.postCategoryService = postCategoryService; + this.postService = postService; this.optionService = optionService; } @@ -87,7 +88,8 @@ public class ContentCategoryController { final Category category = categoryService.getBySlugName(slugName); final Pageable pageable = PageRequest.of(page - 1, optionService.getPostPageSize(), sort); - Page posts = postCategoryService.pagePostBy(category.getId(), pageable); + Page postPage = postCategoryService.pagePostBy(category.getId(), pageable); + Page posts = postService.convertToListVo(postPage); final int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3); model.addAttribute("is_category", true); diff --git a/src/main/java/run/halo/app/controller/content/ContentSearchController.java b/src/main/java/run/halo/app/controller/content/ContentSearchController.java index 016533211..93bf732b3 100644 --- a/src/main/java/run/halo/app/controller/content/ContentSearchController.java +++ b/src/main/java/run/halo/app/controller/content/ContentSearchController.java @@ -69,14 +69,14 @@ public class ContentSearchController { @PathVariable(value = "page") Integer page, @SortDefault(sort = "createTime", direction = DESC) Sort sort) { final Pageable pageable = PageRequest.of(page - 1, optionService.getPostPageSize(), sort); - final Page posts = postService.pageBy(keyword, pageable); + final Page postPage = postService.pageBy(keyword, pageable); - final Page postPage = postService.convertToListVo(posts); + final Page posts = postService.convertToListVo(postPage); - final int[] rainbow = PageUtil.rainbow(page, postPage.getTotalPages(), 3); + final int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3); model.addAttribute("is_search", true); model.addAttribute("keyword", keyword); - model.addAttribute("posts", postPage); + model.addAttribute("posts", posts); model.addAttribute("rainbow", rainbow); return themeService.render("search"); } diff --git a/src/main/java/run/halo/app/controller/content/ContentSheetController.java b/src/main/java/run/halo/app/controller/content/ContentSheetController.java index 7a2e4693d..2b1ae4c61 100644 --- a/src/main/java/run/halo/app/controller/content/ContentSheetController.java +++ b/src/main/java/run/halo/app/controller/content/ContentSheetController.java @@ -4,7 +4,6 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestParam; import run.halo.app.model.entity.Sheet; import run.halo.app.model.enums.PostStatus; import run.halo.app.model.support.HaloConst; diff --git a/src/main/java/run/halo/app/controller/content/ContentTagController.java b/src/main/java/run/halo/app/controller/content/ContentTagController.java index f68b5eef5..eae71c455 100644 --- a/src/main/java/run/halo/app/controller/content/ContentTagController.java +++ b/src/main/java/run/halo/app/controller/content/ContentTagController.java @@ -87,7 +87,8 @@ public class ContentTagController { @PathVariable("slugName") String slugName, @PathVariable("page") Integer page, @SortDefault(sort = "createTime", direction = DESC) Sort sort) { - Tag tag = tagService.getBySlugNameOfNonNull(slugName); + // Get tag by slug name + final Tag tag = tagService.getBySlugNameOfNonNull(slugName); final Pageable pageable = PageRequest.of(page - 1, optionService.getPostPageSize(), sort); Page postPage = postTagService.pagePostsBy(tag.getId(), pageable); diff --git a/src/main/java/run/halo/app/controller/content/api/CategoryController.java b/src/main/java/run/halo/app/controller/content/api/CategoryController.java new file mode 100644 index 000000000..1be79ec43 --- /dev/null +++ b/src/main/java/run/halo/app/controller/content/api/CategoryController.java @@ -0,0 +1,66 @@ +package run.halo.app.controller.content.api; + +import io.swagger.annotations.ApiOperation; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.web.PageableDefault; +import org.springframework.data.web.SortDefault; +import org.springframework.web.bind.annotation.*; +import run.halo.app.model.dto.CategoryDTO; +import run.halo.app.model.dto.post.BasePostSimpleDTO; +import run.halo.app.model.entity.Category; +import run.halo.app.model.entity.Post; +import run.halo.app.service.CategoryService; +import run.halo.app.service.PostCategoryService; +import run.halo.app.service.PostService; + +import java.util.List; + +import static org.springframework.data.domain.Sort.Direction.DESC; + +/** + * Category portal controller. + * + * @author ryanwang + * @date 6/9/19 + */ +@RestController("ApiContentCategoryController") +@RequestMapping("/api/content/categories") +public class CategoryController { + + private final CategoryService categoryService; + + private final PostCategoryService postCategoryService; + + private final PostService postService; + + public CategoryController(CategoryService categoryService, + PostCategoryService postCategoryService, + PostService postService) { + this.categoryService = categoryService; + this.postCategoryService = postCategoryService; + this.postService = postService; + } + + @GetMapping + @ApiOperation("Lists categories") + public List listCategories(@SortDefault(sort = "updateTime", direction = DESC) Sort sort, + @RequestParam(name = "more", required = false, defaultValue = "false") Boolean more) { + if (more) { + return postCategoryService.listCategoryWithPostCountDto(sort); + } + return categoryService.convertTo(categoryService.listAll(sort)); + } + + @GetMapping("{slugName}/posts") + @ApiOperation("Lists posts by category slug name") + public Page listPostsBy(@PathVariable("slugName") String slugName, + @PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable) { + // Get category by slug name + Category category = categoryService.getBySlugName(slugName); + + Page postPage = postCategoryService.pagePostBy(category.getId(), pageable); + return postService.convertToSimple(postPage); + } +} diff --git a/src/main/java/run/halo/app/controller/content/api/LinkController.java b/src/main/java/run/halo/app/controller/content/api/LinkController.java index dea1585b6..20b51b35f 100644 --- a/src/main/java/run/halo/app/controller/content/api/LinkController.java +++ b/src/main/java/run/halo/app/controller/content/api/LinkController.java @@ -1,18 +1,24 @@ package run.halo.app.controller.content.api; +import io.swagger.annotations.ApiOperation; import org.springframework.data.domain.Sort; +import org.springframework.data.web.SortDefault; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import run.halo.app.model.dto.LinkDTO; import run.halo.app.model.vo.LinkTeamVO; import run.halo.app.service.LinkService; import java.util.List; +import static org.springframework.data.domain.Sort.Direction.DESC; + /** * Portal link controller. * * @author johnniang + * @author ryanwang * @date 4/3/19 */ @RestController("ApiContentLinkController") @@ -25,7 +31,14 @@ public class LinkController { this.linkService = linkService; } + @GetMapping + @ApiOperation("List all links") + public List listLinks(@SortDefault(sort = "createTime", direction = DESC) Sort sort) { + return linkService.listDtos(sort); + } + @GetMapping("team_view") + @ApiOperation("List all links with team view") public List listTeamVos(Sort sort) { return linkService.listTeamVos(sort); } diff --git a/src/main/java/run/halo/app/controller/content/api/MenuController.java b/src/main/java/run/halo/app/controller/content/api/MenuController.java index 45cc954f6..866cb5894 100644 --- a/src/main/java/run/halo/app/controller/content/api/MenuController.java +++ b/src/main/java/run/halo/app/controller/content/api/MenuController.java @@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import run.halo.app.model.dto.MenuDTO; +import run.halo.app.model.vo.MenuVO; import run.halo.app.service.MenuService; import java.util.List; @@ -17,6 +18,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC; * Portal menu controller. * * @author johnniang + * @author ryanwang * @date 4/3/19 */ @RestController("ApiContentMenuController") @@ -34,4 +36,10 @@ public class MenuController { public List listAll(@SortDefault(sort = "priority", direction = DESC) Sort sort) { return menuService.listDtos(sort); } + + @GetMapping(value = "tree_view") + @ApiOperation("Lists menus with tree view") + public List listMenusTree(@SortDefault(sort = "createTime", direction = DESC) Sort sort) { + return menuService.listAsTree(sort); + } } diff --git a/src/main/java/run/halo/app/controller/content/api/PostController.java b/src/main/java/run/halo/app/controller/content/api/PostController.java index ae8fbff0f..6ec1514c5 100644 --- a/src/main/java/run/halo/app/controller/content/api/PostController.java +++ b/src/main/java/run/halo/app/controller/content/api/PostController.java @@ -59,6 +59,14 @@ public class PostController { return postService.convertToSimple(postPage); } + @PostMapping(value = "search") + @ApiOperation("Lists posts by keyword") + public Page pageBy(@RequestParam(value = "keyword") String keyword, + @PageableDefault(sort = "createTime", direction = DESC) Pageable pageable) { + Page postPage = postService.pageBy(keyword, pageable); + return postService.convertToSimple(postPage); + } + @GetMapping("{postId:\\d+}") @ApiOperation("Gets a post") public BasePostDetailDTO getBy(@PathVariable("postId") Integer postId, From 186611d5290020e2747c3c7d5544e4e09234ccf1 Mon Sep 17 00:00:00 2001 From: ruibaby Date: Mon, 10 Jun 2019 19:41:31 +0800 Subject: [PATCH 16/19] Support mode for getEnvironment api. --- .../java/run/halo/app/model/dto/EnvironmentDTO.java | 2 ++ .../run/halo/app/service/impl/AdminServiceImpl.java | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/run/halo/app/model/dto/EnvironmentDTO.java b/src/main/java/run/halo/app/model/dto/EnvironmentDTO.java index 644da2bee..77063b26f 100644 --- a/src/main/java/run/halo/app/model/dto/EnvironmentDTO.java +++ b/src/main/java/run/halo/app/model/dto/EnvironmentDTO.java @@ -16,4 +16,6 @@ public class EnvironmentDTO { private long startTime; private String version; + + private String mode; } diff --git a/src/main/java/run/halo/app/service/impl/AdminServiceImpl.java b/src/main/java/run/halo/app/service/impl/AdminServiceImpl.java index 9a6e2ca32..5899ee4f1 100644 --- a/src/main/java/run/halo/app/service/impl/AdminServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/AdminServiceImpl.java @@ -2,6 +2,7 @@ package run.halo.app.service.impl; import cn.hutool.core.lang.Validator; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationEventPublisher; import org.springframework.lang.NonNull; @@ -63,6 +64,8 @@ public class AdminServiceImpl implements AdminService { private final String driverClassName; + private final String mode; + public AdminServiceImpl(PostService postService, SheetService sheetService, AttachmentService attachmentService, @@ -74,7 +77,8 @@ public class AdminServiceImpl implements AdminService { LinkService linkService, StringCacheStore cacheStore, ApplicationEventPublisher eventPublisher, - @Value("${spring.datasource.driver-class-name}") String driverClassName) { + @Value("${spring.datasource.driver-class-name}") String driverClassName, + @Value("${spring.profiles.active}") String mode) { this.postService = postService; this.sheetService = sheetService; this.attachmentService = attachmentService; @@ -87,6 +91,7 @@ public class AdminServiceImpl implements AdminService { this.cacheStore = cacheStore; this.eventPublisher = eventPublisher; this.driverClassName = driverClassName; + this.mode = mode; } @Override @@ -189,6 +194,12 @@ public class AdminServiceImpl implements AdminService { environmentDTO.setVersion(HaloConst.HALO_VERSION); + if (StringUtils.isNotEmpty(mode)) { + environmentDTO.setMode(StringUtils.equals("dev", mode) ? "development" : "production"); + } else { + environmentDTO.setMode("test"); + } + return environmentDTO; } From 5b2591b5c33d1c2d93bc5c2116ac08470d38d0e7 Mon Sep 17 00:00:00 2001 From: johnniang Date: Mon, 10 Jun 2019 20:02:58 +0800 Subject: [PATCH 17/19] Refactor runtime mode conversion --- .../halo/app/model/dto/EnvironmentDTO.java | 3 +- .../java/run/halo/app/model/enums/Mode.java | 47 +++++++++++++++++++ .../run/halo/app/model/support/HaloConst.java | 2 +- .../run/halo/app/service/CategoryService.java | 1 + .../app/service/impl/AdminServiceImpl.java | 14 ++---- .../app/service/impl/BackupServiceImpl.java | 3 +- .../app/service/impl/PostServiceImpl.java | 1 + 7 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 src/main/java/run/halo/app/model/enums/Mode.java diff --git a/src/main/java/run/halo/app/model/dto/EnvironmentDTO.java b/src/main/java/run/halo/app/model/dto/EnvironmentDTO.java index 77063b26f..b2fddafa4 100644 --- a/src/main/java/run/halo/app/model/dto/EnvironmentDTO.java +++ b/src/main/java/run/halo/app/model/dto/EnvironmentDTO.java @@ -1,6 +1,7 @@ package run.halo.app.model.dto; import lombok.Data; +import run.halo.app.model.enums.Mode; /** * Theme controller. @@ -17,5 +18,5 @@ public class EnvironmentDTO { private String version; - private String mode; + private Mode mode; } diff --git a/src/main/java/run/halo/app/model/enums/Mode.java b/src/main/java/run/halo/app/model/enums/Mode.java new file mode 100644 index 000000000..1dd4a7374 --- /dev/null +++ b/src/main/java/run/halo/app/model/enums/Mode.java @@ -0,0 +1,47 @@ +package run.halo.app.model.enums; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import org.apache.commons.lang3.StringUtils; +import org.springframework.lang.Nullable; + +/** + * Halo runtime mode. + * + * @author johnniang + * @date 19-6-10 + */ +public enum Mode { + PRODUCTION, + DEVELOPMENT, + TEST; + + @JsonValue + String getValue() { + return this.name().toLowerCase(); + } + + /** + * Get mode from value. + * + * @param value mode value + * @return runtime mode or null if the value is mismatch + */ + @Nullable + @JsonCreator + public static Mode valueFrom(@Nullable String value) { + if (StringUtils.isBlank(value) || value.equalsIgnoreCase("prod")) { + return Mode.PRODUCTION; + } + + if (value.equalsIgnoreCase("dev")) { + return Mode.DEVELOPMENT; + } + + if (value.equalsIgnoreCase("test")) { + return Mode.TEST; + } + + return null; + } +} diff --git a/src/main/java/run/halo/app/model/support/HaloConst.java b/src/main/java/run/halo/app/model/support/HaloConst.java index 49be00fa6..6455ea3aa 100644 --- a/src/main/java/run/halo/app/model/support/HaloConst.java +++ b/src/main/java/run/halo/app/model/support/HaloConst.java @@ -23,7 +23,7 @@ public class HaloConst { public final static String DEFAULT_THEME_ID = "caicai_anatole"; /** - * version constant + * Version constant. (Available in production environment) */ public static final String HALO_VERSION; diff --git a/src/main/java/run/halo/app/service/CategoryService.java b/src/main/java/run/halo/app/service/CategoryService.java index e73e74d2e..7de4e678f 100755 --- a/src/main/java/run/halo/app/service/CategoryService.java +++ b/src/main/java/run/halo/app/service/CategoryService.java @@ -42,6 +42,7 @@ public interface CategoryService extends CrudService { * @param name name * @return Category */ + @Nullable Category getByName(@NonNull String name); /** diff --git a/src/main/java/run/halo/app/service/impl/AdminServiceImpl.java b/src/main/java/run/halo/app/service/impl/AdminServiceImpl.java index 5899ee4f1..51b989f9b 100644 --- a/src/main/java/run/halo/app/service/impl/AdminServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/AdminServiceImpl.java @@ -15,6 +15,7 @@ import run.halo.app.model.dto.EnvironmentDTO; import run.halo.app.model.dto.StatisticDTO; import run.halo.app.model.entity.User; import run.halo.app.model.enums.CommentStatus; +import run.halo.app.model.enums.Mode; import run.halo.app.model.enums.PostStatus; import run.halo.app.model.params.LoginParam; import run.halo.app.model.support.HaloConst; @@ -78,7 +79,7 @@ public class AdminServiceImpl implements AdminService { StringCacheStore cacheStore, ApplicationEventPublisher eventPublisher, @Value("${spring.datasource.driver-class-name}") String driverClassName, - @Value("${spring.profiles.active}") String mode) { + @Value("${spring.profiles.active:prod}") String mode) { this.postService = postService; this.sheetService = sheetService; this.attachmentService = attachmentService; @@ -194,11 +195,7 @@ public class AdminServiceImpl implements AdminService { environmentDTO.setVersion(HaloConst.HALO_VERSION); - if (StringUtils.isNotEmpty(mode)) { - environmentDTO.setMode(StringUtils.equals("dev", mode) ? "development" : "production"); - } else { - environmentDTO.setMode("test"); - } + environmentDTO.setMode(Mode.valueFrom(this.mode)); return environmentDTO; } @@ -214,9 +211,8 @@ public class AdminServiceImpl implements AdminService { User user = userService.getById(userId); // Remove all token - cacheStore.getAny(SecurityUtils.buildAccessTokenKey(user), String.class).ifPresent(accessToken -> { - cacheStore.delete(SecurityUtils.buildTokenAccessKey(accessToken)); - }); + cacheStore.getAny(SecurityUtils.buildAccessTokenKey(user), String.class) + .ifPresent(accessToken -> cacheStore.delete(SecurityUtils.buildTokenAccessKey(accessToken))); cacheStore.delete(SecurityUtils.buildTokenRefreshKey(refreshToken)); cacheStore.delete(SecurityUtils.buildAccessTokenKey(user)); cacheStore.delete(SecurityUtils.buildRefreshTokenKey(user)); diff --git a/src/main/java/run/halo/app/service/impl/BackupServiceImpl.java b/src/main/java/run/halo/app/service/impl/BackupServiceImpl.java index 88df39af0..483b6308a 100644 --- a/src/main/java/run/halo/app/service/impl/BackupServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/BackupServiceImpl.java @@ -8,6 +8,7 @@ import run.halo.app.service.BackupService; import run.halo.app.service.PostService; import java.io.IOException; +import java.nio.charset.StandardCharsets; /** * Backup service implementation. @@ -28,7 +29,7 @@ public class BackupServiceImpl implements BackupService { public BasePostDetailDTO importMarkdowns(MultipartFile file) throws IOException { // Read markdown content. - String markdown = IoUtil.read(file.getInputStream(), "UTF-8"); + String markdown = IoUtil.read(file.getInputStream(), StandardCharsets.UTF_8); // TODO sheet import diff --git a/src/main/java/run/halo/app/service/impl/PostServiceImpl.java b/src/main/java/run/halo/app/service/impl/PostServiceImpl.java index 44014d0b2..d1130ea96 100644 --- a/src/main/java/run/halo/app/service/impl/PostServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/PostServiceImpl.java @@ -340,6 +340,7 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe category = categoryService.create(category); } categoryIds.add(category.getId()); + break; default: break; } From dd30b83ee93ad30ceb93c5098d46d2895e15a9c7 Mon Sep 17 00:00:00 2001 From: johnniang Date: Mon, 10 Jun 2019 20:18:58 +0800 Subject: [PATCH 18/19] Change halo running command with nohup --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f3926da5a..b6e860a3b 100755 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ wget https://github.com/halo-dev/halo/releases/download/v1.0.1/halo-1.0.1.jar -O ### 启动 Halo ```bash -nohup java -jar halo-latest.jar & +nohup java -jar halo-latest.jar >/dev/null 2>&1& ``` 详细文档请移步: From 417fb5d354a45ee1b2000c7c40f4bb87b8588f47 Mon Sep 17 00:00:00 2001 From: johnniang Date: Tue, 11 Jun 2019 01:22:00 +0800 Subject: [PATCH 19/19] Update lombok gradle plugin --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index e868015fe..708910710 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id 'org.springframework.boot' version '2.1.3.RELEASE' - id "io.freefair.lombok" version "3.1.4" + id "io.freefair.lombok" version "3.6.6" id 'java' id 'war' }