Source: components/filter/filter-result/filter-result-element/robots-meta.js

import jQ from "jquery";
import BaseComponent from "../../../base-component";
import Settings from "../../../../helpers/settings";
import Utils from "../../../../helpers/utils";
import Globals from "../../../../helpers/globals";

/**
 * Rebots meta tag.
 * @extends BaseComponent
 */
class RobotsMeta extends BaseComponent {
	/**
	 * @constructs
	 */
	constructor() {
		super();
		this.selecor = {
			robots: 'meta[content="noindex,nofollow"]'
		}
		this.currentCollection = boostPFSConfig.general.collection_handle;
		this.settings = {
			boostCollection: Settings.getSettingValue('general.boostCollection')
		}
	}

	/**
	 * Get the rebots meta tag for document head
	 * @requires {String} Raw html template
	 */
	getTemplate() {
		return `
			<meta name="robots" content="noindex,nofollow">
		`;
	}

	/**
	 * Replace the brackets in raw html template with proper values
	 * @returns {String} HTML string
	 */
	compileTemplate() {
		return this.getTemplate();
	}

	/**
	 * Returns whether or not the rebots meta tag is rendered
	 */
	isRender() {
		return Settings.getSettingValue('general.enableSeo')
			&& !jQ(this.selecor.robots).length
			&& (
				this.currentCollection.indexOf(this.settings.boostCollection) == 0
				|| Utils.checkExistFilterOptionParam()
				|| (Globals.queryParams.q && !Utils.isSearchPage())
			);
	}

	/**
	 * Add meta[content="noindex,nofollow"] to head tag if the pf_xxx params is a part of a URL]
	 */
	render() {
		jQ('head').append(this.compileTemplate());
	}
}

export default RobotsMeta;