mirror of https://github.com/halo-dev/halo
Update robots router.
parent
eb7ff715c2
commit
463b786671
|
@ -16,6 +16,7 @@ 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;
|
||||||
|
@ -43,13 +44,16 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,6 +129,8 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ User-agent: /
|
||||||
Disallow: /
|
Disallow: /
|
||||||
<#else>
|
<#else>
|
||||||
User-agent: *
|
User-agent: *
|
||||||
Disallow: /admin/
|
Disallow: ${adminPath!}/
|
||||||
Sitemap: ${context!}/sitemap.xml
|
Sitemap: ${context!}/sitemap.xml
|
||||||
Sitemap: ${context!}/sitemap.html
|
Sitemap: ${context!}/sitemap.html
|
||||||
</#if>
|
</#if>
|
Loading…
Reference in New Issue