metalsmith-cache

nodei.co

npm

github-issues

stars

forks

metalsmith] helper to cache values and files between builds.

See the annotated source or github repo

install

npm i --save metalsmith-cache

.gitignore cache

This package will persist data in a cache directory in your project root. You should probably .gitignore that directory.

api

See annotated source

example

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:

Author

Levi Wheatcroft levi@wht.cr

Contributing

Contributions welcome; Please submit all pull requests against the master branch.

License