<commit_before>/**
* @license Apache-2.0
*
* Copyright (c) 2021 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var React = require( 'react' );
var render = require( 'react-dom/server' ).renderToString;
var styles = require( '@mui/styles' );


// VARIABLES //

var ServerStyleSheets = styles.ServerStyleSheets;
var StylesProvider = styles.StylesProvider;
var TITLE = 'Help | stdlib';
var RE_PATHNAME = /(\/docs\/api\/.+\/help)/;


// MAIN //

/**
* Defines a route handler for help page.
*
* @private
* @param {Options} opts - options
* @param {Template} opts.template - application template
* @param {(ReactComponent|null)} opts.app - application component
* @param {Object} opts.meta - default meta data
* @returns {Object} route declaration
*/
function route( opts ) {
	var schema;
	var tmpl;
	var App;

	schema = {
		'method': 'GET',
		'url': '/docs/api/:version/help',
		'schema': {
			'querystring': {},
			'response': {
				'200': {
					'type': 'string'
				}
			}
		},
		'handler': onRequest
	};

	App = opts.app;
	tmpl = opts.template.clone();

	return schema;

	/**
	* Callback invoked upon receiving an HTTP request.
	*
	* @private
	* @param {Object} request - request object
	* @param {Object} reply - reply object
	* @returns {void}
	*/
	function onRequest( request, reply ) {
		var sheets;
		var html;
		var ctx;
		var url;
		var css;
		var v;
		var q;

		v = request.params.version;
		request.log.info( 'Version: %s', v );

		q = request.query.q;
		request.log.info( 'Query: %s', q );

		url = request.url.replace( RE_PATHNAME, '$1' );
		request.log.info( 'Resolved URL: %s', url );

		request.log.info( 'Returning application.' );
		reply.type( 'text/html' );

		// Initialize a means for generating Material-UI CSS:
		sheets = new ServerStyleSheets();

		// Render the application component as parameterized by request data...
		ctx = {};
		html = render(sheets.collect(
			<StylesProvider>
				<App
					url={ url }
					version={ v }
					data={ {} }
					query={ q }
					context={ ctx }
				/>
			</StylesProvider>
		));

		// Generate Material-UI CSS:
		css = sheets.toString();

		// Insert the rendered application into the application template...
		tmpl.title( TITLE )
			.description( opts.meta.description )
			.url( '/docs/api/'+v+'/help' )
			.css( css )
			.content( html );

		// Send the response data:
		reply.send( tmpl.toString() );
	}
}


// EXPORTS //

module.exports = route;
<commit_msg>Refactor logic for removing a trailing slash and remove unused querystring<commit_after>/**
* @license Apache-2.0
*
* Copyright (c) 2021 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var React = require( 'react' );
var render = require( 'react-dom/server' ).renderToString;
var styles = require( '@mui/styles' );


// VARIABLES //

var ServerStyleSheets = styles.ServerStyleSheets;
var StylesProvider = styles.StylesProvider;
var TITLE = 'Help | stdlib';


// MAIN //

/**
* Defines a route handler for help page.
*
* @private
* @param {Options} opts - options
* @param {Template} opts.template - application template
* @param {(ReactComponent|null)} opts.app - application component
* @param {Object} opts.meta - default meta data
* @returns {Object} route declaration
*/
function route( opts ) {
	var schema;
	var tmpl;
	var App;

	schema = {
		'method': 'GET',
		'url': '/docs/api/:version/help',
		'schema': {
			'response': {
				'200': {
					'type': 'string'
				}
			}
		},
		'handler': onRequest
	};

	App = opts.app;
	tmpl = opts.template.clone();

	return schema;

	/**
	* Callback invoked upon receiving an HTTP request.
	*
	* @private
	* @param {Object} request - request object
	* @param {Object} reply - reply object
	* @returns {void}
	*/
	function onRequest( request, reply ) {
		var sheets;
		var html;
		var ctx;
		var url;
		var css;
		var v;

		v = request.params.version;
		request.log.info( 'Version: %s', v );

		if ( request.url[ request.url.length-1 ] === '/' ) {
			url = request.url.slice( 0, request.url.length-1 );
		} else {
			url = request.url;
		}
		request.log.info( 'Resolved URL: %s', url );

		request.log.info( 'Returning application.' );
		reply.type( 'text/html' );

		// Initialize a means for generating Material-UI CSS:
		sheets = new ServerStyleSheets();

		// Render the application component as parameterized by request data...
		ctx = {};
		html = render(sheets.collect(
			<StylesProvider>
				<App
					url={ url }
					version={ v }
					data={ {} }
					query=''
					context={ ctx }
				/>
			</StylesProvider>
		));

		// Generate Material-UI CSS:
		css = sheets.toString();

		// Insert the rendered application into the application template...
		tmpl.title( TITLE )
			.description( opts.meta.description )
			.url( url )
			.css( css )
			.content( html );

		// Send the response data:
		reply.send( tmpl.toString() );
	}
}


// EXPORTS //

module.exports = route;

{'fraction_non_alphanumeric': 0.141081625797783, 'fraction_numerical': 0.0050386294927779645, 'mean_word_length': 3.104066161268091, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2244056', 'n_tokens_mistral': 2102, 'n_tokens_neox': 1893, 'n_words': 619}