metalsmith] helper to cache values and files between builds.
See the annotated source or github repo
npm i --save metalsmith-cache
This package will persist data in a cache
directory in your project root. You should probably .gitignore
that directory.
See annotated source
import {
FileCache,
ValueCache
} from 'metalsmith-cache'
fileCache = new FileCache('google-drive')
valueCache = new ValueCache('google-drive-params')
Metalsmith('src')
// invalidate cache
.use((files) => {
return fileCache.invalidate()
})
// store a file
.use((files) => {
return fileCache.store('some/path', files[path])
})
// retrieve file & store in metalsmith files structure
.use((files) => {
return fileCache.retrieve('some/path')
.then((file) => files['some/path'] = file)
})
// merge all files from cache to metalsmith files structure
.use((files) => {
return fileCache.all()
.then((cache) => Object.assign(files, cache))
})
// fetch files according to multimatch mask
.use((files) => {
return fileCache.mask('**/*.html')
.then((cache) => Object.assign(files, cache))
})
// store a value
.use(() => {
return valueCache.store('lastRun', new Date().toISOString())
})
// retrieve a value
.use(() => {
valueCache.retrieve('lastRun')
.then((lastRun) => console.log(lastRun))
})
.build( ... )
Full implementation examples:
Levi Wheatcroft levi@wht.cr
Contributions welcome; Please submit all pull requests against the master branch.