-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
38 lines (31 loc) · 1.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict'
const path = require('path')
const async = require('async')
const extend = require('extend')
module.exports = function () {
return function (files, metalsmith, done) {
const metadata = metalsmith.metadata()
/**
* Process a file, saving it as metadata if needed.
*
* @param {string} file The file of which is being processed.
* @param {string} filename The name of the given file.
* @param {function} callback The callback to call when the function is finished.
*/
function processFile(file, filename, callback) {
// Check if it matches the convention.
if (path.extname(filename) === '.metadata') {
// Find the name of the metadata.
const name = path.basename(filename, '.metadata')
// Recursively merge the meta data.
const newMetadata = {}
newMetadata[name] = file
extend(true, metadata, newMetadata)
// Remove the file since we've now processed it.
delete files[filename]
}
callback()
}
async.forEachOf(files, processFile, done)
}
}