Skip to content

Raise on duplicate entries in files in :extras#2226

Merged
josevalim merged 3 commits intoelixir-lang:mainfrom
eksperimental-forks:fix/duplicate-extras
Mar 23, 2026
Merged

Raise on duplicate entries in files in :extras#2226
josevalim merged 3 commits intoelixir-lang:mainfrom
eksperimental-forks:fix/duplicate-extras

Conversation

@eksperimental
Copy link
Copy Markdown
Contributor

@eksperimental eksperimental commented Mar 23, 2026

Duplicate entries in :extras silently produced renamed output files (e.g., readme-1.html and readme-2.html instead of readme.html), potentially breaking internal links and links from previously published versions.

Add validation that raises an ArgumentError when duplicate extras are detected. Each entry is normalized to a {source, resolved_id} pair, where resolved_id is the :filename option if provided, or the ID derived from the source path. This means:

  • Same file listed twice raises an error
  • Same file with different non-:filename options (e.g., :title) raises an error, since they produce the same output file
  • Same file with different :filename options is allowed, since they produce different output files
  • Different files that derive the same ID are not flagged, as disambiguate_id/2 already handles that case

Closes #2216

Duplicate entries in :extras silently produced renamed output files
(e.g., readme-1.html and readme-2.html instead of readme.html),
potentially breaking internal links and links from previously
published versions.

Add validation that raises an ArgumentError when duplicate extras
are detected. Each entry is normalized to a {source, resolved_id}
pair, where resolved_id is the :filename option if provided, or the
ID derived from the source path. This means:

  - Same file listed twice raises an error
  - Same file with different non-:filename options (e.g., :title)
    raises an error, since they produce the same output file
  - Same file with different :filename options is allowed, since
    they produce different output files
  - Different files that derive the same ID are not flagged, as
    disambiguate_id/2 already handles that case

Closes elixir-lang#2216
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 23, 2026

end

defp resolve_id(_input, filename) when is_binary(filename), do: filename
defp resolve_id(input, _filename), do: input |> filename_to_title() |> Utils.text_to_id()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is doing a bit of duplicate work compareed to build_extra. Can't we run this validation after we call build_extra, so we work with well-defined structs? Also, keep in mind that we have URL nodes (and those likely shouldn't be part of this validation).

Copy link
Copy Markdown
Contributor Author

@eksperimental eksperimental Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. That simplified things a WHOLE LOT. Thank you for the advice.

Duplicate detection logic logis has been simplified considerable.
Move duplicate detection to run after
build_extra/3 so it operates on ExtraNode structs instead of duplicating input-parsing logic.
URLNodes are excluded from the check since they don't produce output files.
@eksperimental
Copy link
Copy Markdown
Contributor Author

Suggestions applied.

@josevalim josevalim merged commit 974b263 into elixir-lang:main Mar 23, 2026
6 checks passed
@josevalim
Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

@eksperimental eksperimental deleted the fix/duplicate-extras branch March 23, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Duplicated entries in :extras generates no warning

2 participants