add published custom pages to sitemap
All checks were successful
deploy / deploy (push) Successful in 1m20s

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey 2026-02-28 11:37:16 +00:00
parent 3a243151af
commit 22d7b0e92b
3 changed files with 26 additions and 3 deletions

View File

@ -146,7 +146,7 @@ Plans: [admin-redesign.md](docs/plans/admin-redesign.md) | [admin-font-loading.m
| ~~97~~ | ~~Stage 1: data model + context — schema fields, split changeset, CRUD functions, cache~~ | — | 1.5h | done |
| ~~98~~ | ~~Stage 2: routing + LiveView — `Shop.CustomPage`, catch-all route, 404 handling~~ | 97 | 1h | done |
| ~~99~~ | ~~Stage 3: admin CRUD — create/edit/delete pages, page settings, admin index~~ | 98 | 2.5h | done |
| 100 | Stage 4: navigation management — data-driven nav, settings storage, admin editor | 99 | 3h | planned |
| ~~100~~ | ~~Stage 4: navigation management — data-driven nav, settings storage, admin editor~~ | 99 | 3h | done |
| 101 | Stage 5: SEO + redirects — sitemap, auto-redirect on slug change, draft/published | 100 | 1h | planned |
| 102 | Stage 6: polish — page templates, new block types, bulk ops | 101 | 3-4h | deferred |
| | **Platform site** | | | |

View File

@ -1,7 +1,7 @@
defmodule BerrypodWeb.SeoController do
use BerrypodWeb, :controller
alias Berrypod.Products
alias Berrypod.{Pages, Products}
def robots(conn, _params) do
base = BerrypodWeb.Endpoint.url()
@ -48,7 +48,12 @@ defmodule BerrypodWeb.SeoController do
{"/products/#{product.slug}", "weekly", "0.9"}
end)
all_pages = static_pages ++ category_pages ++ product_pages
custom_pages =
Pages.list_custom_pages()
|> Enum.filter(& &1.published)
|> Enum.map(fn page -> {"/#{page.slug}", "weekly", "0.6"} end)
all_pages = static_pages ++ category_pages ++ product_pages ++ custom_pages
entries =
Enum.map_join(all_pages, "\n", fn {path, changefreq, priority} ->

View File

@ -4,7 +4,11 @@ defmodule BerrypodWeb.SeoControllerTest do
import Berrypod.AccountsFixtures
import Berrypod.ProductsFixtures
alias Berrypod.Pages
alias Berrypod.Pages.PageCache
setup do
PageCache.invalidate_all()
user_fixture()
{:ok, _} = Berrypod.Settings.set_site_live(true)
:ok
@ -64,5 +68,19 @@ defmodule BerrypodWeb.SeoControllerTest do
assert body =~ "<urlset"
assert body =~ "</urlset>"
end
test "includes published custom pages", %{conn: conn} do
{:ok, _} = Pages.create_custom_page(%{slug: "faq", title: "FAQ", published: true})
body = get(conn, "/sitemap.xml") |> response(200)
assert body =~ "/faq"
end
test "excludes unpublished custom pages", %{conn: conn} do
{:ok, _} = Pages.create_custom_page(%{slug: "draft", title: "Draft", published: false})
body = get(conn, "/sitemap.xml") |> response(200)
refute body =~ "/draft"
end
end
end