Skip to content

Commit

Permalink
fix 404 from search result (shuding#2181)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina committed Aug 19, 2023
1 parent 778b13f commit e0256d4
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions src/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
CODE_BLOCK_FILENAME_REGEX,
CWD,
DEFAULT_LOCALE,
ERROR_ROUTES,
MARKDOWN_URL_EXTENSION_REGEX
} from './constants'
import {
Expand Down Expand Up @@ -90,22 +91,35 @@ export async function compileMdx(

const structurizedData = Object.create(null)

const {
staticImage,
flexsearch,
readingTime,
latex,
codeHighlight,
defaultShowCopyCode,
route = '',
locale,
mdxOptions
} = loaderOptions

let searchIndexKey: string | null = null
if (typeof loaderOptions.flexsearch === 'object') {
if (loaderOptions.flexsearch.indexKey) {
searchIndexKey = loaderOptions.flexsearch.indexKey(
filePath,
loaderOptions.route || '',
loaderOptions.locale
)
if (
ERROR_ROUTES.has(route) ||
route === '/_app' /* remove this check in v3 */
) {
/* skip */
} else if (typeof flexsearch === 'object') {
if (flexsearch.indexKey) {
searchIndexKey = flexsearch.indexKey(filePath, route, locale)
if (searchIndexKey === '') {
searchIndexKey = loaderOptions.locale || DEFAULT_LOCALE
searchIndexKey = locale || DEFAULT_LOCALE
}
} else {
searchIndexKey = loaderOptions.locale || DEFAULT_LOCALE
searchIndexKey = locale || DEFAULT_LOCALE
}
} else if (loaderOptions.flexsearch) {
searchIndexKey = loaderOptions.locale || DEFAULT_LOCALE
} else if (flexsearch) {
searchIndexKey = locale || DEFAULT_LOCALE
}

const {
Expand All @@ -116,23 +130,14 @@ export async function compileMdx(
rehypePlugins,
rehypePrettyCodeOptions
}: MdxOptions = {
...loaderOptions.mdxOptions,
...mdxOptions,
// You can override MDX options in the frontMatter too.
...frontMatter.mdxOptions
}

const format =
_format === 'detect' ? (filePath.endsWith('.mdx') ? 'mdx' : 'md') : _format

const {
staticImage,
flexsearch,
readingTime,
latex,
codeHighlight,
defaultShowCopyCode
} = loaderOptions

// https://github.com/shuding/nextra/issues/1303
const isFileOutsideCWD =
!isPageImport && path.relative(CWD, filePath).startsWith('..')
Expand Down

0 comments on commit e0256d4

Please sign in to comment.