-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import Metalsmith from "metalsmith"; | ||
|
||
export default initializeCollections; | ||
export type CollectionConfig = { | ||
/** | ||
* - One or more glob patterns to match files to a collection | ||
*/ | ||
pattern: string | string[]; | ||
/** | ||
* - A key to sort by (e.g. `date`,`title`, ..) or a custom sort function | ||
*/ | ||
sortBy: string | ((a: any, b: any) => 0 | 1 | -1); | ||
/** | ||
* - Limit the amount of items in a collection to `limit` | ||
*/ | ||
limit: number; | ||
/** | ||
* - Adds `next` and `previous` keys to file metadata of matched files | ||
*/ | ||
refer: boolean; | ||
/** | ||
* - Whether to invert the sorting function results (asc/descending) | ||
*/ | ||
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; | ||
/** | ||
* - 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; | ||
}; | ||
/** | ||
* Add `collections` of files to the global metadata as a sorted array. | ||
* @example | ||
* metalsmith.use(collections({ | ||
* posts: 'posts/*.md', | ||
* portfolio: { | ||
* pattern: 'portfolio/*.md', | ||
* metadata: { title: 'My portfolio' }, | ||
* sortBy: 'order' | ||
* } | ||
* })) | ||
* | ||
* @param {Object.<string,CollectionConfig|string>} options | ||
*/ | ||
declare function initializeCollections(options: { | ||
[x: string]: CollectionConfig | string; | ||
}): Metalsmith.Plugin; | ||
declare namespace initializeCollections { | ||
export { defaultOptions as defaults }; | ||
} | ||
|
||
declare const defaultOptions: CollectionConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters