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

'use strict';

const parseHref = require( '../utils/parse-href' );

/**
 * Parses an href string to generate a relative URL. If the href contains a cross-project reference, it will be logged.
 * If the href is invalid or the target page cannot be found, an error will be returned.
 *
 * @param {String} str The href string to parse
 * @param {Object} data Data object containing path and project information
 * @return {String} The parsed relative URL
 */
hexo.extend.helper.register( 'uParseHref', function( str, data ) {
	return parseHref( str, {
		path: data.path,
		projectName: data.projectName,
		projectGlobals: hexo.projectGlobals,
		BASE_PATH: data.BASE_PATH
	}, hexo, {
		relativeUrlHelper: hexo.extend.helper.store.relative_url,
		isSilentError: true
	} );
} );
