vue-if-bot
Version:
Hide stuff from bots (especially cookie consents)
28 lines (22 loc) • 650 B
JavaScript
var index = {
functional: true,
render: function render(h, _ref) {
var children = _ref.children,
slots = _ref.slots,
_ref$props = _ref.props,
regex = _ref$props.regex,
invert = _ref$props.invert;
var dummyEl = h('div', {}, []);
if (process.server) {
return dummyEl;
}
var botRegex = regex || /bot|googlebot|crawler|spider|robot|crawling/i;
var isBot = navigator.userAgent && botRegex.test(navigator.userAgent);
var shouldShow = invert ? isBot : !isBot;
if (!shouldShow) {
return dummyEl;
}
return h('div', {}, slots().default);
}
};
export default index;