From 463b786671553620298f29baca58f3a76d3e7a00 Mon Sep 17 00:00:00 2001 From: ruibaby Date: Mon, 28 Oct 2019 20:36:42 +0800 Subject: [PATCH] Update robots router. --- .../app/controller/content/ContentFeedController.java | 8 +++++++- src/main/resources/templates/common/web/robots.ftl | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/run/halo/app/controller/content/ContentFeedController.java b/src/main/java/run/halo/app/controller/content/ContentFeedController.java index 13b790130..8ded9a21c 100644 --- a/src/main/java/run/halo/app/controller/content/ContentFeedController.java +++ b/src/main/java/run/halo/app/controller/content/ContentFeedController.java @@ -16,6 +16,7 @@ import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; +import run.halo.app.config.properties.HaloProperties; import run.halo.app.model.entity.Post; import run.halo.app.model.enums.PostStatus; import run.halo.app.model.vo.PostListVO; @@ -43,13 +44,16 @@ public class ContentFeedController { private final PostService postService; private final OptionService optionService; private final FreeMarkerConfigurer freeMarker; + private final HaloProperties haloProperties; public ContentFeedController(PostService postService, OptionService optionService, - FreeMarkerConfigurer freeMarker) { + FreeMarkerConfigurer freeMarker, + HaloProperties haloProperties) { this.postService = postService; this.optionService = optionService; this.freeMarker = freeMarker; + this.haloProperties = haloProperties; } /** @@ -125,6 +129,8 @@ public class ContentFeedController { @GetMapping(value = "robots.txt", produces = MediaType.TEXT_PLAIN_VALUE) @ResponseBody public String robots(Model model) throws IOException, TemplateException { + String adminPath = haloProperties.getAdminPath(); + model.addAttribute("adminPath", adminPath); Template template = freeMarker.getConfiguration().getTemplate("common/web/robots.ftl"); return FreeMarkerTemplateUtils.processTemplateIntoString(template, model); } diff --git a/src/main/resources/templates/common/web/robots.ftl b/src/main/resources/templates/common/web/robots.ftl index 2dca6ba50..1ab729f55 100644 --- a/src/main/resources/templates/common/web/robots.ftl +++ b/src/main/resources/templates/common/web/robots.ftl @@ -3,7 +3,7 @@ User-agent: / Disallow: / <#else> User-agent: * -Disallow: /admin/ +Disallow: ${adminPath!}/ Sitemap: ${context!}/sitemap.xml Sitemap: ${context!}/sitemap.html \ No newline at end of file