Skip to content

Commit

Permalink
fix(nextra): ignore in loader files from pages/api folder (#543)
Browse files Browse the repository at this point in the history
* fix(nextra): ignore loading markdown files in `pages/api` folder

* Update packages/nextra/src/loader.ts

* Create stale-chairs-relate.md

Co-authored-by: Shu Ding <g@shud.in>
  • Loading branch information
dimaMachina and shuding committed Jul 22, 2022
1 parent 94a8587 commit c751458
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-chairs-relate.md
@@ -0,0 +1,5 @@
---
"nextra": patch
---

fix(nextra): ignore in loader files from `pages/api` folder
6 changes: 3 additions & 3 deletions packages/nextra/scripts/dev.js
@@ -1,7 +1,7 @@
const esbuild = require('esbuild')
const packageJson = require('../package.json')

console.log('Watching...')
console.log('[nextra] Watching...')

const BUILD_OPTIONS = {
platform: 'node',
Expand All @@ -11,9 +11,9 @@ const BUILD_OPTIONS = {
watch: {
onRebuild(error) {
if (error) {
console.error('Watch build failed:', error)
console.error('[nextra] Watch build failed:', error)
} else {
console.log('Watch build succeeded.')
console.log('[nextra] Watch build succeeded.')
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions packages/nextra/src/compile.ts
Expand Up @@ -89,8 +89,7 @@ export async function compileMdx(
structurizedData
}
} catch (err) {
console.error(`\nError compiling ${resourcePath}`)
console.error(`${err}\n`)
console.error(`[nextra] Error compiling ${resourcePath}.`)
throw err
}
}
2 changes: 1 addition & 1 deletion packages/nextra/src/index.js
Expand Up @@ -23,7 +23,7 @@ module.exports =

if (locales) {
console.log(
'[Nextra] You have Next.js i18n enabled, read here (TODO: link) for the docs.'
'[nextra] You have Next.js i18n enabled, read here (TODO: link) for the docs.'
)
}

Expand Down
13 changes: 9 additions & 4 deletions packages/nextra/src/loader.ts
Expand Up @@ -27,7 +27,7 @@ const [repository, gitRoot] = (function () {
const gitRoot = path.join(repo.path(), '..')
return [repo, gitRoot]
} catch (e) {
console.warn('Init git repository failed', e)
console.warn('[nextra] Init git repository failed', e)
return []
}
})()
Expand All @@ -50,6 +50,11 @@ async function loader(
} = options

const { resourcePath } = context
if (resourcePath.includes('/pages/api/')) {
console.warn(`[nextra] Ignoring ${resourcePath} because it is located in the "pages/api" folder.`)
return ''
}

const filename = resourcePath.slice(resourcePath.lastIndexOf('/') + 1)
const fileLocale = getLocaleFromFilename(filename)

Expand Down Expand Up @@ -137,15 +142,15 @@ async function loader(
if (repository.isShallow()) {
if (process.env.VERCEL) {
console.warn(
`The repository is shallow cloned, so the latest modified time will not be presented. Set the VERCEL_DEEP_CLONE=true environment variable to enable deep cloning.`
'[nextra] The repository is shallow cloned, so the latest modified time will not be presented. Set the VERCEL_DEEP_CLONE=true environment variable to enable deep cloning.'
)
} else if (process.env.GITHUB_ACTION) {
console.warn(
`The repository is shallow cloned, so the latest modified time will not be presented. See https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches to fetch all the history.`
'[nextra] The repository is shallow cloned, so the latest modified time will not be presented. See https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches to fetch all the history.'
)
} else {
console.warn(
`The repository is shallow cloned, so the latest modified time will not be presented.`
'[nextra] The repository is shallow cloned, so the latest modified time will not be presented.'
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/nextra/src/utils.ts
Expand Up @@ -23,7 +23,7 @@ export const parseJsonFile: (
try {
return JSON.parse(content)
} catch (err) {
console.error(`Error parsing ${path}, make sure it's a valid JSON \n` + err)
console.error(`[nextra] Error parsing ${path}, make sure it's a valid JSON`, err)
return {}
}
}
Expand Down

0 comments on commit c751458

Please sign in to comment.