Skip to content
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

fix: uppercase in path #2170

Merged
merged 7 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/content/4.api/3.configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,10 @@ Toggles the document-driven mode.
| `layoutFallbacks` | `string[]` | A list of `globals` key to use to find a layout fallback. |
| `injectPage` | `boolean` | Inject `[...slug].vue` pre-configured page |
| `trailingSlash` | `boolean` | Add a slash at the end of `canonical` and `og:url` |

## `respectPathCase`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could provide an example to help dev to understand types of issues that this option can solve

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect πŸ‘Œ


- Type: `boolean`{lang=ts}
- Default: `false`{lang=ts}

Whether to respect the case of the file path when generating the route. Defaults to `false`, which means the route will be generated in lowercase. If set to `true`, the route will be generated with the same case as the file path.
9 changes: 9 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ export interface ModuleOptions {
injectPage?: boolean
trailingSlash?: boolean
},
/**
* Enable to keep uppercase characters in the generated routes.
*
* @default false
*/
respectPathCase: boolean
experimental: {
clientDB: boolean
stripQueryParameters: boolean
Expand Down Expand Up @@ -281,6 +287,7 @@ export default defineNuxtModule<ModuleOptions>({
fields: []
},
documentDriven: false,
respectPathCase: false,
experimental: {
clientDB: false,
stripQueryParameters: false
Expand Down Expand Up @@ -605,6 +612,7 @@ export default defineNuxtModule<ModuleOptions>({
stripQueryParameters: options.experimental.stripQueryParameters,
clientDB: options.experimental.clientDB && nuxt.options.ssr === false
},
respectPathCase: options.respectPathCase ?? false,
api: {
baseURL: options.api.baseURL
},
Expand Down Expand Up @@ -729,6 +737,7 @@ interface ModulePublicRuntimeConfig {
stripQueryParameters: boolean
clientDB: boolean
}
respectPathCase: boolean

defaultLocale: ModuleOptions['defaultLocale']

Expand Down
3 changes: 2 additions & 1 deletion src/runtime/transformers/path-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ const isPartial = (path: string): boolean => path.split(/[:/]/).some(part => par
* @returns generated slug
*/
export const generatePath = (path: string, { forceLeadingSlash = true } = {}): string => {
path = path.split('/').map(part => slugify(refineUrlPart(part), { lower: true })).join('/')
const { content } = useRuntimeConfig().public
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid using Nuxt generated helpers (like useRuntimeConfig) in transformers. Transformers and in general the content parser could be able to work outside of Nuxt Context.

There is already several usecases of parser outside of Nuxt.

respectPathCase could be passed in second argumant of this function and transformer itseld

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I've now moved it into the options of the transformer.

path = path.split('/').map(part => slugify(refineUrlPart(part), { lower: !content.respectPathCase })).join('/')
return forceLeadingSlash ? withLeadingSlash(withoutTrailingSlash(path)) : path
}

Expand Down