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 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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` |

## `keepUppercase`

- Type: `Boolean`{lang=ts}
Jannchie marked this conversation as resolved.
Show resolved Hide resolved
- Default: `false`{lang=ts}

Whether to keep uppercase characters in the generated routes.
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
*/
keepUppercase: boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

This name may be too vague since we do not understand it's related to path.

Maybe something like respectPathCase, when false, it lower case or respectFilenameCase

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've rename the name to respectPathCase.

experimental: {
clientDB: boolean
stripQueryParameters: boolean
Expand Down Expand Up @@ -281,6 +287,7 @@ export default defineNuxtModule<ModuleOptions>({
fields: []
},
documentDriven: false,
keepUppercase: 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
},
keepUppercase: options.keepUppercase ?? false,
api: {
baseURL: options.api.baseURL
},
Expand Down Expand Up @@ -729,6 +737,7 @@ interface ModulePublicRuntimeConfig {
stripQueryParameters: boolean
clientDB: boolean
}
keepUppercase: 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.keepUppercase })).join('/')
return forceLeadingSlash ? withLeadingSlash(withoutTrailingSlash(path)) : path
}

Expand Down