-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Beacon generates robots.txt
per site
#700
Open
APB9785
wants to merge
1
commit into
apb/sitemap
Choose a base branch
from
apb/robots-txt
base: apb/sitemap
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
defmodule Beacon.Web.RobotsController do | ||
@moduledoc false | ||
use Beacon.Web, :controller | ||
|
||
def init(:show), do: :show | ||
|
||
def call(%{assigns: %{site: site}} = conn, :show) do | ||
conn | ||
|> put_view(Beacon.Web.RobotsTxt) | ||
|> put_resp_content_type("text/txt") | ||
|> put_resp_header("cache-control", "public max-age=300") | ||
|> render(:robots, sitemap_url: get_sitemap_url(conn, site)) | ||
end | ||
|
||
defp get_sitemap_url(conn, site) do | ||
routes_module = Beacon.Loader.fetch_routes_module(site) | ||
|
||
Beacon.apply_mfa(site, routes_module, :beacon_sitemap_url, [conn]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# http://www.robotstxt.org | ||
User-agent: * | ||
Sitemap: <%= @sitemap_url %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
defmodule Beacon.Web.RobotsTxt do | ||
import Phoenix.Template, only: [embed_templates: 1] | ||
embed_templates "robots/*.txt" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
defmodule Beacon.Web.RobotsControllerTest do | ||
use Beacon.Web.ConnCase, async: false | ||
|
||
test "show", %{conn: conn} do | ||
conn = get(conn, "/robots.txt") | ||
|
||
assert response(conn, 200) == """ | ||
# http://www.robotstxt.org | ||
User-agent: * | ||
Sitemap: http://localhost:4000/sitemap.xml | ||
""" | ||
|
||
assert response_content_type(conn, :txt) =~ "charset=utf-8" | ||
|
||
# site: :not_booted | ||
conn = get(conn, "/other/robots.txt") | ||
|
||
assert response(conn, 200) == """ | ||
# http://www.robotstxt.org | ||
User-agent: * | ||
Sitemap: http://localhost:4000/other/sitemap.xml | ||
""" | ||
|
||
assert response_content_type(conn, :txt) =~ "charset=utf-8" | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could disallow the admin prefix here as well. See https://github.com/BeaconCMS/beacon_live_admin/blob/f8ff1621253c30c5f143655c11acf1116fa1c1e4/lib/beacon/live_admin/router.ex#L88
We need to use
scoped_path
to build the full path including thescope
path. So if that attribute is present in the router we could include it asDisallow: <%= @admin_prefix %>
otherwise just ignore the line since the admin might not even be included in the router.And we'll need at least a simple test because that function might change and we need a failing test if that happens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that will be included. This PR only uses the
beacon_site
macro for generation