Skip to content

Commit

Permalink
Allow passing sitemap url directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Michał committed Nov 25, 2024
1 parent c992fbf commit 93c719b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion apps/api/lib/buildel/sitemaps.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Buildel.Sitemaps do
import SweetXml

def get_sitemaps(url) do
with {:ok, sitemaps} <- fetch_robots_sitemaps(url) do
with {:ok, sitemaps} <- fetch_sitemaps(url) do
fetch_sitemaps_recursive(sitemaps)
else
_ ->
Expand All @@ -15,6 +15,14 @@ defmodule Buildel.Sitemaps do
end
end

defp fetch_sitemaps(url) do
if url |> String.ends_with?("sitemap.xml") do
{:ok, [url]}
else
fetch_robots_sitemaps(url)
end
end

defp fetch_robots_sitemaps(url) do
uri = URI.parse(url) |> URI.merge("/robots.txt")

Expand Down

0 comments on commit 93c719b

Please sign in to comment.