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: make all option properties optional #106

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all 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
14 changes: 7 additions & 7 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@ export type CollectionConfig = {
/**
* - One or more glob patterns to match files to a collection
*/
pattern: string | string[];
pattern?: string | string[] | null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The nulls are because the default options use them:

pattern: null,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The root change I want to correct is the ability for pattern to be omitted, such that the collection frontmatter array is used.

Proof it's optional:

if (pattern) {

I think the rest of the properties are optional as well, as I see them all given defaults.

Copy link
Member

Choose a reason for hiding this comment

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

Ah yeah good catch. I need to check if having the null makes sense. Also, currently developing new major and had to make quite some breaking changes: main...release/2.x.
Still need to wrap my head around some things, like how to make "next" and "previous" references work and how to access "all" vs "own" collections from the metadata

/**
* - A key to sort by (e.g. `date`,`title`, ..) or a custom sort function
*/
sortBy: string | ((a: any, b: any) => 0 | 1 | -1);
sortBy?: string | ((a: any, b: any) => 0 | 1 | -1);
/**
* - Limit the amount of items in a collection to `limit`
*/
limit: number;
limit?: number;
/**
* - Adds `next` and `previous` keys to file metadata of matched files
*/
refer: boolean;
refer?: boolean;
/**
* - Whether to invert the sorting function results (asc/descending)
*/
reverse: boolean;
reverse?: boolean;
/**
* - A function that gets a `Metalsmith.File` as first argument and returns `true` for every file to include in the collection
*/
filterBy: Function;
filterBy?: Function;
/**
* - An object with metadata to attach to the collection, or a `json`/`yaml`filepath string to load data from (relative to `Metalsmith.directory`)
*/
metadata: any | string;
metadata?: any | string | null;
};
/**
* Add `collections` of files to the global metadata as a sorted array.
Expand Down