From 381341a18b501f2609ad8765b8790cb6fe2c7c1f Mon Sep 17 00:00:00 2001 From: ruibaby Date: Mon, 18 Nov 2019 11:42:25 +0800 Subject: [PATCH] feat: hide admin path in robot.txt --- .../app/controller/content/ContentFeedController.java | 8 +------- src/main/resources/templates/common/web/robots.ftl | 3 +-- 2 files changed, 2 insertions(+), 9 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 8ded9a21c..13b790130 100644 --- a/src/main/java/run/halo/app/controller/content/ContentFeedController.java +++ b/src/main/java/run/halo/app/controller/content/ContentFeedController.java @@ -16,7 +16,6 @@ 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; @@ -44,16 +43,13 @@ 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, - HaloProperties haloProperties) { + FreeMarkerConfigurer freeMarker) { this.postService = postService; this.optionService = optionService; this.freeMarker = freeMarker; - this.haloProperties = haloProperties; } /** @@ -129,8 +125,6 @@ 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 1ab729f55..0c3014a64 100644 --- a/src/main/resources/templates/common/web/robots.ftl +++ b/src/main/resources/templates/common/web/robots.ftl @@ -1,9 +1,8 @@ <#if options.seo_spider_disabled!false> -User-agent: / +User-agent: * Disallow: / <#else> User-agent: * -Disallow: ${adminPath!}/ Sitemap: ${context!}/sitemap.xml Sitemap: ${context!}/sitemap.html \ No newline at end of file