Skip to content

Redirect /subdir to /subdir/ when the page is given by docs/subdir/index.md#274

Merged
mbostock merged 3 commits intomainfrom
fil/subsection-redirect
Nov 29, 2023
Merged

Redirect /subdir to /subdir/ when the page is given by docs/subdir/index.md#274
mbostock merged 3 commits intomainfrom
fil/subsection-redirect

Conversation

@Fil
Copy link
Copy Markdown
Contributor

@Fil Fil commented Nov 29, 2023

Otherwise links seen in preview under /subdir can look correct, but will fail in the build.

To test, run:

yarn dev --root test/input/build/multi/
and open http://127.0.0.1:3000/subsection

(extracted from #257)

…dex.md.

Otherwise links seen in preview under /subdir can look correct, but will fail in the build.

To test, run:
> yarn dev --root test/input/build/multi/
and open http://127.0.0.1:3000/subsection
@Fil Fil requested a review from mbostock November 29, 2023 15:52
Copy link
Copy Markdown
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

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

This causes one more redirect than necessary in the /subdir/index and /subdir/index.html case, which first get redirected to /subdir, and then to /subdir/. Let’s add the trailing slash on L127 too?

Given a /dir/index(.html) path, we redirect the browser to /dir/ if there is a dir/index.md file, otherwise to /dir.

This accomodates /javascript in the documentation as well as test/input/build/multi/subsection/
@Fil
Copy link
Copy Markdown
Contributor Author

Fil commented Nov 29, 2023

Done. But more complicated than it seems!

Let's also remove a redundant call to await access(join(path, "index") + ".md", constants.R_OK);

@mbostock mbostock merged commit 052835b into main Nov 29, 2023
@mbostock mbostock deleted the fil/subsection-redirect branch November 29, 2023 16:54
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