feat: hide admin path in robot.txt

pull/389/head
ruibaby 2019-11-18 11:42:25 +08:00
parent 406ced57f5
commit 381341a18b
2 changed files with 2 additions and 9 deletions

View File

@ -16,7 +16,6 @@ import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; 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.entity.Post;
import run.halo.app.model.enums.PostStatus; import run.halo.app.model.enums.PostStatus;
import run.halo.app.model.vo.PostListVO; import run.halo.app.model.vo.PostListVO;
@ -44,16 +43,13 @@ public class ContentFeedController {
private final PostService postService; private final PostService postService;
private final OptionService optionService; private final OptionService optionService;
private final FreeMarkerConfigurer freeMarker; private final FreeMarkerConfigurer freeMarker;
private final HaloProperties haloProperties;
public ContentFeedController(PostService postService, public ContentFeedController(PostService postService,
OptionService optionService, OptionService optionService,
FreeMarkerConfigurer freeMarker, FreeMarkerConfigurer freeMarker) {
HaloProperties haloProperties) {
this.postService = postService; this.postService = postService;
this.optionService = optionService; this.optionService = optionService;
this.freeMarker = freeMarker; this.freeMarker = freeMarker;
this.haloProperties = haloProperties;
} }
/** /**
@ -129,8 +125,6 @@ public class ContentFeedController {
@GetMapping(value = "robots.txt", produces = MediaType.TEXT_PLAIN_VALUE) @GetMapping(value = "robots.txt", produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseBody @ResponseBody
public String robots(Model model) throws IOException, TemplateException { 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"); Template template = freeMarker.getConfiguration().getTemplate("common/web/robots.ftl");
return FreeMarkerTemplateUtils.processTemplateIntoString(template, model); return FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
} }

View File

@ -1,9 +1,8 @@
<#if options.seo_spider_disabled!false> <#if options.seo_spider_disabled!false>
User-agent: / User-agent: *
Disallow: / Disallow: /
<#else> <#else>
User-agent: * User-agent: *
Disallow: ${adminPath!}/
Sitemap: ${context!}/sitemap.xml Sitemap: ${context!}/sitemap.xml
Sitemap: ${context!}/sitemap.html Sitemap: ${context!}/sitemap.html
</#if> </#if>