Skip to content

Commit

Permalink
chore: move to transformer options
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannchie committed Jul 17, 2023
1 parent 76cde2a commit 4d47939
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/runtime/server/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface ParseContentOptions {
pathMeta?: {
locales?: ModuleOptions['locales']
defaultLocale?: ModuleOptions['defaultLocale']
respectPathCase?: ModuleOptions['respectPathCase']
}
// Allow passing options for custom transformers
[key: string]: any
Expand Down Expand Up @@ -173,7 +174,8 @@ export async function parseContent (id: string, content: string, opts: ParseCont
transformers: customTransformers,
pathMeta: {
defaultLocale: contentConfig.defaultLocale,
locales: contentConfig.locales
locales: contentConfig.locales,
respectPathCase: contentConfig.respectPathCase
}
}
)
Expand Down
11 changes: 4 additions & 7 deletions src/runtime/transformers/path-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ export default defineTransformer({
name: 'path-meta',
extensions: ['.*'],
transform (content, options: any = {}) {
const { locales = [], defaultLocale = 'en' } = options
const { locales = [], defaultLocale = 'en', respectPathCase = false } = options
const { _source, _file, _path, _extension } = describeId(content._id)
const parts = _path.split('/')

// Check first part for locale name
const _locale = locales.includes(parts[0]) ? parts.shift() : defaultLocale

const filePath = generatePath(parts.join('/'))
const filePath = generatePath(parts.join('/'), { respectPathCase })

return <ParsedContent> {
_path: filePath,
Expand Down Expand Up @@ -66,9 +64,8 @@ const isPartial = (path: string): boolean => path.split(/[:/]/).some(part => par
* @param path file full path
* @returns generated slug
*/
export const generatePath = (path: string, { forceLeadingSlash = true } = {}): string => {
const { content } = useRuntimeConfig().public
path = path.split('/').map(part => slugify(refineUrlPart(part), { lower: !content.respectPathCase })).join('/')
export const generatePath = (path: string, { forceLeadingSlash = true, respectPathCase = false } = {}): string => {
path = path.split('/').map(part => slugify(refineUrlPart(part), { lower: !respectPathCase })).join('/')
return forceLeadingSlash ? withLeadingSlash(withoutTrailingSlash(path)) : path
}

Expand Down

0 comments on commit 4d47939

Please sign in to comment.