Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[akkoma] / lib / mix / tasks / pleroma / robots_txt.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Mix.Tasks.Pleroma.RobotsTxt do
6 use Mix.Task
7
8 @shortdoc "Generate robots.txt"
9 @moduledoc """
10 Generates robots.txt
11
12 ## Overwrite robots.txt to disallow all
13
14 mix pleroma.robots_txt disallow_all
15
16 This will write a robots.txt that will hide all paths on your instance
17 from search engines and other robots that obey robots.txt
18
19 """
20 def run(["disallow_all"]) do
21 Mix.Pleroma.start_pleroma()
22 static_dir = Pleroma.Config.get([:instance, :static_dir], "instance/static/")
23
24 if !File.exists?(static_dir) do
25 File.mkdir_p!(static_dir)
26 end
27
28 robots_txt_path = Path.join(static_dir, "robots.txt")
29 robots_txt_content = "User-Agent: *\nDisallow: /\n"
30
31 File.write!(robots_txt_path, robots_txt_content, [:write])
32 end
33 end