/**
 * @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' );

/**
 * The only purpose of this filter is to group all the guides.
 * It is used by 'import-guide' filter, which supports importing a guide into another guide for reusing.
 */
hexo.extend.filter.register( 'after_post_render', page => {
	if ( !hexo.projectGlobals || !hexo.projectGlobals[ page.projectName ] ) {
		return;
	}

	if ( !hexo.projectGlobals.common.allGuides ) {
		hexo.projectGlobals.common.allGuides = [];
	}

	const allGuides = hexo.projectGlobals.common.allGuides;
	const guideData = {
		path: page.oldDataPath.replace( page.BASE_PATH + '/', '' ).replace( upath.extname( page.oldDataPath ), '' ),
		content: page.content,
		title: page.title
	};

	allGuides.push( guideData );
}, 25 );
