From a807ccc00e5d90fb78d2da999926c34e35efcb82 Mon Sep 17 00:00:00 2001 From: zjy <3161362058@qq.com> Date: Wed, 30 Oct 2024 14:45:33 +0800 Subject: [PATCH 1/3] docs: Update docs scripts --- docs/website/docusaurus.config.js | 147 +++++++++++++++++++++++------- docs/website/src/pages/index.tsx | 33 ------- 2 files changed, 116 insertions(+), 64 deletions(-) diff --git a/docs/website/docusaurus.config.js b/docs/website/docusaurus.config.js index eccc6c41755..c252aca1bfe 100644 --- a/docs/website/docusaurus.config.js +++ b/docs/website/docusaurus.config.js @@ -75,32 +75,32 @@ const config = { themeConfig: { // @type {import('@docusaurus/preset-classic').ThemeConfig} metadata: [{ name: 'title', content: 'Sealos by 环界云' }], - // announcementBar: { - // id: 'sealos_tip', - // content: ` - //
- //
${isDomesticSite ? 'If you are an international user, please visit 👉' : '如果您是国内用户,请直接访问 👉 '}
- //
- // ${isDomesticSite ? 'International Site' : '国内官网'} - //
- // - // - // - // - // - // - // - // - // - // - // - // - //
- // `, - // isCloseable: true, - // }, + announcementBar: { + id: 'sealos_tip', + content: ` +
+
${isDomesticSite ? 'If you are an international user, please visit 👉' : '如果您是国内用户,请直接访问 👉 '}
+
+ ${isDomesticSite ? 'International Site' : '国内官网'} +
+ + + + + + + + + + + + +
+ `, + isCloseable: true, + }, algolia: { // Algolia 提供的应用 ID appId: "SLTSB7B9Y0", @@ -251,11 +251,7 @@ const config = { { src: "/global.js", async: true - }, - ...(isDomesticSite ? [{ - src: 'https://hm.baidu.com/hm.js?d8e8ecf669c47dc2512d3f1417e761f9', - async: true, - }] : []) + } ], headTags: [ { @@ -279,6 +275,95 @@ const config = { }, } }, + function gtmPlugin (context, options) { + return { + name: 'docusaurus-gtm-plugin', + injectHtmlTags () { + return { + headTags: [ + { + tagName: 'script', + innerHTML: ` + (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': + new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], + j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= + 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); + })(window,document,'script','dataLayer','GTM-5953N4CP'); + `, + }, + ], + preBodyTags: [ + { + tagName: 'noscript', + innerHTML: ` + + `, + }, + ], + } + }, + } + }, + function umamiPlugin (context, options) { + return { + name: 'docusaurus-umami-plugin', + injectHtmlTags () { + return { + headTags: [ + { + tagName: 'script', + innerHTML: ` + (function() { + const hostname = window.location.hostname; + if (hostname === 'sealos.run') { + const script1 = document.createElement('script'); + script1.src = 'https://umami.cloud.sealos.io/oishii'; + script1.setAttribute('data-website-id', 'e5a8009f-7cb6-4841-9522-d23b96216b7a'); + script1.async = true; + document.head.appendChild(script1); + } else { + const script2 = document.createElement('script'); + script2.src = 'https://umami.cloud.sealos.io/oishii'; + script2.setAttribute('data-website-id', 'a1c29ace-b288-431a-a2eb-8617d1d5b5ed'); + script2.async = true; + document.head.appendChild(script2); + } + })(); + `, + }, + ], + } + }, + } + }, + function baiduPlugin (context, options) { + return { + name: 'docusaurus-baidu-plugin', + injectHtmlTags () { + return { + headTags: [ + { + tagName: 'script', + innerHTML: ` + (function() { + const hostname = window.location.hostname; + if (hostname === 'sealos.run') { + var _hmt = _hmt || []; + var hm = document.createElement("script"); + hm.src = "https://hm.baidu.com/hm.js?d8e8ecf669c47dc2512d3f1417e761f9"; + hm.async = true; + var s = document.getElementsByTagName("script")[0]; + s.parentNode.insertBefore(hm, s); + } + })(); + `, + }, + ], + } + }, + } + } ] } diff --git a/docs/website/src/pages/index.tsx b/docs/website/src/pages/index.tsx index 88c4eac6dc6..519f0a6cfe6 100644 --- a/docs/website/src/pages/index.tsx +++ b/docs/website/src/pages/index.tsx @@ -1,7 +1,6 @@ import '@site/src/css/animate.css'; import Layout from '@theme/Layout'; import React, { useEffect, useMemo } from 'react'; -import { Helmet } from 'react-helmet'; import { PC_MIN_WIDTH } from '../constants/platform'; import useWindow from '../hooks/useWindow'; import Capability from './components/Capability'; @@ -20,26 +19,6 @@ const Home = () => { const isPc = useMemo(() => screenWidth > PC_MIN_WIDTH, [screenWidth]); const { i18n } = useDocusaurusContext(); - useEffect(() => { - const loadUmamiScript = () => { - const hostname = window.location.hostname; - if (hostname === 'sealos.run') { - const script1 = document.createElement('script'); - script1.src = 'https://umami.cloud.sealos.io/oishii'; - script1.setAttribute('data-website-id', 'e5a8009f-7cb6-4841-9522-d23b96216b7a'); - script1.async = true; - document.head.appendChild(script1); - } else { - const script2 = document.createElement('script'); - script2.src = 'https://umami.cloud.sealos.io/oishii'; - script2.setAttribute('data-website-id', 'a1c29ace-b288-431a-a2eb-8617d1d5b5ed'); - script2.async = true; - document.head.appendChild(script2); - } - }; - loadUmamiScript(); - }, []); - useEffect(() => { const urlParams = new URLSearchParams(window.location.search); const params: Record = {}; @@ -83,18 +62,6 @@ const Home = () => { } /> - - -
{/* */} From 6e405b933569fa6d2950ebbbea12a681fb51ed2c Mon Sep 17 00:00:00 2001 From: zjy <3161362058@qq.com> Date: Wed, 30 Oct 2024 14:48:09 +0800 Subject: [PATCH 2/3] update --- docs/website/docusaurus.config.js | 35 ++++++++++++++++++------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/docs/website/docusaurus.config.js b/docs/website/docusaurus.config.js index c252aca1bfe..8513b02178f 100644 --- a/docs/website/docusaurus.config.js +++ b/docs/website/docusaurus.config.js @@ -284,20 +284,27 @@ const config = { { tagName: 'script', innerHTML: ` - (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': - new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], - j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= - 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); - })(window,document,'script','dataLayer','GTM-5953N4CP'); - `, - }, - ], - preBodyTags: [ - { - tagName: 'noscript', - innerHTML: ` - + (function() { + const hostname = window.location.hostname; + if (hostname !== 'sealos.run') { + (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': + new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], + j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= + 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); + })(window,document,'script','dataLayer','GTM-5953N4CP'); + + // 添加 noscript iframe + const noscript = document.createElement('noscript'); + const iframe = document.createElement('iframe'); + iframe.src = 'https://www.googletagmanager.com/ns.html?id=GTM-5953N4CP'; + iframe.height = '0'; + iframe.width = '0'; + iframe.style.display = 'none'; + iframe.style.visibility = 'hidden'; + noscript.appendChild(iframe); + document.body.appendChild(noscript); + } + })(); `, }, ], From 4d0649193436796fee3a98c71f107d29176caee8 Mon Sep 17 00:00:00 2001 From: zjy <3161362058@qq.com> Date: Wed, 30 Oct 2024 15:05:55 +0800 Subject: [PATCH 3/3] fix noscript --- docs/website/docusaurus.config.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/docs/website/docusaurus.config.js b/docs/website/docusaurus.config.js index 8513b02178f..8ba2a26c79c 100644 --- a/docs/website/docusaurus.config.js +++ b/docs/website/docusaurus.config.js @@ -292,22 +292,21 @@ const config = { j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-5953N4CP'); - - // 添加 noscript iframe - const noscript = document.createElement('noscript'); - const iframe = document.createElement('iframe'); - iframe.src = 'https://www.googletagmanager.com/ns.html?id=GTM-5953N4CP'; - iframe.height = '0'; - iframe.width = '0'; - iframe.style.display = 'none'; - iframe.style.visibility = 'hidden'; - noscript.appendChild(iframe); - document.body.appendChild(noscript); } })(); `, }, ], + preBodyTags: [ + { + tagName: 'script', + innerHTML: ` + if (window.location.hostname !== 'sealos.run') { + document.write(''); + } + `, + }, + ] } }, }