diff --git a/PROGRESS.md b/PROGRESS.md index 9fc2bf1..8088708 100644 --- a/PROGRESS.md +++ b/PROGRESS.md @@ -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** | | | | diff --git a/lib/berrypod_web/controllers/seo_controller.ex b/lib/berrypod_web/controllers/seo_controller.ex index 5b4ea14..f7fb2c7 100644 --- a/lib/berrypod_web/controllers/seo_controller.ex +++ b/lib/berrypod_web/controllers/seo_controller.ex @@ -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} -> diff --git a/test/berrypod_web/controllers/seo_controller_test.exs b/test/berrypod_web/controllers/seo_controller_test.exs index f2842ac..8b64e71 100644 --- a/test/berrypod_web/controllers/seo_controller_test.exs +++ b/test/berrypod_web/controllers/seo_controller_test.exs @@ -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 =~ "" 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