Merge branch 'mix_sem_ver_version_fix' into 'develop'
[akkoma] / lib / mix / tasks / pleroma / robotstxt.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2019 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 static_dir = Pleroma.Config.get([:instance, :static_dir], "instance/static/")
22
23 if !File.exists?(static_dir) do
24 File.mkdir_p!(static_dir)
25 end
26
27 robots_txt_path = Path.join(static_dir, "robots.txt")
28 robots_txt_content = "User-Agent: *\nDisallow: /\n"
29
30 File.write!(robots_txt_path, robots_txt_content, [:write])
31 end
32 end