@metalsmith/collections 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.cjs +11 -10
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.ts +10 -10
- package/lib/index.js +11 -10
- package/lib/index.js.map +1 -0
- package/package.json +3 -2
package/lib/index.cjs
CHANGED
|
@@ -32,13 +32,13 @@ const defaultSort = sortBy('date');
|
|
|
32
32
|
const defaultFilter = () => true;
|
|
33
33
|
/**
|
|
34
34
|
* @typedef {Object} CollectionConfig
|
|
35
|
-
* @property {string|string[]} pattern - One or more glob patterns to match files to a collection
|
|
36
|
-
* @property {string|(a,b) => 0|1|-1} sortBy - A key to sort by (e.g. `date`,`title`, ..) or a custom sort function
|
|
37
|
-
* @property {number} limit - Limit the amount of items in a collection to `limit`
|
|
38
|
-
* @property {boolean} refer - Adds `next` and `previous` keys to file metadata of matched files
|
|
39
|
-
* @property {boolean} reverse - Whether to invert the sorting function results (asc/descending)
|
|
40
|
-
* @property {Function} filterBy - A function that gets a `Metalsmith.File` as first argument and returns `true` for every file to include in the collection
|
|
41
|
-
* @property {Object|string} metadata - An object with metadata to attach to the collection, or a `json`/`yaml`filepath string to load data from (relative to `Metalsmith.directory`)
|
|
35
|
+
* @property {string|string[]} [pattern] - One or more glob patterns to match files to a collection
|
|
36
|
+
* @property {string|(a,b) => 0|1|-1} [sortBy] - A key to sort by (e.g. `date`,`title`, ..) or a custom sort function
|
|
37
|
+
* @property {number} [limit] - Limit the amount of items in a collection to `limit`
|
|
38
|
+
* @property {boolean} [refer] - Adds `next` and `previous` keys to file metadata of matched files
|
|
39
|
+
* @property {boolean} [reverse] - Whether to invert the sorting function results (asc/descending)
|
|
40
|
+
* @property {Function} [filterBy] - A function that gets a `Metalsmith.File` as first argument and returns `true` for every file to include in the collection
|
|
41
|
+
* @property {Object|string} [metadata] - An object with metadata to attach to the collection, or a `json`/`yaml`filepath string to load data from (relative to `Metalsmith.directory`)
|
|
42
42
|
*/
|
|
43
43
|
|
|
44
44
|
/** @type {CollectionConfig} */
|
|
@@ -102,7 +102,7 @@ function normalizeOptions(options) {
|
|
|
102
102
|
*/
|
|
103
103
|
|
|
104
104
|
|
|
105
|
-
function
|
|
105
|
+
function collections(options) {
|
|
106
106
|
options = normalizeOptions(options);
|
|
107
107
|
const collectionNames = Object.keys(options);
|
|
108
108
|
const mappedCollections = collectionNames.map(name => {
|
|
@@ -216,6 +216,7 @@ function initializeCollections(options) {
|
|
|
216
216
|
};
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
|
|
219
|
+
collections.defaults = defaultOptions;
|
|
220
220
|
|
|
221
|
-
module.exports =
|
|
221
|
+
module.exports = collections;
|
|
222
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/index.js"],"sourcesContent":["import get from 'lodash.get'\nimport { sync as loadMetadata } from 'read-metadata'\n\nfunction sortBy(key) {\n let getKey = (x) => x[key]\n if (key.includes('.')) {\n getKey = (x) => get(x, key)\n }\n return function defaultSort(a, b) {\n a = getKey(a)\n b = getKey(b)\n if (!a && !b) return 0\n if (!a) return -1\n if (!b) return 1\n if (b > a) return -1\n if (a > b) return 1\n return 0\n }\n}\n\n// for backwards-compatibility only, date makes as little sense as \"pubdate\" or any custom key\nconst defaultSort = sortBy('date')\nconst defaultFilter = () => true\n\n/**\n * @typedef {Object} CollectionConfig\n * @property {string|string[]} [pattern] - One or more glob patterns to match files to a collection\n * @property {string|(a,b) => 0|1|-1} [sortBy] - A key to sort by (e.g. `date`,`title`, ..) or a custom sort function\n * @property {number} [limit] - Limit the amount of items in a collection to `limit`\n * @property {boolean} [refer] - Adds `next` and `previous` keys to file metadata of matched files\n * @property {boolean} [reverse] - Whether to invert the sorting function results (asc/descending)\n * @property {Function} [filterBy] - A function that gets a `Metalsmith.File` as first argument and returns `true` for every file to include in the collection\n * @property {Object|string} [metadata] - An object with metadata to attach to the collection, or a `json`/`yaml`filepath string to load data from (relative to `Metalsmith.directory`)\n */\n\n/** @type {CollectionConfig} */\nconst defaultOptions = {\n pattern: null,\n reverse: false,\n metadata: null,\n limit: Infinity,\n refer: true,\n sortBy: defaultSort,\n filterBy: defaultFilter\n}\n\n/**\n * Normalize options\n * @param {Object.<string,CollectionConfig>} options\n */\nfunction normalizeOptions(options) {\n options = options || {}\n\n for (const config in options) {\n let normalized = options[config]\n if (typeof normalized === 'string' || Array.isArray(normalized)) {\n normalized = { pattern: normalized }\n }\n normalized = Object.assign({}, defaultOptions, normalized)\n if (typeof normalized.metadata === 'string') {\n normalized.metadata = loadMetadata(normalized.metadata)\n }\n if (typeof normalized.sortBy === 'string') {\n normalized.sortBy = sortBy(normalized.sortBy)\n }\n options[config] = normalized\n }\n\n return options\n}\n\n/**\n * Add `collections` of files to the global metadata as a sorted array.\n * @example\n * metalsmith.use(collections({\n * posts: 'posts/*.md',\n * portfolio: {\n * pattern: 'portfolio/*.md',\n * metadata: { title: 'My portfolio' },\n * sortBy: 'order'\n * }\n * }))\n *\n * @param {Object.<string,CollectionConfig|string>} options\n * @return {import('metalsmith').Plugin}\n */\nfunction collections(options) {\n options = normalizeOptions(options)\n const collectionNames = Object.keys(options)\n const mappedCollections = collectionNames.map((name) => {\n return Object.assign({ name: name }, options[name])\n })\n\n return function collections(files, metalsmith, done) {\n const metadata = metalsmith.metadata()\n const fileNames = Object.keys(files)\n const debug = metalsmith.debug('@metalsmith/collections')\n\n metadata.collections = {}\n\n fileNames.forEach((filePath) => {\n // add path property to file metadata for convenience\n // this is for backward-compatibility only and is pretty useless\n const file = files[filePath]\n file.path = file.path || filePath\n\n // dynamically add collections with default options when encountered in file metadata,\n // and not explicitly defined in plugin options\n if (file.collection) {\n ;(Array.isArray(file.collection) ? file.collection : [file.collection]).forEach((name) => {\n if (!collectionNames.includes(name)) {\n collectionNames.push(name)\n const normalized = Object.assign({}, defaultOptions)\n mappedCollections.push(Object.assign({ name }, normalized))\n }\n })\n }\n })\n\n debug('Identified %s collections: %s', mappedCollections.length, collectionNames.join())\n\n mappedCollections.forEach((collection) => {\n const { pattern, filterBy, sortBy, reverse, refer, limit } = collection\n const name = collection.name\n const matches = []\n debug('Processing collection %s with options %s:', name, collection)\n\n // first match by pattern if provided\n if (pattern) {\n matches.push.apply(\n matches,\n metalsmith.match(pattern, fileNames).map((filepath) => {\n const data = files[filepath]\n // pattern-matched files might or might not have a \"collection\" property defined in front-matter\n // and might also be included in multiple collections\n if (!data.collection) {\n data.collection = []\n } else if (typeof data.collection === 'string') {\n data.collection = [data.collection]\n }\n if (!data.collection.includes(collection.name)) {\n data.collection = [...data.collection, collection.name]\n }\n return data\n })\n )\n }\n\n // next match by \"collection\" key, but only push if the files haven't been added through pattern matching first\n matches.push.apply(\n matches,\n Object.values(files).filter((file) => {\n const patternMatched = matches.includes(file)\n const isInCollection = Array.isArray(file.collection)\n ? file.collection.includes(collection.name)\n : file.collection === collection.name\n return !patternMatched && isInCollection\n })\n )\n\n if (Object.prototype.hasOwnProperty.call(metadata, name)) {\n debug('Warning: overwriting previously set metadata property %s', name)\n }\n // apply sort, reverse, filter, limit options in this order\n metadata[name] = matches.sort(sortBy)\n\n if (reverse) {\n metadata[name].reverse()\n }\n\n metadata[name] = metadata[name].filter(filterBy).slice(0, limit)\n\n if (collection.metadata) {\n metadata[name].metadata = collection.metadata\n }\n if (refer) {\n if (reverse) {\n metadata[name].forEach((file, i) => {\n Object.assign(file, {\n next: i > 0 ? metadata[name][i - 1] : null,\n previous: i < metadata[name].length - 1 ? metadata[name][i + 1] : null\n })\n })\n } else {\n metadata[name].forEach((file, i) => {\n Object.assign(file, {\n previous: i > 0 ? metadata[name][i - 1] : null,\n next: i < metadata[name].length - 1 ? metadata[name][i + 1] : null\n })\n })\n }\n }\n\n metadata.collections[name] = metadata[name]\n debug('Added %s files to collection %s', metadata[name].length, name)\n })\n done()\n }\n}\n\ncollections.defaults = defaultOptions\n\nexport default collections\n"],"names":["sortBy","key","getKey","x","includes","get","defaultSort","a","b","defaultFilter","defaultOptions","pattern","reverse","metadata","limit","Infinity","refer","filterBy","normalizeOptions","options","config","normalized","Array","isArray","Object","assign","loadMetadata","collections","collectionNames","keys","mappedCollections","map","name","files","metalsmith","done","fileNames","debug","forEach","filePath","file","path","collection","push","length","join","matches","apply","match","filepath","data","values","filter","patternMatched","isInCollection","prototype","hasOwnProperty","call","sort","slice","i","next","previous","defaults"],"mappings":";;;;;;;;;AAGA,SAASA,MAAT,CAAgBC,GAAhB,EAAqB;AACnB,EAAA,IAAIC,MAAM,GAAIC,CAAD,IAAOA,CAAC,CAACF,GAAD,CAArB,CAAA;;AACA,EAAA,IAAIA,GAAG,CAACG,QAAJ,CAAa,GAAb,CAAJ,EAAuB;IACrBF,MAAM,GAAIC,CAAD,IAAOE,uBAAG,CAACF,CAAD,EAAIF,GAAJ,CAAnB,CAAA;AACD,GAAA;;AACD,EAAA,OAAO,SAASK,WAAT,CAAqBC,CAArB,EAAwBC,CAAxB,EAA2B;AAChCD,IAAAA,CAAC,GAAGL,MAAM,CAACK,CAAD,CAAV,CAAA;AACAC,IAAAA,CAAC,GAAGN,MAAM,CAACM,CAAD,CAAV,CAAA;AACA,IAAA,IAAI,CAACD,CAAD,IAAM,CAACC,CAAX,EAAc,OAAO,CAAP,CAAA;AACd,IAAA,IAAI,CAACD,CAAL,EAAQ,OAAO,CAAC,CAAR,CAAA;AACR,IAAA,IAAI,CAACC,CAAL,EAAQ,OAAO,CAAP,CAAA;AACR,IAAA,IAAIA,CAAC,GAAGD,CAAR,EAAW,OAAO,CAAC,CAAR,CAAA;AACX,IAAA,IAAIA,CAAC,GAAGC,CAAR,EAAW,OAAO,CAAP,CAAA;AACX,IAAA,OAAO,CAAP,CAAA;GARF,CAAA;AAUD;;;AAGD,MAAMF,WAAW,GAAGN,MAAM,CAAC,MAAD,CAA1B,CAAA;;AACA,MAAMS,aAAa,GAAG,MAAM,IAA5B,CAA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,QAAQ,EAAEF,CAAC,GAAG,CAAJ,GAAQ/C,QAAQ,CAACmB,IAAD,CAAR,CAAe4B,CAAC,GAAG,CAAnB,CAAR,GAAgC,IADxB;cAElBC,IAAI,EAAED,CAAC,GAAG/C,QAAQ,CAACmB,IAAD,CAAR,CAAeY,MAAf,GAAwB,CAA5B,GAAgC/B,QAAQ,CAACmB,IAAD,CAAR,CAAe4B,CAAC,GAAG,CAAnB,CAAhC,GAAwD,IAAA;aAFhE,CAAA,CAAA;WADF,CAAA,CAAA;AAMD,SAAA;AACF,OAAA;;MAED/C,QAAQ,CAACc,WAAT,CAAqBK,IAArB,IAA6BnB,QAAQ,CAACmB,IAAD,CAArC,CAAA;MACAK,KAAK,CAAC,iCAAD,EAAoCxB,QAAQ,CAACmB,IAAD,CAAR,CAAeY,MAAnD,EAA2DZ,IAA3D,CAAL,CAAA;KAzEF,CAAA,CAAA;IA2EAG,IAAI,EAAA,CAAA;GAvGN,CAAA;AAyGD,CAAA;;AAEDR,WAAW,CAACoC,QAAZ,GAAuBrD,cAAvB;;;;"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import Metalsmith from "metalsmith";
|
|
2
2
|
|
|
3
|
-
export default
|
|
3
|
+
export default collections;
|
|
4
4
|
export type CollectionConfig = {
|
|
5
5
|
/**
|
|
6
6
|
* - One or more glob patterns to match files to a collection
|
|
7
7
|
*/
|
|
8
|
-
pattern
|
|
8
|
+
pattern?: string | string[] | null;
|
|
9
9
|
/**
|
|
10
10
|
* - A key to sort by (e.g. `date`,`title`, ..) or a custom sort function
|
|
11
11
|
*/
|
|
12
|
-
sortBy
|
|
12
|
+
sortBy?: string | ((a: any, b: any) => 0 | 1 | -1);
|
|
13
13
|
/**
|
|
14
14
|
* - Limit the amount of items in a collection to `limit`
|
|
15
15
|
*/
|
|
16
|
-
limit
|
|
16
|
+
limit?: number;
|
|
17
17
|
/**
|
|
18
18
|
* - Adds `next` and `previous` keys to file metadata of matched files
|
|
19
19
|
*/
|
|
20
|
-
refer
|
|
20
|
+
refer?: boolean;
|
|
21
21
|
/**
|
|
22
22
|
* - Whether to invert the sorting function results (asc/descending)
|
|
23
23
|
*/
|
|
24
|
-
reverse
|
|
24
|
+
reverse?: boolean;
|
|
25
25
|
/**
|
|
26
26
|
* - A function that gets a `Metalsmith.File` as first argument and returns `true` for every file to include in the collection
|
|
27
27
|
*/
|
|
28
|
-
filterBy
|
|
28
|
+
filterBy?: Function;
|
|
29
29
|
/**
|
|
30
30
|
* - An object with metadata to attach to the collection, or a `json`/`yaml`filepath string to load data from (relative to `Metalsmith.directory`)
|
|
31
31
|
*/
|
|
32
|
-
metadata
|
|
32
|
+
metadata?: any | string | null;
|
|
33
33
|
};
|
|
34
34
|
/**
|
|
35
35
|
* Add `collections` of files to the global metadata as a sorted array.
|
|
@@ -45,10 +45,10 @@ export type CollectionConfig = {
|
|
|
45
45
|
*
|
|
46
46
|
* @param {Object.<string,CollectionConfig|string>} options
|
|
47
47
|
*/
|
|
48
|
-
declare function
|
|
48
|
+
declare function collections(options: {
|
|
49
49
|
[x: string]: CollectionConfig | string;
|
|
50
50
|
}): Metalsmith.Plugin;
|
|
51
|
-
declare namespace
|
|
51
|
+
declare namespace collections {
|
|
52
52
|
export { defaultOptions as defaults };
|
|
53
53
|
}
|
|
54
54
|
|
package/lib/index.js
CHANGED
|
@@ -26,13 +26,13 @@ const defaultSort = sortBy('date');
|
|
|
26
26
|
const defaultFilter = () => true;
|
|
27
27
|
/**
|
|
28
28
|
* @typedef {Object} CollectionConfig
|
|
29
|
-
* @property {string|string[]} pattern - One or more glob patterns to match files to a collection
|
|
30
|
-
* @property {string|(a,b) => 0|1|-1} sortBy - A key to sort by (e.g. `date`,`title`, ..) or a custom sort function
|
|
31
|
-
* @property {number} limit - Limit the amount of items in a collection to `limit`
|
|
32
|
-
* @property {boolean} refer - Adds `next` and `previous` keys to file metadata of matched files
|
|
33
|
-
* @property {boolean} reverse - Whether to invert the sorting function results (asc/descending)
|
|
34
|
-
* @property {Function} filterBy - A function that gets a `Metalsmith.File` as first argument and returns `true` for every file to include in the collection
|
|
35
|
-
* @property {Object|string} metadata - An object with metadata to attach to the collection, or a `json`/`yaml`filepath string to load data from (relative to `Metalsmith.directory`)
|
|
29
|
+
* @property {string|string[]} [pattern] - One or more glob patterns to match files to a collection
|
|
30
|
+
* @property {string|(a,b) => 0|1|-1} [sortBy] - A key to sort by (e.g. `date`,`title`, ..) or a custom sort function
|
|
31
|
+
* @property {number} [limit] - Limit the amount of items in a collection to `limit`
|
|
32
|
+
* @property {boolean} [refer] - Adds `next` and `previous` keys to file metadata of matched files
|
|
33
|
+
* @property {boolean} [reverse] - Whether to invert the sorting function results (asc/descending)
|
|
34
|
+
* @property {Function} [filterBy] - A function that gets a `Metalsmith.File` as first argument and returns `true` for every file to include in the collection
|
|
35
|
+
* @property {Object|string} [metadata] - An object with metadata to attach to the collection, or a `json`/`yaml`filepath string to load data from (relative to `Metalsmith.directory`)
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
38
|
/** @type {CollectionConfig} */
|
|
@@ -96,7 +96,7 @@ function normalizeOptions(options) {
|
|
|
96
96
|
*/
|
|
97
97
|
|
|
98
98
|
|
|
99
|
-
function
|
|
99
|
+
function collections(options) {
|
|
100
100
|
options = normalizeOptions(options);
|
|
101
101
|
const collectionNames = Object.keys(options);
|
|
102
102
|
const mappedCollections = collectionNames.map(name => {
|
|
@@ -210,6 +210,7 @@ function initializeCollections(options) {
|
|
|
210
210
|
};
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
|
|
213
|
+
collections.defaults = defaultOptions;
|
|
214
214
|
|
|
215
|
-
export {
|
|
215
|
+
export { collections as default };
|
|
216
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.js"],"sourcesContent":["import get from 'lodash.get'\nimport { sync as loadMetadata } from 'read-metadata'\n\nfunction sortBy(key) {\n let getKey = (x) => x[key]\n if (key.includes('.')) {\n getKey = (x) => get(x, key)\n }\n return function defaultSort(a, b) {\n a = getKey(a)\n b = getKey(b)\n if (!a && !b) return 0\n if (!a) return -1\n if (!b) return 1\n if (b > a) return -1\n if (a > b) return 1\n return 0\n }\n}\n\n// for backwards-compatibility only, date makes as little sense as \"pubdate\" or any custom key\nconst defaultSort = sortBy('date')\nconst defaultFilter = () => true\n\n/**\n * @typedef {Object} CollectionConfig\n * @property {string|string[]} [pattern] - One or more glob patterns to match files to a collection\n * @property {string|(a,b) => 0|1|-1} [sortBy] - A key to sort by (e.g. `date`,`title`, ..) or a custom sort function\n * @property {number} [limit] - Limit the amount of items in a collection to `limit`\n * @property {boolean} [refer] - Adds `next` and `previous` keys to file metadata of matched files\n * @property {boolean} [reverse] - Whether to invert the sorting function results (asc/descending)\n * @property {Function} [filterBy] - A function that gets a `Metalsmith.File` as first argument and returns `true` for every file to include in the collection\n * @property {Object|string} [metadata] - An object with metadata to attach to the collection, or a `json`/`yaml`filepath string to load data from (relative to `Metalsmith.directory`)\n */\n\n/** @type {CollectionConfig} */\nconst defaultOptions = {\n pattern: null,\n reverse: false,\n metadata: null,\n limit: Infinity,\n refer: true,\n sortBy: defaultSort,\n filterBy: defaultFilter\n}\n\n/**\n * Normalize options\n * @param {Object.<string,CollectionConfig>} options\n */\nfunction normalizeOptions(options) {\n options = options || {}\n\n for (const config in options) {\n let normalized = options[config]\n if (typeof normalized === 'string' || Array.isArray(normalized)) {\n normalized = { pattern: normalized }\n }\n normalized = Object.assign({}, defaultOptions, normalized)\n if (typeof normalized.metadata === 'string') {\n normalized.metadata = loadMetadata(normalized.metadata)\n }\n if (typeof normalized.sortBy === 'string') {\n normalized.sortBy = sortBy(normalized.sortBy)\n }\n options[config] = normalized\n }\n\n return options\n}\n\n/**\n * Add `collections` of files to the global metadata as a sorted array.\n * @example\n * metalsmith.use(collections({\n * posts: 'posts/*.md',\n * portfolio: {\n * pattern: 'portfolio/*.md',\n * metadata: { title: 'My portfolio' },\n * sortBy: 'order'\n * }\n * }))\n *\n * @param {Object.<string,CollectionConfig|string>} options\n * @return {import('metalsmith').Plugin}\n */\nfunction collections(options) {\n options = normalizeOptions(options)\n const collectionNames = Object.keys(options)\n const mappedCollections = collectionNames.map((name) => {\n return Object.assign({ name: name }, options[name])\n })\n\n return function collections(files, metalsmith, done) {\n const metadata = metalsmith.metadata()\n const fileNames = Object.keys(files)\n const debug = metalsmith.debug('@metalsmith/collections')\n\n metadata.collections = {}\n\n fileNames.forEach((filePath) => {\n // add path property to file metadata for convenience\n // this is for backward-compatibility only and is pretty useless\n const file = files[filePath]\n file.path = file.path || filePath\n\n // dynamically add collections with default options when encountered in file metadata,\n // and not explicitly defined in plugin options\n if (file.collection) {\n ;(Array.isArray(file.collection) ? file.collection : [file.collection]).forEach((name) => {\n if (!collectionNames.includes(name)) {\n collectionNames.push(name)\n const normalized = Object.assign({}, defaultOptions)\n mappedCollections.push(Object.assign({ name }, normalized))\n }\n })\n }\n })\n\n debug('Identified %s collections: %s', mappedCollections.length, collectionNames.join())\n\n mappedCollections.forEach((collection) => {\n const { pattern, filterBy, sortBy, reverse, refer, limit } = collection\n const name = collection.name\n const matches = []\n debug('Processing collection %s with options %s:', name, collection)\n\n // first match by pattern if provided\n if (pattern) {\n matches.push.apply(\n matches,\n metalsmith.match(pattern, fileNames).map((filepath) => {\n const data = files[filepath]\n // pattern-matched files might or might not have a \"collection\" property defined in front-matter\n // and might also be included in multiple collections\n if (!data.collection) {\n data.collection = []\n } else if (typeof data.collection === 'string') {\n data.collection = [data.collection]\n }\n if (!data.collection.includes(collection.name)) {\n data.collection = [...data.collection, collection.name]\n }\n return data\n })\n )\n }\n\n // next match by \"collection\" key, but only push if the files haven't been added through pattern matching first\n matches.push.apply(\n matches,\n Object.values(files).filter((file) => {\n const patternMatched = matches.includes(file)\n const isInCollection = Array.isArray(file.collection)\n ? file.collection.includes(collection.name)\n : file.collection === collection.name\n return !patternMatched && isInCollection\n })\n )\n\n if (Object.prototype.hasOwnProperty.call(metadata, name)) {\n debug('Warning: overwriting previously set metadata property %s', name)\n }\n // apply sort, reverse, filter, limit options in this order\n metadata[name] = matches.sort(sortBy)\n\n if (reverse) {\n metadata[name].reverse()\n }\n\n metadata[name] = metadata[name].filter(filterBy).slice(0, limit)\n\n if (collection.metadata) {\n metadata[name].metadata = collection.metadata\n }\n if (refer) {\n if (reverse) {\n metadata[name].forEach((file, i) => {\n Object.assign(file, {\n next: i > 0 ? metadata[name][i - 1] : null,\n previous: i < metadata[name].length - 1 ? metadata[name][i + 1] : null\n })\n })\n } else {\n metadata[name].forEach((file, i) => {\n Object.assign(file, {\n previous: i > 0 ? metadata[name][i - 1] : null,\n next: i < metadata[name].length - 1 ? metadata[name][i + 1] : null\n })\n })\n }\n }\n\n metadata.collections[name] = metadata[name]\n debug('Added %s files to collection %s', metadata[name].length, name)\n })\n done()\n }\n}\n\ncollections.defaults = defaultOptions\n\nexport default collections\n"],"names":["sortBy","key","getKey","x","includes","get","defaultSort","a","b","defaultFilter","defaultOptions","pattern","reverse","metadata","limit","Infinity","refer","filterBy","normalizeOptions","options","config","normalized","Array","isArray","Object","assign","loadMetadata","collections","collectionNames","keys","mappedCollections","map","name","files","metalsmith","done","fileNames","debug","forEach","filePath","file","path","collection","push","length","join","matches","apply","match","filepath","data","values","filter","patternMatched","isInCollection","prototype","hasOwnProperty","call","sort","slice","i","next","previous","defaults"],"mappings":";;;AAGA,SAASA,MAAT,CAAgBC,GAAhB,EAAqB;AACnB,EAAA,IAAIC,MAAM,GAAIC,CAAD,IAAOA,CAAC,CAACF,GAAD,CAArB,CAAA;;AACA,EAAA,IAAIA,GAAG,CAACG,QAAJ,CAAa,GAAb,CAAJ,EAAuB;IACrBF,MAAM,GAAIC,CAAD,IAAOE,GAAG,CAACF,CAAD,EAAIF,GAAJ,CAAnB,CAAA;AACD,GAAA;;AACD,EAAA,OAAO,SAASK,WAAT,CAAqBC,CA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,QAAZ,GAAuBrD,cAAvB;;;;"}
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"type": "git",
|
|
16
16
|
"url": "https://github.com/metalsmith/collections.git"
|
|
17
17
|
},
|
|
18
|
-
"version": "1.3.
|
|
18
|
+
"version": "1.3.1",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"source": "src/index.js",
|
|
21
21
|
"main": "lib/index.cjs",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"type": "module",
|
|
24
24
|
"types": "./lib/index.d.ts",
|
|
25
25
|
"exports": {
|
|
26
|
+
"types": "./lib/index.d.ts",
|
|
26
27
|
"import": "./lib/index.js",
|
|
27
28
|
"require": "./lib/index.cjs"
|
|
28
29
|
},
|
|
@@ -61,7 +62,7 @@
|
|
|
61
62
|
"lint:check": "eslint --fix-dry-run .",
|
|
62
63
|
"dev": "nodemon --exec 'npm test'",
|
|
63
64
|
"release": "release-it .",
|
|
64
|
-
"build": "microbundle --target node
|
|
65
|
+
"build": "microbundle --target node -f cjs,esm --strict --generateTypes=false",
|
|
65
66
|
"pretest": "npm run build",
|
|
66
67
|
"test": "nyc mocha"
|
|
67
68
|
},
|