fix: issue #15 calendar index not properly created, also some smaller bugs
This commit is contained in:
@@ -375,7 +375,7 @@ defmodule BDS.Generation.Outputs do
|
||||
main_static_outputs =
|
||||
[
|
||||
{"404.html", render_not_found_output(plan, language)},
|
||||
{"feed.xml", render_feed(plan, language, published_posts)},
|
||||
{"rss.xml", render_feed(plan, language, published_posts)},
|
||||
{"atom.xml", render_atom(plan, language, published_posts)},
|
||||
{"calendar.json", render_calendar(published_posts)}
|
||||
]
|
||||
@@ -399,7 +399,7 @@ defmodule BDS.Generation.Outputs do
|
||||
[
|
||||
{Path.join(localized_language, "404.html"),
|
||||
render_not_found_output(plan, localized_language)},
|
||||
{Path.join(localized_language, "feed.xml"),
|
||||
{Path.join(localized_language, "rss.xml"),
|
||||
render_feed(plan, localized_language, localized_source_posts)},
|
||||
{Path.join(localized_language, "atom.xml"),
|
||||
render_atom(plan, localized_language, localized_source_posts)}
|
||||
|
||||
@@ -237,7 +237,7 @@ defmodule BDS.Generation.Paths do
|
||||
|
||||
@spec sitemap_route_output?(String.t()) :: boolean()
|
||||
def sitemap_route_output?("404.html"), do: false
|
||||
def sitemap_route_output?("feed.xml"), do: false
|
||||
def sitemap_route_output?("rss.xml"), do: false
|
||||
def sitemap_route_output?("atom.xml"), do: false
|
||||
def sitemap_route_output?("calendar.json"), do: false
|
||||
def sitemap_route_output?(relative_path), do: String.ends_with?(relative_path, ".html")
|
||||
|
||||
@@ -212,13 +212,19 @@ defmodule BDS.Generation.Sitemap do
|
||||
"<feed><title>#{xml_escape(plan.project_name)} (#{xml_escape(language || "default")})</title>#{entries}</feed>"
|
||||
end
|
||||
|
||||
@doc "Render a JSON calendar of all published posts."
|
||||
@doc """
|
||||
Render the JSON calendar archive consumed by the calendar runtime:
|
||||
post counts keyed by year ("2024"), month ("2024-05"), and day ("2024-05-17").
|
||||
"""
|
||||
@spec render_calendar([map()]) :: String.t()
|
||||
def render_calendar(published_posts) do
|
||||
published_posts
|
||||
|> Enum.map(fn post ->
|
||||
%{date: Paths.local_date_iso8601!(post.created_at), slug: post.slug, title: post.title}
|
||||
end)
|
||||
day_keys = Enum.map(published_posts, &Paths.local_date_iso8601!(&1.created_at))
|
||||
|
||||
%{
|
||||
years: Enum.frequencies_by(day_keys, &binary_part(&1, 0, 4)),
|
||||
months: Enum.frequencies_by(day_keys, &binary_part(&1, 0, 7)),
|
||||
days: Enum.frequencies(day_keys)
|
||||
}
|
||||
|> Jason.encode!()
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user