fix: issue #35 validation expected unrendered .lang translation variant routes; main-language lists now render main-language translations
This commit is contained in:
@@ -74,8 +74,8 @@ defmodule BDS.Generation.Data do
|
||||
|> Enum.uniq_by(& &1.id)
|
||||
|> Enum.sort_by(&{-(&1.created_at || 0), -(&1.published_at || 0), to_string(&1.slug)})
|
||||
|
||||
{published_route_posts, translations_by_post} =
|
||||
build_generation_route_posts(
|
||||
translations_by_post =
|
||||
build_generation_translations(
|
||||
plan.project_id,
|
||||
project_data_dir,
|
||||
published_posts,
|
||||
@@ -87,7 +87,6 @@ defmodule BDS.Generation.Data do
|
||||
project_data_dir: project_data_dir,
|
||||
published_posts: published_posts,
|
||||
published_list_posts: published_list_posts,
|
||||
published_route_posts: published_route_posts,
|
||||
translations_by_post: translations_by_post,
|
||||
post_index: build_generation_post_index(published_list_posts)
|
||||
}
|
||||
@@ -121,18 +120,13 @@ defmodule BDS.Generation.Data do
|
||||
post_language = String.downcase(to_string(post.language || ""))
|
||||
effective_language = if post_language == "", do: main, else: post_language
|
||||
|
||||
cond do
|
||||
is_binary(Map.get(post, :translation_source_slug)) ->
|
||||
post
|
||||
|
||||
effective_language == target ->
|
||||
post
|
||||
|
||||
true ->
|
||||
case Map.get(translations_by_post_language, {post.id, target_language}) do
|
||||
nil -> post
|
||||
translation -> build_localized_subtree_variant(post, translation)
|
||||
end
|
||||
if effective_language == target do
|
||||
post
|
||||
else
|
||||
case Map.get(translations_by_post_language, {post.id, target_language}) do
|
||||
nil -> post
|
||||
translation -> build_localized_subtree_variant(post, translation)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
@@ -231,7 +225,7 @@ defmodule BDS.Generation.Data do
|
||||
read_snapshot(full_path, fallback_post, &build_post_snapshot/2)
|
||||
end
|
||||
|
||||
defp build_generation_route_posts(
|
||||
defp build_generation_translations(
|
||||
project_id,
|
||||
project_data_dir,
|
||||
published_posts,
|
||||
@@ -268,17 +262,7 @@ defmodule BDS.Generation.Data do
|
||||
end)
|
||||
|> Map.new(fn {post_id, translations} -> {post_id, Enum.reverse(translations)} end)
|
||||
|
||||
route_posts =
|
||||
Enum.flat_map(published_posts, fn post ->
|
||||
variants =
|
||||
translations_by_post
|
||||
|> Map.get(post.id, [])
|
||||
|> Enum.map(&build_published_translation_variant(post, &1))
|
||||
|
||||
[post | variants]
|
||||
end)
|
||||
|
||||
{route_posts, translations_by_post}
|
||||
translations_by_post
|
||||
end
|
||||
|
||||
defp published_translation_snapshot(project_data_dir, %Translation{} = translation) do
|
||||
@@ -357,31 +341,6 @@ defmodule BDS.Generation.Data do
|
||||
}
|
||||
end
|
||||
|
||||
defp build_published_translation_variant(post, translation) do
|
||||
%{
|
||||
id: translation.id,
|
||||
project_id: post.project_id,
|
||||
title: translation.title,
|
||||
slug: "#{post.slug}.#{translation.language}",
|
||||
excerpt: translation.excerpt,
|
||||
content: nil,
|
||||
status: :published,
|
||||
author: post.author,
|
||||
created_at: post.created_at,
|
||||
updated_at: translation.updated_at,
|
||||
published_at: translation.published_at || post.published_at,
|
||||
file_path: translation.file_path,
|
||||
tags: post.tags,
|
||||
categories: post.categories,
|
||||
template_slug: post.template_slug,
|
||||
language: translation.language,
|
||||
do_not_translate: post.do_not_translate,
|
||||
translation_source_slug: post.slug,
|
||||
translation_canonical_language: post.language,
|
||||
translation_file_path: translation.file_path
|
||||
}
|
||||
end
|
||||
|
||||
defp build_localized_subtree_variant(post, translation) do
|
||||
%{
|
||||
post
|
||||
|
||||
@@ -22,16 +22,6 @@ defmodule BDS.Generation.Outputs do
|
||||
def route_post_output_path(post, ""), do: post_output_path(post)
|
||||
def route_post_output_path(post, route_language), do: post_output_path(post, route_language)
|
||||
|
||||
@spec suppress_subtree_translation_variants([map()], [String.t()]) :: [map()]
|
||||
def suppress_subtree_translation_variants(route_posts, additional_languages) do
|
||||
subtree_languages = MapSet.new(additional_languages)
|
||||
|
||||
Enum.reject(route_posts, fn post ->
|
||||
is_binary(Map.get(post, :translation_source_slug)) and
|
||||
MapSet.member?(subtree_languages, to_string(post.language))
|
||||
end)
|
||||
end
|
||||
|
||||
@spec build_validation_route_paths(map(), [map()], [map()], map(), String.t() | nil) :: [
|
||||
String.t()
|
||||
]
|
||||
|
||||
@@ -28,15 +28,15 @@ defmodule BDS.Generation.Validation do
|
||||
@spec build_post_timestamp_checks(String.t(), [map()], map()) :: [map()]
|
||||
def build_post_timestamp_checks(
|
||||
project_data_dir,
|
||||
published_route_posts,
|
||||
published_posts,
|
||||
generated_file_updated_at
|
||||
) do
|
||||
build_timestamp_checks(
|
||||
project_data_dir,
|
||||
published_route_posts,
|
||||
published_posts,
|
||||
generated_file_updated_at,
|
||||
&BDS.Generation.Paths.post_output_path/1,
|
||||
fn post -> Map.get(post, :translation_file_path) || post.file_path end
|
||||
& &1.file_path
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user