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

'use strict';

/**
 * Replaces %BASE_PATH% placeholders.
 */
hexo.extend.filter.register( 'after_post_render', page => {
	// jscs:disable
	const relativeUrlHelper = hexo.extend.helper.store.relative_url;
	// jscs:enable

	// Markdown renderer add 25 after %BASE_PATH% for some reason, quick fix here.
	page.content = page.content.replace( /%BASE_PATH%25/g, '%BASE_PATH%' );
	page.content = page.content.replace( /%BASE_PATH%/g, relativeUrlHelper( page.path, page.BASE_PATH ) );

	return page;
}, 40 );

// Priority 40 in order to execute this filter after the snippet filter (so snippet output is also processed).
