UNPKG

wikic

Version:

a simple static site generator

22 lines (16 loc) 719 B
const fse = require('fs-extra') const _ = require('lodash') const path = require('path') const getClosestConfig = require('../utils/get-closest-config') module.exports = async function loadData(context) { if (!_.isPlainObject(context)) throw Error('should pass a object to load.') const { configCaches, src, site: oldSite } = context if (typeof src !== 'string') throw Error('context.src must be a string.') if (!_.isPlainObject(oldSite)) { throw Error('context.site must be passed as a object.') } const data = await fse.readFile(src, 'utf8') const srcDir = path.dirname(src) const site = await getClosestConfig(srcDir, oldSite, configCaches) return Object.assign(context, { data, site }) }