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 independent npm run build:search with the message:
Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data are supported by the default ESM loader. Received protocol 'astro:'
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.
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.