fix(microprints): limit page to 2 most recently modified files

- Sort source files by mtime (newest first) and take only the first 2
- This limits the page scope for easier testing/investigation
- Temporary limit; will be 10 most recently changed files later
- Updated tests to work with the 2-file limit
This commit is contained in:
2026-05-15 16:21:11 +01:00
parent 5a9940c082
commit f01cdf918a
3 changed files with 29 additions and 10 deletions
+15 -7
View File
@@ -123,25 +123,33 @@ defmodule FirehoseWeb.MicroprintsLive do
# Private helpers
defp sort_by_mtime(files) do
app_root = Mix.Project.project_file() |> Path.dirname()
files
|> Enum.map(fn file ->
abs_path = Path.join(app_root, file)
{file, File.stat!(abs_path).mtime}
end)
|> Enum.sort_by(fn {_file, mtime} -> mtime end, :desc)
|> Enum.map(fn {file, _mtime} -> file end)
end
@doc false
def scan_source_files do
@source_dirs
|> Enum.flat_map(&collect_elixir_files/1)
|> Enum.uniq()
|> Enum.sort()
|> sort_by_mtime()
|> Enum.take(2)
end
defp resolve_absolute_paths(files) do
app_root = Mix.Project.project_file() |> Path.dirname()
Enum.map(files, fn path ->
case Path.split(path) do
[".." | _rest] ->
Path.join(app_root, path)
_ ->
Path.expand(path)
end
Path.join(app_root, path)
end)
end