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

Added ability to provide custom slug validation #36

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mariusGundersen
Copy link

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.
Copy link
Member

@tstikvoort tstikvoort left a comment

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.

@@ -79,3 +81,4 @@ const basePageFields = (config: PageTreeConfig, options: Options, ownType: Docum
];

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
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 on lines +39 to +44
export type GlobalOptions = {
fieldsGroupName?: string;
slugSource?: SlugOptions['source'];
slugValidationRules?: ValidationBuilder<SlugRule, SlugValue>
}

Copy link
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.

languageFieldName?: string;
};
/** Define options that apply to all pages. Can be overridden by options supplied using definePageType */
globalOptions?: GlobalOptions
Copy link
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
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