@@ -22,18 +22,15 @@ const maybeMetaRedirect = (visit, {page}) => {
2222window . addEventListener ( 'DOMContentLoaded' , emitExdocLoaded )
2323
2424// Match links to local .html documentation pages, with or without a fragment.
25- // Routing non-HTML files (downloads such as .mmd) through SWUP breaks the page
26- // swap (#2182); the `.html#` branch keeps in-doc anchored links (function
27- // references like file.html#list_dir/1, sidebar entries) on the SWUP path.
25+ // Note we need to explicitly check for .html so we don't use swup on other
26+ // formats, such as .md, and so forth.
27+ //
28+ // We want to only apply SWUP on links without "/" (or rather "/" can only
29+ // appear in a fragment), but it is not possible to write such selector,
30+ // so we check specifically for root relative links (starting with "/" or
31+ // starting with http) in the LINK_SELECTOR and then reject any link with
32+ // "/" before the fragment in "isWithinBuild".
2833export const LINK_SELECTOR = 'a[href]:not([href^="/"]):not([href^="http"]):is([href$=".html"], [href*=".html#"])'
29-
30- // SWUP only swaps `#main`, so it must stay within a single ExDoc build: the
31- // sidebar (navigation + version) is built from per-build <head> scripts SWUP
32- // does not re-run. ExDoc writes every page of a build as a flat file in one
33- // folder, so an in-build link is a bare filename and a slash in its path means
34- // another folder/build (the Erlang/OTP docs flatten one build per application).
35- // We test the path -- the part before the fragment -- not the whole href, since
36- // anchors carry slashes too (the arity in file.html#list_dir/1).
3734export const isWithinBuild = ( href ) => ! href . split ( '#' ) [ 0 ] . includes ( '/' )
3835
3936if ( ! isEmbedded && window . location . protocol !== 'file:' ) {
0 commit comments