From 9342fa7294ea28b2c667e8b487a3a99b1c0aefc8 Mon Sep 17 00:00:00 2001 From: ruibaby Date: Tue, 14 May 2019 10:23:30 +0800 Subject: [PATCH] Support disable spider. --- .../run/halo/app/model/properties/OtherProperties.java | 7 ++++++- src/main/resources/templates/common/web/robots.ftl | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) 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 51f03983b..43b66ebcc 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,12 @@ public enum OtherProperties implements PropertyEnum { API_TOKEN("api_token", String.class, ""), - STATISTICS_CODE("statistics_code", String.class, ""); + STATISTICS_CODE("statistics_code", String.class, ""), + + /** + * 是否禁止爬虫 + */ + SPIDER_DISABLE("spider_disable",Boolean.class,"false"); private final String value; diff --git a/src/main/resources/templates/common/web/robots.ftl b/src/main/resources/templates/common/web/robots.ftl index e7bfbaab7..4d55ecffe 100644 --- a/src/main/resources/templates/common/web/robots.ftl +++ b/src/main/resources/templates/common/web/robots.ftl @@ -1,4 +1,9 @@ +<#if options.spider_disable!false> +User-agent: / +Disallow: / +<#else> User-agent: * Disallow: /admin/ Sitemap: ${options.blog_url!}/sitemap.xml -Sitemap: ${options.blog_url!}/sitemap.html \ No newline at end of file +Sitemap: ${options.blog_url!}/sitemap.html + \ No newline at end of file