close
Skip to content

Fix URL remapping for page references#1395

Merged
jonludlam merged 2 commits into
ocaml:masterfrom
jonludlam:fix-page-remap
Mar 11, 2026
Merged

Fix URL remapping for page references#1395
jonludlam merged 2 commits into
ocaml:masterfrom
jonludlam:fix-page-remap

Conversation

@jonludlam
Copy link
Copy Markdown
Member

Page links were not being remapped because the remap prefix check only matched against the directory path. For modules, the module name is part of the directory (e.g., prefix/otherpkg/Otherlib/index.html), so it matched. But for pages, the page name is in the filename (e.g., prefix/otherpkg/otherpage.html), leaving only prefix/otherpkg in the directory - which didn't match prefix/otherpkg/ due to the trailing slash.

Fix by including the filename in the path used for prefix matching. Also normalize remap entries at config creation time (ensure trailing slashes) rather than on each lookup.

🤖 Generated with Claude Code

Comment thread src/html/config.ml
}

let ensure_trailing_slash s =
if Astring.String.is_suffix ~affix:"/" s then s else s ^ "/"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think a possibly long list of string with requirements in them is the right data structure.
I think a Trie structure would be better.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

True, though this PR doesn't change that. It'll be a good future improvement.

Comment thread src/html/link.ml
Comment on lines +30 to +31
String.sub path (String.length prefix)
(String.length path - String.length prefix)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is also Astring.String.with_range ~first:(String.length prefix) path.

jonludlam and others added 2 commits March 10, 2026 16:46
Page links were not being remapped because the remap prefix check
only matched against the directory path. For modules, the module name
is part of the directory (e.g., prefix/otherpkg/Otherlib/index.html),
so it matched. But for pages, the page name is in the filename
(e.g., prefix/otherpkg/otherpage.html), leaving only prefix/otherpkg
in the directory - which didn't match prefix/otherpkg/ due to the
trailing slash.

Fix by including the filename in the path used for prefix matching.
Also normalize remap entries at config creation time (ensure trailing
slashes) rather than on each lookup.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jonludlam jonludlam merged commit f1256cc into ocaml:master Mar 11, 2026
11 checks passed
jonludlam added a commit to jonludlam/opam-repository that referenced this pull request May 1, 2026
CHANGES:

- Allow persistent latex macros in HTML/KaTeX backend (@dlesbre, ocaml/odoc#1391)
- `markdown-generate` command now accepts multiple `.odocl` files in a single
  invocation, eliminating the need for shell scripting (@davesnx, ocaml/odoc#1387)
- Support for OxCaml (@lukemaurer, @art-w, ocaml/odoc#1399)
- OCaml 5.5.0 support (@panglesd, @xvw, ocaml/odoc#1406)

- Fix compile-time crashing bugs ocaml/odoc#930 and ocaml/odoc#1385 (@jonludlam, ocaml/odoc#1400)
- Markdown backend assumes ocaml as langId on declarations
- Markdown backend collects all code snippets and render a single code block with comments, rather than split the variants/records per constructor/field
- Fix URL remapping for page references (@jonludlam, ocaml/odoc#1395)
- Fix ocaml/odoc#1396, which broke incrememntal builds (@jonludlam, ocaml/odoc#1402)
- Ensure all warnings turn into errors with --warn-error (@jonludlam, ocaml/odoc#1402)
- Fix missing parentheses for polymorphic arguments (@art-w, ocaml/odoc#1404)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants