Deduplicate sitemap URL entry builders
This commit is contained in:
1
AUDIT.md
1
AUDIT.md
@@ -22,6 +22,7 @@ after each item.
|
|||||||
- [x] `rendering/links_and_languages.ex`
|
- [x] `rendering/links_and_languages.ex`
|
||||||
- [x] `generation/validation.ex`
|
- [x] `generation/validation.ex`
|
||||||
- [x] `generation/outputs.ex`
|
- [x] `generation/outputs.ex`
|
||||||
|
- [x] `generation/sitemap.ex`
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -26,12 +26,14 @@ defmodule BDS.Generation.Sitemap do
|
|||||||
|
|
||||||
urls =
|
urls =
|
||||||
[
|
[
|
||||||
url_entry(
|
build_url_entry(
|
||||||
Paths.url_for_path(plan.base_url, "/"),
|
plan.base_url,
|
||||||
|
"/",
|
||||||
latest_post_updated_at,
|
latest_post_updated_at,
|
||||||
"daily",
|
"daily",
|
||||||
"1.0",
|
"1.0",
|
||||||
build_hreflang_links(plan.base_url, "/", plan.language, all_languages)
|
plan.language,
|
||||||
|
all_languages
|
||||||
)
|
)
|
||||||
] ++
|
] ++
|
||||||
Enum.map(
|
Enum.map(
|
||||||
@@ -39,35 +41,41 @@ defmodule BDS.Generation.Sitemap do
|
|||||||
fn page_number ->
|
fn page_number ->
|
||||||
page_path = "/page/#{page_number}"
|
page_path = "/page/#{page_number}"
|
||||||
|
|
||||||
url_entry(
|
build_url_entry(
|
||||||
Paths.url_for_path(plan.base_url, page_path),
|
plan.base_url,
|
||||||
|
page_path,
|
||||||
latest_post_updated_at,
|
latest_post_updated_at,
|
||||||
"daily",
|
"daily",
|
||||||
"0.9",
|
"0.9",
|
||||||
build_hreflang_links(plan.base_url, page_path, plan.language, all_languages)
|
plan.language,
|
||||||
|
all_languages
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
) ++
|
) ++
|
||||||
Enum.map(translatable_posts, fn post ->
|
Enum.map(translatable_posts, fn post ->
|
||||||
post_path = Paths.relative_path_to_url_path(Paths.post_output_path(post))
|
post_path = Paths.relative_path_to_url_path(Paths.post_output_path(post))
|
||||||
|
|
||||||
url_entry(
|
build_url_entry(
|
||||||
Paths.url_for_path(plan.base_url, post_path),
|
plan.base_url,
|
||||||
|
post_path,
|
||||||
unix_ms_to_iso8601(post.updated_at),
|
unix_ms_to_iso8601(post.updated_at),
|
||||||
"monthly",
|
"monthly",
|
||||||
"0.8",
|
"0.8",
|
||||||
build_hreflang_links(plan.base_url, post_path, plan.language, all_languages)
|
plan.language,
|
||||||
|
all_languages
|
||||||
)
|
)
|
||||||
end) ++
|
end) ++
|
||||||
Enum.map(do_not_translate_posts, fn post ->
|
Enum.map(do_not_translate_posts, fn post ->
|
||||||
post_path = Paths.relative_path_to_url_path(Paths.post_output_path(post))
|
post_path = Paths.relative_path_to_url_path(Paths.post_output_path(post))
|
||||||
|
|
||||||
url_entry(
|
build_url_entry(
|
||||||
Paths.url_for_path(plan.base_url, post_path),
|
plan.base_url,
|
||||||
|
post_path,
|
||||||
unix_ms_to_iso8601(post.updated_at),
|
unix_ms_to_iso8601(post.updated_at),
|
||||||
"monthly",
|
"monthly",
|
||||||
"0.8",
|
"0.8",
|
||||||
build_hreflang_links(plan.base_url, post_path, plan.language, [plan.language])
|
plan.language,
|
||||||
|
[plan.language]
|
||||||
)
|
)
|
||||||
end) ++
|
end) ++
|
||||||
Enum.flat_map(translatable_posts ++ do_not_translate_posts, fn post ->
|
Enum.flat_map(translatable_posts ++ do_not_translate_posts, fn post ->
|
||||||
@@ -80,12 +88,14 @@ defmodule BDS.Generation.Sitemap do
|
|||||||
else: all_languages
|
else: all_languages
|
||||||
|
|
||||||
[
|
[
|
||||||
url_entry(
|
build_url_entry(
|
||||||
Paths.url_for_path(plan.base_url, page_path),
|
plan.base_url,
|
||||||
|
page_path,
|
||||||
unix_ms_to_iso8601(post.updated_at),
|
unix_ms_to_iso8601(post.updated_at),
|
||||||
"weekly",
|
"weekly",
|
||||||
"0.7",
|
"0.7",
|
||||||
build_hreflang_links(plan.base_url, page_path, plan.language, languages)
|
plan.language,
|
||||||
|
languages
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
else
|
else
|
||||||
@@ -95,12 +105,14 @@ defmodule BDS.Generation.Sitemap do
|
|||||||
Enum.map(Enum.sort_by(post_index.posts_by_year, &elem(&1, 0), :desc), fn {year, _posts} ->
|
Enum.map(Enum.sort_by(post_index.posts_by_year, &elem(&1, 0), :desc), fn {year, _posts} ->
|
||||||
year_path = "/#{year}"
|
year_path = "/#{year}"
|
||||||
|
|
||||||
url_entry(
|
build_url_entry(
|
||||||
Paths.url_for_path(plan.base_url, year_path),
|
plan.base_url,
|
||||||
|
year_path,
|
||||||
latest_post_updated_at,
|
latest_post_updated_at,
|
||||||
"monthly",
|
"monthly",
|
||||||
"0.5",
|
"0.5",
|
||||||
build_hreflang_links(plan.base_url, year_path, plan.language, all_languages)
|
plan.language,
|
||||||
|
all_languages
|
||||||
)
|
)
|
||||||
end) ++
|
end) ++
|
||||||
Enum.map(
|
Enum.map(
|
||||||
@@ -108,12 +120,14 @@ defmodule BDS.Generation.Sitemap do
|
|||||||
fn {year_month, _posts} ->
|
fn {year_month, _posts} ->
|
||||||
month_path = "/#{year_month}"
|
month_path = "/#{year_month}"
|
||||||
|
|
||||||
url_entry(
|
build_url_entry(
|
||||||
Paths.url_for_path(plan.base_url, month_path),
|
plan.base_url,
|
||||||
|
month_path,
|
||||||
latest_post_updated_at,
|
latest_post_updated_at,
|
||||||
"monthly",
|
"monthly",
|
||||||
"0.5",
|
"0.5",
|
||||||
build_hreflang_links(plan.base_url, month_path, plan.language, all_languages)
|
plan.language,
|
||||||
|
all_languages
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
) ++
|
) ++
|
||||||
@@ -122,35 +136,41 @@ defmodule BDS.Generation.Sitemap do
|
|||||||
fn {year_month_day, _posts} ->
|
fn {year_month_day, _posts} ->
|
||||||
day_path = "/#{year_month_day}"
|
day_path = "/#{year_month_day}"
|
||||||
|
|
||||||
url_entry(
|
build_url_entry(
|
||||||
Paths.url_for_path(plan.base_url, day_path),
|
plan.base_url,
|
||||||
|
day_path,
|
||||||
latest_post_updated_at,
|
latest_post_updated_at,
|
||||||
"monthly",
|
"monthly",
|
||||||
"0.4",
|
"0.4",
|
||||||
build_hreflang_links(plan.base_url, day_path, plan.language, all_languages)
|
plan.language,
|
||||||
|
all_languages
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
) ++
|
) ++
|
||||||
Enum.map(Enum.sort_by(post_index.posts_by_category, &elem(&1, 0)), fn {category, _posts} ->
|
Enum.map(Enum.sort_by(post_index.posts_by_category, &elem(&1, 0)), fn {category, _posts} ->
|
||||||
category_path = "/category/#{Paths.archive_route_segment(category)}"
|
category_path = "/category/#{Paths.archive_route_segment(category)}"
|
||||||
|
|
||||||
url_entry(
|
build_url_entry(
|
||||||
Paths.url_for_path(plan.base_url, category_path),
|
plan.base_url,
|
||||||
|
category_path,
|
||||||
latest_post_updated_at,
|
latest_post_updated_at,
|
||||||
"weekly",
|
"weekly",
|
||||||
"0.6",
|
"0.6",
|
||||||
build_hreflang_links(plan.base_url, category_path, plan.language, all_languages)
|
plan.language,
|
||||||
|
all_languages
|
||||||
)
|
)
|
||||||
end) ++
|
end) ++
|
||||||
Enum.map(Enum.sort_by(post_index.posts_by_tag, &elem(&1, 0)), fn {tag, _posts} ->
|
Enum.map(Enum.sort_by(post_index.posts_by_tag, &elem(&1, 0)), fn {tag, _posts} ->
|
||||||
tag_path = "/tag/#{Paths.archive_route_segment(tag)}"
|
tag_path = "/tag/#{Paths.archive_route_segment(tag)}"
|
||||||
|
|
||||||
url_entry(
|
build_url_entry(
|
||||||
Paths.url_for_path(plan.base_url, tag_path),
|
plan.base_url,
|
||||||
|
tag_path,
|
||||||
latest_post_updated_at,
|
latest_post_updated_at,
|
||||||
"weekly",
|
"weekly",
|
||||||
"0.6",
|
"0.6",
|
||||||
build_hreflang_links(plan.base_url, tag_path, plan.language, all_languages)
|
plan.language,
|
||||||
|
all_languages
|
||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -274,6 +294,16 @@ defmodule BDS.Generation.Sitemap do
|
|||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp build_url_entry(base_url, url_path, lastmod, changefreq, priority, main_language, languages) do
|
||||||
|
url_entry(
|
||||||
|
Paths.url_for_path(base_url, url_path),
|
||||||
|
lastmod,
|
||||||
|
changefreq,
|
||||||
|
priority,
|
||||||
|
build_hreflang_links(base_url, url_path, main_language, languages)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
defp url_entry(loc, lastmod, changefreq, priority, hreflang_links) do
|
defp url_entry(loc, lastmod, changefreq, priority, hreflang_links) do
|
||||||
[
|
[
|
||||||
" <url>",
|
" <url>",
|
||||||
|
|||||||
Reference in New Issue
Block a user