Files
ULIVZandGitHub e5d8ed4655 feat: refine node api (#1395)
- fix($core): markdown slot doesn‘t work. (regression of c85f62d)
- docs: fresh Node.JS API.
- test: official plugins.
2019-03-04 23:46:13 +08:00

16 lines
444 B
JavaScript

const LRU = require('lru-cache')
const { fs, path } = require('@vuepress/shared-utils')
const cache = new LRU({ max: 1000 })
module.exports = function getFragment (dirname, name, fragmentsDir = 'fragments') {
const target = path.resolve(dirname, `${fragmentsDir}/${name}`)
let content = cache.get(target)
if (content) {
return content
}
content = fs.readFileSync(target, 'utf-8')
cache.set(target, content)
return content
}