-
-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The Astro plugin is not compatible with Astro 5 #862
Comments
Changing the method from async function prepareOramaDb(
dbConfig: OramaOptions,
pages: AstroPage[],
routes: RouteData[],
dir: URL
): Promise<Orama<PageIndexSchema, any, any, any>> {
const contentConverter = compile({
baseElements: {
selectors: dbConfig.contentSelectors?.length ? dbConfig.contentSelectors : ['body']
}
})
// All routes are in the same folder, we can use the first one to get the basePath
const basePath = dir.pathname.slice(isWindows ? 1 : 0)
const pathsToBeIndexed = pages
.filter(({ pathname }) => dbConfig.pathMatcher.test(pathname))
.map(({ pathname }) => {
// Some pages like 404 are generated as 404.html while others are usually pageName/index.html
const matchingPathname = routes
.find((r) => r.distURL?.pathname.endsWith(pathname.replace(/\/$/, '') + '.html'))
?.distURL?.pathname?.slice(isWindows ? 1 : 0)
return {
pathname,
generatedFilePath: matchingPathname ?? `${basePath}${pathname.replace(/\/+$/, '')}/index.html`
}
})
.filter(({ generatedFilePath }) => !!generatedFilePath) to the one below should do it, so instead of looking directly in async function prepareOramaDb(
dbConfig: OramaOptions,
pages: AstroPage[],
routes: RouteData[],
dir: URL
): Promise<Orama<PageIndexSchema, any, any, any>> {
const contentConverter = compile({
baseElements: {
selectors: dbConfig.contentSelectors?.length ? dbConfig.contentSelectors : ['body']
}
})
// All routes are in the same folder, we can use the first one to get the basePath
const basePath = dir.pathname.slice(isWindows ? 1 : 0)
// Create a dist urls
const distUrls = routes.flatMap(r => r.distURL);
const pathsToBeIndexed = pages
.filter(({ pathname }) => dbConfig.pathMatcher.test(pathname))
.map(({ pathname }) => {
// Some pages like 404 are generated as 404.html while others are usually pageName/index.html
const matchingPathname = distUrls
.find((url) => url?.pathname.endsWith(pathname.replace(/\/$/, '') + '.html'))?.pathname?.slice(isWindows ? 1 : 0)
return {
pathname,
generatedFilePath: matchingPathname ?? `${basePath}${pathname.replace(/\/+$/, '')}/index.html`
}
})
.filter(({ generatedFilePath }) => !!generatedFilePath) |
Hey @alexisreina thanks for opening this. Would you mind opening a PR with your proposed changes? We'd be glad to help debugging and landing the PR in the next release 🙏 |
@micheleriva, I was trying to submit a PR for this, but my clone doesn't pass |
Describe the bug
Astro 5 introduces breaking changes that affect this plugin. According to astro documentation:
"Astro v5.0 updates the shape of IntegrationRouteData.distURL to be undefined or an array of URLs. This fixes a previous error because a route can generate multiple files on disk, especially when using dynamic routes such as [slug] or [...slug]"
This change made to the
distUrl
used by the pluginprepareOramaDb
causes the plugin to throw the following error before completing:To Reproduce
Expected behavior
The porject builds and the orama db is created
Environment Info
Affected areas
Initialization
Additional context
After reviewing the code looks like an easy fix that can be done backwards compatible so it won't require a major relase of the plugin
The text was updated successfully, but these errors were encountered: