1
0
mirror of https://github.com/Bayselonarrend/OpenIntegrations.git synced 2025-04-21 12:17:20 +02:00

65 lines
2.2 KiB
JavaScript
Raw Normal View History

2024-10-09 20:52:28 +03:00
import React, { useEffect } from 'react';
import Layout from '@theme-original/Layout';
import Head from '@docusaurus/Head';
2024-10-10 09:15:58 +03:00
import { useLocation } from '@docusaurus/router';
2024-10-09 20:52:28 +03:00
export default function CustomLayout(props) {
2024-10-10 09:15:58 +03:00
const location = useLocation();
2024-10-09 20:52:28 +03:00
2024-10-10 09:15:58 +03:00
useEffect(() => {
// Проверяем, находимся ли мы на странице документации
2024-10-09 22:58:48 +03:00
if (!location.pathname.startsWith('/docs/')) {
2024-10-10 09:15:58 +03:00
return; // Если нет, не выполняем код для рекламы
2024-10-09 22:58:48 +03:00
}
2024-10-10 09:15:58 +03:00
// Функция для рендеринга рекламы
const renderAds = () => {
// Удаляем предыдущий скрипт рендеринга, если он существует
const existingScript = document.getElementById('yandex-ad-script');
if (existingScript) {
existingScript.remove();
}
// Создаем новый скрипт для рендеринга рекламы
const script = document.createElement('script');
script.id = 'yandex-ad-script';
script.innerHTML = `
window.yaContextCb.push(() => {
Ya.Context.AdvManager.render({
"blockId": "R-A-12294791-3",
"type": "floorAd",
"platform": "touch"
});
Ya.Context.AdvManager.render({
"blockId": "R-A-12294791-4",
"type": "floorAd",
"platform": "desktop"
});
})
`;
document.body.appendChild(script);
};
// Рендерим рекламные блоки при загрузке страницы или изменении маршрута
renderAds();
// Удаляем блоки при размонтировании или смене страницы
2024-10-09 20:52:28 +03:00
return () => {
2024-10-10 09:15:58 +03:00
const existingScript = document.getElementById('yandex-ad-script');
if (existingScript) existingScript.remove();
2024-10-09 20:52:28 +03:00
};
2024-10-10 09:15:58 +03:00
}, [location.pathname]); // Следим за изменением пути
2024-10-09 20:52:28 +03:00
return (
<>
<Head>
<script>
window.yaContextCb = window.yaContextCb || [];
</script>
<script src="https://yandex.ru/ads/system/context.js" async></script>
</Head>
<Layout {...props} />
</>
);
}