Skip to content

Commit

Permalink
add renumberFilenames next plugin option
Browse files Browse the repository at this point in the history
  • Loading branch information
souporserious committed May 4, 2024
1 parent eadd96d commit 0e2cc45
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-dots-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"mdxts": minor
---

Adds a `renumberFilenames` option to the next plugin for configuring whether or not to renumber filenames when adding/removing/modifying ordered content.
15 changes: 12 additions & 3 deletions packages/mdxts/src/next/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ type PluginOptions = {
/** The branch to use for linking to the repository and source files. */
gitBranch?: string

/** Whether or not to renumber ordered filenames (e.g. 01.getting-started) when adding/removing/modifying MDX files. This only occurs while the development server is running. */
renumberFilenames?: boolean

/** Whether or not to add rich highlighted errors in the console when type-checking source code in `CodeBlock`. Note, this may affect framework error boundaries that don't understand color encoding. */
highlightErrors?: boolean
}
Expand All @@ -34,6 +37,7 @@ export function createMdxtsPlugin(pluginOptions: PluginOptions) {
gitBranch = 'main',
siteUrl,
theme,
renumberFilenames: renumberFilenamesOption = true,
highlightErrors,
} = pluginOptions
const themePath = theme.endsWith('.json')
Expand All @@ -42,7 +46,7 @@ export function createMdxtsPlugin(pluginOptions: PluginOptions) {

return function withMdxts(nextConfig: NextConfig = {}) {
const getWebpackConfig = nextConfig.webpack
let startedWatcher = false
let startedRenumberFilenameWatcher = false

return async (phase: typeof PHASE_DEVELOPMENT_SERVER) => {
const plugins = await getMdxPlugins({ gitSource, gitBranch })
Expand Down Expand Up @@ -72,9 +76,14 @@ export function createMdxtsPlugin(pluginOptions: PluginOptions) {
})
)

if (options.isServer && options.dev && !startedWatcher) {
if (
!startedRenumberFilenameWatcher &&
renumberFilenamesOption &&
options.isServer &&
options.dev
) {
renumberFilenames()
startedWatcher = true
startedRenumberFilenameWatcher = true
}

config.module.rules.push({
Expand Down

0 comments on commit 0e2cc45

Please sign in to comment.