mirror of
https://github.com/plausible/analytics.git
synced 2024-12-27 19:47:26 +03:00
fea9bb32ee
* Add noindex,nofollow to dashboard pages * Implement NoRobots plug * Enable NoRobots plug in the router * Fixup internal route * Fix double slash in the router * Add special bot treatment to plausible.io live demo page * Revert aggressive protection with agent detection
30 lines
855 B
Elixir
30 lines
855 B
Elixir
defmodule PlausibleWeb.Plugs.NoRobots do
|
|
@moduledoc """
|
|
Rejects bot requests by any means available.
|
|
|
|
We're adding `x-robots-tag` to the response header and annotate the conn
|
|
with "noindex, nofollow" under `private.robots` key.
|
|
|
|
The only exception is, if the request is trying to access our live demo
|
|
at plausible.io/plausible.io - in which case we'll allow indexing, but deny
|
|
following links and skip the bot detection, in kind robots we trust.
|
|
"""
|
|
@behaviour Plug
|
|
import Plug.Conn
|
|
|
|
@impl true
|
|
def init(opts), do: opts
|
|
|
|
@impl true
|
|
def call(conn, _opts \\ nil) do
|
|
conn =
|
|
if conn.path_info == ["plausible.io"] do
|
|
put_private(conn, :robots, "index, nofollow")
|
|
else
|
|
put_private(conn, :robots, "noindex, nofollow")
|
|
end
|
|
|
|
put_resp_header(conn, "x-robots-tag", conn.private.robots)
|
|
end
|
|
end
|