ripunzel/src/sources/getIndex.js

25 lines
687 B
JavaScript

'use strict';
const config = require('config');
const fs = require('fs-extra');
const yaml = require('js-yaml');
const logger = require('../logger')(__filename);
const interpolate = require('../interpolate');
async function getIndex(user) {
const indexFilePath = interpolate(config.library.index.file, null, null, null, null, user, false);
try {
const indexFile = await fs.readFile(indexFilePath, 'utf8');
return yaml.safeLoad(indexFile);
} catch (error) {
logger.info(`No index file found for '${user.name}' at '${indexFilePath}'`);
return { profile: { image: null, description: null }, posts: [] };
}
}
module.exports = getIndex;