adding a postbuild step to allow a trailing slash to resolve index pages#268
adding a postbuild step to allow a trailing slash to resolve index pages#268
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds a post-build step to handle trailing slash URL resolution by copying HTML files to index.html files in corresponding directories. This allows URLs with trailing slashes (e.g., /myPath/) to resolve to the same content as URLs without trailing slashes (e.g., /myPath).
- Adds a new post-build script that walks through the build directory and creates index.html files
- Integrates the post-build script into the build command in package.json
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| scripts/postbuild.js | New script that creates index.html files from sibling HTML files to support trailing slash URLs |
| package.json | Updates build command to run the post-build script after Docusaurus build |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
going to merge now to get the 404 issue resolved in prod |
|
|
||
| // Walk through all directories recursively | ||
| async function* walkDirs(dir) { | ||
| const dirents = await fs.readdir(dir, { withFileTypes: true }); |
There was a problem hiding this comment.
https://nodejs.org/docs/latest/api/fs.html#fspromisesreaddirpath-options
FWIW you could use the recursive option for fs.readdir
| // Check if there's already an index.html in this directory | ||
| const indexPath = path.join(dirPath, 'index.html'); | ||
| try { | ||
| await fs.stat(indexPath); |
There was a problem hiding this comment.
Should use fs.access() instead if you don't actually care for the result of stat. access is faster
Fixes #263. This is based on a recommended solution: https://github.com/slorber/trailing-slash-guide/blob/main/docs/Solutions.md#post-process-your-static-site-generator-output-before-deployment