mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 23:31:18 +08:00
FEATURE: Allow customization of robots.txt (#7884)
* FEATURE: Allow customization of robots.txt This allows admins to customize/override the content of the robots.txt file at /admin/customize/robots. That page is not linked to anywhere in the UI -- admins have to manually type the URL to access that page. * use Ember.computed.not * Jeff feedback * Feedback * Remove unused import
This commit is contained in:
38
app/controllers/admin/robots_txt_controller.rb
Normal file
38
app/controllers/admin/robots_txt_controller.rb
Normal file
@ -0,0 +1,38 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Admin::RobotsTxtController < Admin::AdminController
|
||||
|
||||
def show
|
||||
render json: { robots_txt: current_robots_txt, overridden: @overridden }
|
||||
end
|
||||
|
||||
def update
|
||||
params.require(:robots_txt)
|
||||
SiteSetting.overridden_robots_txt = params[:robots_txt]
|
||||
|
||||
render json: { robots_txt: current_robots_txt, overridden: @overridden }
|
||||
end
|
||||
|
||||
def reset
|
||||
SiteSetting.overridden_robots_txt = ""
|
||||
render json: { robots_txt: original_robots_txt, overridden: false }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def current_robots_txt
|
||||
robots_txt = SiteSetting.overridden_robots_txt.presence
|
||||
@overridden = robots_txt.present?
|
||||
robots_txt ||= original_robots_txt
|
||||
robots_txt
|
||||
end
|
||||
|
||||
def original_robots_txt
|
||||
if SiteSetting.allow_index_in_robots_txt?
|
||||
@robots_info = ::RobotsTxtController.fetch_default_robots_info
|
||||
render_to_string "robots_txt/index"
|
||||
else
|
||||
render_to_string "robots_txt/no_index"
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user