/**
 * @license Copyright (c) 2017-2025, CKSource Holding sp. z o.o. All rights reserved.
 * For licensing, see LICENSE.md.
 */

'use strict';

const upath = require( 'upath' );
const fs = require( 'fs' );

/**
 * Reads Umberto's hexo config file.
 *
 * @returns {Object}
 */
module.exports = () => {
	const defaultConfigPath = upath.join( __dirname, '../../hexo-config.json' );
	let defaultConfig;

	try {
		if ( fs.existsSync( defaultConfigPath ) ) {
			defaultConfig = JSON.parse( fs.readFileSync( defaultConfigPath, 'utf8' ) );
			// jscs: disable
			defaultConfig.public_dir = upath.resolve( defaultConfig.public_dir );
			// jscs: enable
		}
	} catch ( err ) {
		console.error( 'Skipped hexo-prepare due to error:', err );
	}

	return defaultConfig;
};
