|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | + |
| 3 | +// quarto-nav.js rewrites every link on page load to clean up index.html |
| 4 | +// URLs. The rewrite must only strip index.html at the end of the path |
| 5 | +// (optionally followed by a query or fragment); hrefs that merely start |
| 6 | +// with index.html — like the index.html.md markdown twins generated for |
| 7 | +// llms.txt workflows — must be left alone (#14667). |
| 8 | +test("index.html clean-URL rewrite only strips whole path segments", async ({ page }) => { |
| 9 | + await page.goto("./website/issue-14667/_site/index.html"); |
| 10 | + |
| 11 | + // data-original-href is stamped by the rewrite loop, so waiting on it |
| 12 | + // ensures quarto-nav.js has processed the links |
| 13 | + const mdLink = page.locator("#lnk-md"); |
| 14 | + await expect(mdLink).toHaveAttribute("data-original-href", /\/index\.html\.md$/); |
| 15 | + |
| 16 | + // a link to an index.html-prefixed file must not be rewritten |
| 17 | + await expect(mdLink).toHaveAttribute("href", /\/index\.html\.md$/); |
| 18 | + |
| 19 | + // ...while genuine index.html links still get cleaned up |
| 20 | + await expect(page.locator("#lnk-clean")).toHaveAttribute("href", /\/sub\/$/); |
| 21 | + await expect(page.locator("#lnk-frag")).toHaveAttribute("href", /\/_site\/#section$/); |
| 22 | + await expect(page.locator("#lnk-query")).toHaveAttribute("href", /\/_site\/\?a=1$/); |
| 23 | + |
| 24 | + // index.html as an intermediate path segment is not the index page of |
| 25 | + // the link's directory, so it must be left alone too |
| 26 | + await expect(page.locator("#lnk-segment")).toHaveAttribute("href", /\/index\.html\/foo$/); |
| 27 | +}); |
0 commit comments