Apply /reference path replacements to search index build scripts. #488
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This resolves #485, which was caused by the paths of items in subfolders of the reference directory being modified in the Astro router but not in the search index build scripts generating the relative URLs to each search result. To address this, I've moved the string replacement previously happening in normalizeReferenceRoute to a separate function which I then used in the search index build scripts to apply the same transformation.
One small caveat — I had trouble importing any function from the pages/_utils.ts file in the search build script due to the astro:content dependencies included in that file, so I moved this function to the pages/_utils-node.ts file, which is probably not a huge deal but maybe worth noting as it doesn't technically rely on any runtime node dependencies. With the function in the pages/_utils.ts file the build would work perfectly through the total
npm run build
/astro build
, but fail on the independentnpm run build:search
with the message:Moving the function to the other utils file solved this, and this standardization solves the issue with the links to any items from the constants or types section 404ing, but maybe I'm missing an easier way that would let that function live in the same file it's getting used for the router and still be imported to the search builder.