Skip to content

Commit

Permalink
Tweak Sitemap generation
Browse files Browse the repository at this point in the history
Include all public, published items in sitemap
Have index point at api/sitemap/ route
  • Loading branch information
mbklein committed Jul 30, 2024
1 parent 44fa64d commit 6ba4b8d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ if prefix = System.get_env("DEV_PREFIX") do
end

config :meadow, :sitemaps,
base_url: "https://dc.library.northwestern.edu/",
gzip: false,
store: Sitemapper.FileStore,
sitemap_url: "https://devbox.library.northwestern.edu:3333/",
Expand Down
11 changes: 9 additions & 2 deletions app/config/releases.exs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ config :meadow,
bucket: aws_secret("meadow", dig: ["buckets", "sitemap"]),
path: "/"
],
sitemap_url: aws_secret("meadow", dig: ["dc", "base_url"])
base_url: aws_secret("meadow", dig: ["dc", "base_url"]),
sitemap_url:
aws_secret("meadow", dig: ["dc", "base_url"], apply: &{:ok, Path.join(&1, "api/sitemap")})
],
validation_ping_interval: environment_secret("VALIDATION_PING_INTERVAL", default: "1000")

Expand All @@ -125,7 +127,12 @@ config :meadow, Meadow.Scheduler,
overlap: false,
timezone: "America/Chicago",
jobs: [
# Runs daily at the configured time (default: 2AM Central)
# Sitemap generation runs daily at the configured time (default: 1AM Central)
{
aws_secret("meadow", dig: ["scheduler", "sitemap"], default: "0 1 * * *"),
{Meadow.Utils.Sitemap, :generate, []}
},
# Preservation check runs daily at the configured time (default: 2AM Central)
{
aws_secret("meadow", dig: ["scheduler", "preservation_check"], default: "0 2 * * *"),
{Meadow.Data.PreservationChecks, :start_job, []}
Expand Down
1 change: 1 addition & 0 deletions app/config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ config :honeybadger,
config :meadow, :sitemaps,
gzip: true,
store: Sitemapper.S3Store,
base_url: "http://localhost:3333/",
sitemap_url: "http://localhost:3333/",
store_config: [bucket: prefix("uploads"), path: ""]

Expand Down
9 changes: 6 additions & 3 deletions app/lib/meadow/utils/sitemap.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ defmodule Meadow.Utils.Sitemap do
@moduledoc """
Generate and upload Digital Collection sitemaps
"""
alias Meadow.Data.{Collections, Works}
alias Meadow.Data.Collections
alias Meadow.Data.Schemas.Work
alias Meadow.Repo

import Ecto.Query

require Logger

@doc """
Expand Down Expand Up @@ -74,7 +77,7 @@ defmodule Meadow.Utils.Sitemap do
end

defp work_urls do
Works.work_query(visibility: "OPEN", work_type: "IMAGE")
from(w in Work, where: w.visibility["id"] == ^"OPEN" and w.published)
|> Repo.stream()
|> Stream.map(fn %{id: id, updated_at: updated_at} ->
%Sitemapper.URL{
Expand All @@ -88,7 +91,7 @@ defmodule Meadow.Utils.Sitemap do

defp expand_url(path) do
config()
|> Keyword.get(:sitemap_url)
|> Keyword.get(:base_url)
|> URI.parse()
|> URI.merge(path)
|> URI.to_string()
Expand Down

0 comments on commit 6ba4b8d

Please sign in to comment.