Consolidate generation route builders
This commit is contained in:
1
AUDIT.md
1
AUDIT.md
@@ -21,6 +21,7 @@ after each item.
|
|||||||
- [x] `rendering/metadata.ex`
|
- [x] `rendering/metadata.ex`
|
||||||
- [x] `rendering/links_and_languages.ex`
|
- [x] `rendering/links_and_languages.ex`
|
||||||
- [x] `generation/validation.ex`
|
- [x] `generation/validation.ex`
|
||||||
|
- [x] `generation/outputs.ex`
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -51,114 +51,102 @@ defmodule BDS.Generation.Outputs do
|
|||||||
|
|
||||||
@spec core_route_paths(map(), [map()], String.t() | nil) :: [String.t()]
|
@spec core_route_paths(map(), [map()], String.t() | nil) :: [String.t()]
|
||||||
def core_route_paths(plan, published_list_posts, route_language) do
|
def core_route_paths(plan, published_list_posts, route_language) do
|
||||||
if :core in plan.sections do
|
section_route_paths(plan, :core, fn ->
|
||||||
root_route_paths(route_language, length(published_list_posts), plan.max_posts_per_page)
|
root_route_paths(route_language, length(published_list_posts), plan.max_posts_per_page)
|
||||||
else
|
end)
|
||||||
[]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec page_route_paths(map(), [map()], String.t() | nil) :: [String.t()]
|
@spec page_route_paths(map(), [map()], String.t() | nil) :: [String.t()]
|
||||||
def page_route_paths(plan, route_posts, route_language) do
|
def page_route_paths(plan, route_posts, route_language) do
|
||||||
if :core in plan.sections do
|
section_route_paths(plan, :core, fn ->
|
||||||
route_posts
|
route_posts
|
||||||
|> Enum.filter(&("page" in (&1.categories || [])))
|
|> Enum.filter(&("page" in (&1.categories || [])))
|
||||||
|> Enum.map(&page_output_path(&1.slug, route_language))
|
|> Enum.map(&page_output_path(&1.slug, route_language))
|
||||||
else
|
end)
|
||||||
[]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec single_route_paths(map(), [map()], String.t() | nil) :: [String.t()]
|
@spec single_route_paths(map(), [map()], String.t() | nil) :: [String.t()]
|
||||||
def single_route_paths(plan, route_posts, route_language) do
|
def single_route_paths(plan, route_posts, route_language) do
|
||||||
if :single in plan.sections do
|
section_route_paths(plan, :single, fn ->
|
||||||
Enum.map(route_posts, &route_post_output_path(&1, route_language))
|
Enum.map(route_posts, &route_post_output_path(&1, route_language))
|
||||||
else
|
end)
|
||||||
[]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec category_route_paths(map(), map(), String.t() | nil) :: [String.t()]
|
@spec category_route_paths(map(), map(), String.t() | nil) :: [String.t()]
|
||||||
def category_route_paths(plan, posts_by_category, route_language) do
|
def category_route_paths(plan, posts_by_category, route_language) do
|
||||||
if :category in plan.sections do
|
section_route_paths(plan, :category, fn ->
|
||||||
Enum.flat_map(posts_by_category, fn {category, posts} ->
|
archive_collection_route_paths(
|
||||||
post_count = length(posts)
|
posts_by_category,
|
||||||
|
|
||||||
paginated_archive_paths(
|
|
||||||
route_language,
|
route_language,
|
||||||
["category", archive_route_segment(category)],
|
plan.max_posts_per_page,
|
||||||
post_count,
|
fn category -> ["category", archive_route_segment(category)] end
|
||||||
plan.max_posts_per_page
|
|
||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
else
|
|
||||||
[]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec tag_route_paths(map(), map(), String.t() | nil) :: [String.t()]
|
@spec tag_route_paths(map(), map(), String.t() | nil) :: [String.t()]
|
||||||
def tag_route_paths(plan, posts_by_tag, route_language) do
|
def tag_route_paths(plan, posts_by_tag, route_language) do
|
||||||
if :tag in plan.sections do
|
section_route_paths(plan, :tag, fn ->
|
||||||
Enum.flat_map(posts_by_tag, fn {tag, posts} ->
|
archive_collection_route_paths(
|
||||||
post_count = length(posts)
|
posts_by_tag,
|
||||||
|
|
||||||
paginated_archive_paths(
|
|
||||||
route_language,
|
route_language,
|
||||||
["tag", archive_route_segment(tag)],
|
plan.max_posts_per_page,
|
||||||
post_count,
|
fn tag -> ["tag", archive_route_segment(tag)] end
|
||||||
plan.max_posts_per_page
|
|
||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
else
|
|
||||||
[]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec date_route_paths(map(), map(), String.t() | nil) :: [String.t()]
|
@spec date_route_paths(map(), map(), String.t() | nil) :: [String.t()]
|
||||||
def date_route_paths(plan, post_index, route_language) do
|
def date_route_paths(plan, post_index, route_language) do
|
||||||
if :date in plan.sections do
|
section_route_paths(plan, :date, fn ->
|
||||||
year_paths =
|
year_paths =
|
||||||
Enum.flat_map(post_index.posts_by_year, fn {year, posts} ->
|
archive_collection_route_paths(
|
||||||
post_count = length(posts)
|
post_index.posts_by_year,
|
||||||
|
|
||||||
paginated_archive_paths(
|
|
||||||
route_language,
|
route_language,
|
||||||
[Integer.to_string(year)],
|
plan.max_posts_per_page,
|
||||||
post_count,
|
fn year -> [Integer.to_string(year)] end
|
||||||
plan.max_posts_per_page
|
|
||||||
)
|
)
|
||||||
end)
|
|
||||||
|
|
||||||
month_paths =
|
month_paths =
|
||||||
Enum.flat_map(post_index.posts_by_year_month, fn {year_month, posts} ->
|
archive_collection_route_paths(
|
||||||
[year, month] = String.split(year_month, "/", parts: 2)
|
post_index.posts_by_year_month,
|
||||||
post_count = length(posts)
|
|
||||||
|
|
||||||
paginated_archive_paths(
|
|
||||||
route_language,
|
route_language,
|
||||||
[year, month],
|
plan.max_posts_per_page,
|
||||||
post_count,
|
fn year_month -> String.split(year_month, "/", parts: 2) end
|
||||||
plan.max_posts_per_page
|
|
||||||
)
|
)
|
||||||
end)
|
|
||||||
|
|
||||||
day_paths =
|
day_paths =
|
||||||
Enum.flat_map(post_index.posts_by_year_month_day, fn {year_month_day, posts} ->
|
archive_collection_route_paths(
|
||||||
[year, month, day] = String.split(year_month_day, "/", parts: 3)
|
post_index.posts_by_year_month_day,
|
||||||
|
route_language,
|
||||||
|
plan.max_posts_per_page,
|
||||||
|
fn year_month_day -> String.split(year_month_day, "/", parts: 3) end
|
||||||
|
)
|
||||||
|
|
||||||
|
year_paths ++ month_paths ++ day_paths
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp section_route_paths(plan, section, builder) do
|
||||||
|
if section in plan.sections, do: builder.(), else: []
|
||||||
|
end
|
||||||
|
|
||||||
|
defp archive_collection_route_paths(
|
||||||
|
collections,
|
||||||
|
route_language,
|
||||||
|
max_posts_per_page,
|
||||||
|
segment_builder
|
||||||
|
) do
|
||||||
|
Enum.flat_map(collections, fn {key, posts} ->
|
||||||
post_count = length(posts)
|
post_count = length(posts)
|
||||||
|
|
||||||
paginated_archive_paths(
|
paginated_archive_paths(
|
||||||
route_language,
|
route_language,
|
||||||
[year, month, day],
|
segment_builder.(key),
|
||||||
post_count,
|
post_count,
|
||||||
plan.max_posts_per_page
|
max_posts_per_page
|
||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
year_paths ++ month_paths ++ day_paths
|
|
||||||
else
|
|
||||||
[]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec build_archive_outputs(map(), map(), map()) :: [{String.t(), iodata()}]
|
@spec build_archive_outputs(map(), map(), map()) :: [{String.t(), iodata()}]
|
||||||
|
|||||||
Reference in New Issue
Block a user