Shared helper functions for blocks.
Extracts common patterns that would otherwise be duplicated across multiple block modules (language filtering, URL prefix generation, etc.).
Summary
Functions
Filters contents to only those matching the given language.
Returns the language prefix path segment for a given language.
Functions
@spec filter_by_lang([Sayfa.Content.t()], atom() | nil) :: [Sayfa.Content.t()]
Filters contents to only those matching the given language.
Returns the full list when lang is nil.
Examples
iex> contents = [%Sayfa.Content{title: "A", body: "", lang: :en}, %Sayfa.Content{title: "B", body: "", lang: :tr}]
iex> Sayfa.Blocks.Helpers.filter_by_lang(contents, :en) |> length()
1
iex> Sayfa.Blocks.Helpers.filter_by_lang(contents, nil) |> length()
2
Returns the language prefix path segment for a given language.
Returns "" when the language matches the site default.
Examples
iex> Sayfa.Blocks.Helpers.lang_prefix_path(nil, %{})
""