@metalsmith/collections
Version:
A Metalsmith plugin that adds collections of files to the global metadata.
1 lines • 19 kB
Source Map (JSON)
{"version":3,"file":"index.cjs","sources":["../src/index.js"],"sourcesContent":["import get from 'lodash.get'\nimport { relative, resolve } from 'path'\n\nfunction sortBy(key, order) {\n order = order === 'asc' ? -1 : 1\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 let ret\n if (!a && !b) ret = 0\n else if (!a) ret = 1 * order\n else if (!b) ret = -1 * order\n else if (b > a) ret = 1 * order\n else if (a > b) ret = -1 * order\n else ret = 0\n\n return ret\n }\n}\n\n/**\n * @param {import('metalsmith').File[]} items\n * @param {CollectionConfig} config\n */\nfunction Collection(items, { metadata, ...config }) {\n const collection = [...items]\n Object.assign(collection, metadata)\n collection.config = config\n collection.constructor = Collection\n Object.seal(collection)\n return collection\n}\n\nconst defaultSort = sortBy('path', 'asc')\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} [sort] - a sort string of the format `'<key_or_keypath>:<asc|desc>'`, followed by the sort order, 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`, `previous`, `first` and `last` keys to `file.collection[name]` metadata of matched files\n * @property {Function} [filter] - 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 metadata: null,\n limit: Infinity,\n refer: true,\n sort: defaultSort,\n filter: defaultFilter\n}\n\n/**\n * Normalize options\n * @param {Object.<string,CollectionConfig>} options\n * @param {import('metalsmith').Files} files\n * @param {import('metalsmith')} metalsmith\n * @throws {}\n */\nfunction normalizeOptions(options, files, metalsmith) {\n options = options || {}\n const matter = metalsmith.matter\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 const absPath = resolve(metalsmith.source(), normalized.metadata)\n const inSourcePath = relative(metalsmith.source(), absPath)\n const metadataFile = files[inSourcePath]\n if (!metadataFile) {\n const err = new Error(`No collection metadata file at \"${absPath}\"`)\n err.name = '@metalsmith/collections'\n throw err\n }\n normalized.metadata = matter.parse(matter.wrap(metadataFile.contents.toString()))\n }\n\n // remap sort option\n let sort = normalized.sort\n if (typeof sort === 'string') {\n if (!sort.includes(':')) sort += ':desc'\n const [key, order] = sort.split(':')\n sort = sortBy(key, order)\n }\n normalized.sort = sort\n\n options[config] = normalized\n }\n\n return options\n}\n\n/**\n * @typedef {import('../lib/index').ReferencesArray}\n * @property {import('metalsmith').File[]} previous\n * @property {import('metalsmith').File[]} next\n * @property {import('metalsmith').File} first\n * @property {import('metalsmith').File} last\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 * sort: 'date:desc'\n * }\n * }))\n *\n * @param {Object.<string,CollectionConfig|string>} options\n * @return {import('metalsmith').Plugin}\n */\nfunction collections(options) {\n return function collections(files, metalsmith, done) {\n try {\n options = normalizeOptions(options, files, metalsmith)\n } catch (err) {\n done(err)\n }\n const collectionNames = Object.keys(options)\n const mappedCollections = collectionNames.map((name) => {\n return Object.assign({ name: name }, options[name])\n })\n\n const fileNames = Object.keys(files)\n const debug = metalsmith.debug('@metalsmith/collections')\n\n metalsmith.metadata({ collections: {} })\n const metadata = metalsmith.metadata()\n\n fileNames.forEach((filePath) => {\n const file = files[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((collectionConfig) => {\n const { pattern, filter, sort, refer, limit } = collectionConfig\n const name = collectionConfig.name\n const matches = []\n debug('Processing collection %s with options %O:', name, collectionConfig)\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(collectionConfig.name)) {\n data.collection = [...data.collection, collectionConfig.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)\n .filter((file) => {\n const patternMatched = matches.includes(file)\n const isInCollection = Array.isArray(file.collection)\n ? file.collection.includes(collectionConfig.name)\n : file.collection === collectionConfig.name\n return !patternMatched && isInCollection\n })\n .map((file) => {\n if (!file.collection) {\n file.collection = []\n } else if (typeof file.collection === 'string') {\n file.collection = [file.collection]\n }\n return file\n })\n )\n\n // apply sort, filter, limit options in this order\n\n let currentCollection = matches\n // safely add to and remove from the sorting context 'path' property\n const originalPaths = []\n currentCollection.forEach((item) => {\n if (item.path) originalPaths.push([item, item.path])\n item.path = metalsmith.path(Object.entries(files).find((entry) => entry[1] === item)[0])\n })\n\n currentCollection = currentCollection.sort(sort).filter(filter).slice(0, limit)\n\n currentCollection.forEach((item) => {\n const original = originalPaths.find(([file]) => file === item)\n if (original) {\n item.path = original[1]\n } else {\n delete item.path\n }\n })\n\n metadata.collections[name] = Collection(currentCollection, collectionConfig)\n\n if (refer) {\n const lastIndex = currentCollection.length - 1\n currentCollection.forEach((file, i) => {\n file.collection[name] = Object.assign(file.collection[name] || {}, {\n previous: [],\n next: [],\n first: currentCollection[0],\n last: currentCollection[lastIndex]\n })\n // previous and next are arrays in which resp. the last & first item are merged\n // so users can easily get a single prev/next vs a list. Without it, getting the single prev is tricky, eg in NJK: {% set coll = collection.some.previous | last %}{{ coll.title }}\n if (i > 0)\n file.collection[name].previous = Object.assign(currentCollection.slice(0, i), currentCollection[i - 1])\n if (i < lastIndex)\n file.collection[name].next = Object.assign(currentCollection.slice(i + 1), currentCollection[i + 1])\n })\n }\n\n debug('Added %s files to collection %s', currentCollection.length, name)\n })\n done()\n }\n}\n\ncollections.defaults = defaultOptions\n\nexport default collections\n"],"names":["sortBy","key","order","getKey","x","includes","get","defaultSort","a","b","ret","Collection","items","metadata","config","collection","Object","assign","constructor","seal","defaultFilter","defaultOptions","pattern","limit","Infinity","refer","sort","filter","normalizeOptions","options","files","metalsmith","matter","normalized","Array","isArray","absPath","resolve","source","inSourcePath","relative","metadataFile","err","Error","name","parse","wrap","contents","toString","split","collections","done","collectionNames","keys","mappedCollections","map","fileNames","debug","forEach","filePath","file","push","length","join","collectionConfig","matches","apply","match","filepath","data","values","patternMatched","isInCollection","currentCollection","originalPaths","item","path","entries","find","entry","slice","original","lastIndex","i","previous","next","first","last","defaults"],"mappings":";;;;;;;;;AAGA,SAASA,MAAMA,CAACC,GAAG,EAAEC,KAAK,EAAE;EAC1BA,KAAK,GAAGA,KAAK,KAAK,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAA;AAChC,EAAA,IAAIC,MAAM,GAAIC,CAAC,IAAKA,CAAC,CAACH,GAAG,CAAC,CAAA;AAC1B,EAAA,IAAIA,GAAG,CAACI,QAAQ,CAAC,GAAG,CAAC,EAAE;IACrBF,MAAM,GAAIC,CAAC,IAAKE,uBAAG,CAACF,CAAC,EAAEH,GAAG,CAAC,CAAA;AAC7B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