Skip to content

Added ability to provide custom slug validation - #36

Open
mariusGundersen wants to merge 1 commit into
Q42:mainfrom
mariusGundersen:slugValidation
Open

Added ability to provide custom slug validation#36
mariusGundersen wants to merge 1 commit into
Q42:mainfrom
mariusGundersen:slugValidation

Conversation

@mariusGundersen

Copy link
Copy Markdown

The validation rules can be supplied either to each definePageTree option or to a new globalOptions. This also fixes the problem where the titleFieldName is preferred ahead of the slugSource provided to a specific page definition.

The validation rules can be supplied either to each `definePageTree` option or to a new `globalOptions`. This also fixes the problem where the `titleFieldName` is preferred ahead of the `slugSource` provided to a specific page definition.

@tstikvoort tstikvoort left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for opening this PR. It's a nice and useful improvement! Just have some small remarks.

];

const getSlugSourceField = (config: PageTreeConfig, options: Options) => config.titleFieldName ?? options.slugSource;
const toArray = <T>(t: undefined | T | T[]) => t === undefined ? [] : Array.isArray(t) ? t : [t];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Bit nitpicky, but could you move this to an array-utils.ts in the utils folder?

Comment thread src/types.ts
Comment on lines +39 to +44
export type GlobalOptions = {
fieldsGroupName?: string;
slugSource?: SlugOptions['source'];
slugValidationRules?: ValidationBuilder<SlugRule, SlugValue>
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Now that we expose the Options outside of the definePageType function / file, a more specific name would be better, like PageTypeOptions.

By defining in the page tree config, global is implied.

Comment thread src/types.ts
languageFieldName?: string;
};
/** Define options that apply to all pages. Can be overridden by options supplied using definePageType */
globalOptions?: GlobalOptions

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The same goes for this propertyName then.

@mariusGundersen

Copy link
Copy Markdown
Author

I'm on holiday now, so I won't be able to make any further changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants