From fdbccd6d46c136b1a83cde4b36eddf760ab3c06b Mon Sep 17 00:00:00 2001 From: zhujingyang <72259332+zjy365@users.noreply.github.com> Date: Tue, 7 Nov 2023 17:41:48 +0800 Subject: [PATCH] feat:docs add link proxy (#4266) --- docs/website/.gitignore | 1 + docs/website/docusaurus.config.js | 14 ++++++++++- docs/website/package.json | 9 ++++---- docs/website/src/hooks/useUploadData.ts | 16 +++++++------ docs/website/src/hooks/useWindow.ts | 8 +------ .../pages/components/Header/index.phone.scss | 1 + .../src/pages/components/Header/index.scss | 1 + .../src/pages/components/Header/index.tsx | 12 ++++++---- docs/website/src/pages/index.tsx | 2 -- .../src/pages/self-hosting/header/index.scss | 2 ++ docs/website/static/global.js | 23 +++++++++++++++++++ docs/website/yarn.lock | 5 ++++ 12 files changed, 68 insertions(+), 26 deletions(-) create mode 100644 docs/website/static/global.js diff --git a/docs/website/.gitignore b/docs/website/.gitignore index 1ee8fd85f5f..e83755844c1 100644 --- a/docs/website/.gitignore +++ b/docs/website/.gitignore @@ -10,6 +10,7 @@ # Misc .DS_Store +.env .env.local .env.development.local .env.test.local diff --git a/docs/website/docusaurus.config.js b/docs/website/docusaurus.config.js index 7bcc4e62505..e3ea1c625c0 100644 --- a/docs/website/docusaurus.config.js +++ b/docs/website/docusaurus.config.js @@ -1,5 +1,6 @@ // @ts-check const generateAlgoliKey = () => "ce5b8e1e4d0d35ff587caf75ac404df4" +require('dotenv').config() /** @type {import('@docusaurus/types').Config} */ const config = { @@ -11,7 +12,7 @@ const config = { onBrokenMarkdownLinks: "warn", favicon: "img/favicon.ico", customFields: { - bdToken: process.env.BD_TOKEN, + BD_TOKEN: process.env.BD_TOKEN, }, // GitHub pages deployment config. // If you aren't using GitHub pages, you don't need these. @@ -198,6 +199,10 @@ const config = { { src: "https://cdn.bootcdn.net/ajax/libs/wow/1.1.2/wow.min.js", async: false, + }, + { + src: "/global.js", + async: true, } ], headTags: [ @@ -207,6 +212,13 @@ const config = { name: 'baidu-site-verification', content: 'codeva-gAHDaifnOq', }, + }, + { + tagName: 'meta', + attributes: { + name: 'baidu-site-verification', + content: 'codeva-E1X5UKtV9p', + }, } ], plugins: [ diff --git a/docs/website/package.json b/docs/website/package.json index 0d9caa7a1b2..14812c1413b 100644 --- a/docs/website/package.json +++ b/docs/website/package.json @@ -20,18 +20,19 @@ "@docusaurus/core": "^2.4.3", "@docusaurus/preset-classic": "^2.4.3", "@docusaurus/theme-search-algolia": "^2.4.3", + "@headlessui/react": "^1.7.17", "@mdx-js/react": "^1.6.22", + "autoprefixer": "^10.4.16", "docusaurus-plugin-sass": "^0.2.2", + "dotenv": "^16.3.1", + "postcss": "^8.4.31", "prism-react-renderer": "^1.3.5", "prismjs": "^1.29.0", "react": "^17.0.2", "react-dom": "^17.0.2", "react-helmet": "^6.1.0", "sass": "^1.62.1", - "@headlessui/react": "^1.7.17", - "autoprefixer": "^10.4.16", "tailwindcss": "^3.3.3", - "postcss": "^8.4.31", "wowjs": "^1.1.3" }, "devDependencies": { @@ -52,4 +53,4 @@ "last 1 safari version" ] } -} \ No newline at end of file +} diff --git a/docs/website/src/hooks/useUploadData.ts b/docs/website/src/hooks/useUploadData.ts index 1d4239f7a2a..6f32ef5fe58 100644 --- a/docs/website/src/hooks/useUploadData.ts +++ b/docs/website/src/hooks/useUploadData.ts @@ -4,25 +4,27 @@ import useIsBrowser from '@docusaurus/useIsBrowser'; export default function useUploadData() { const isBrowser = useIsBrowser(); - const [id, setId] = useState(''); + const [bd_vid, setBdId] = useState(''); const { siteConfig: { customFields } } = useDocusaurusContext(); useEffect(() => { if (!isBrowser) return; + console.log(customFields); let bd_vid = sessionStorage.getItem('bd_vid'); - if (bd_vid) setId(bd_vid); + if (bd_vid) setBdId(bd_vid); }, [isBrowser]); async function uploadConvertData(params: { newType: number }[]) { - if (!isBrowser || !customFields?.bdToken || !id) return; + if (!isBrowser || !customFields?.BD_TOKEN || !bd_vid) return; const url = 'https://ocpc.baidu.com/ocpcapi/api/uploadConvertData'; - const logidUrl = `${window.location.origin}?bd_vid=${id}`; - console.log(customFields, id, '========', logidUrl); + const logidUrl = `${window.location.origin}?bd_vid=${bd_vid}`; + + console.log(customFields, bd_vid, logidUrl); const data = { - token: customFields.bdToken, + token: customFields?.BD_TOKEN, conversionTypes: params.map((newType) => ({ logidUrl: logidUrl, newType: newType })) }; @@ -36,7 +38,7 @@ export default function useUploadData() { } return { - id, + bd_vid, uploadConvertData }; } diff --git a/docs/website/src/hooks/useWindow.ts b/docs/website/src/hooks/useWindow.ts index f2fe0e0fc1c..ac3eb1031c7 100644 --- a/docs/website/src/hooks/useWindow.ts +++ b/docs/website/src/hooks/useWindow.ts @@ -16,14 +16,8 @@ export default function () { requestAnimationFrame(() => setScreenWidth(document?.body.clientWidth)); }; window.addEventListener('resize', updateScreenWidth); - // handle - setCurrentLanguage(document.documentElement.lang); - // console.log(document.documentElement.lang, window.location, navigator.language); - // if (navigator.language !== 'en' && !window.location.pathname.includes('zh-Hans')) { - // const newPath = window.location.pathname.endsWith('/') ? 'zh-Hans/' : '/zh-Hans/'; - // window.location.pathname += newPath; - // } + setCurrentLanguage(document.documentElement.lang); setCloudUrl( document.documentElement.lang === 'en' diff --git a/docs/website/src/pages/components/Header/index.phone.scss b/docs/website/src/pages/components/Header/index.phone.scss index 5efb90939a4..1649bbf592f 100644 --- a/docs/website/src/pages/components/Header/index.phone.scss +++ b/docs/website/src/pages/components/Header/index.phone.scss @@ -54,6 +54,7 @@ border-radius: 4px; background: rgba(255, 255, 255, 0.2); filter: blur(4px); + pointer-events: none; } .start-now-button { diff --git a/docs/website/src/pages/components/Header/index.scss b/docs/website/src/pages/components/Header/index.scss index ff85ddc2b10..e7625619b1a 100644 --- a/docs/website/src/pages/components/Header/index.scss +++ b/docs/website/src/pages/components/Header/index.scss @@ -109,6 +109,7 @@ border-radius: 4px; background: rgba(255, 255, 255, 0.2); filter: blur(4px); + pointer-events: none; } .start-now-button { diff --git a/docs/website/src/pages/components/Header/index.tsx b/docs/website/src/pages/components/Header/index.tsx index d1e77f2aa30..7920f1718e8 100644 --- a/docs/website/src/pages/components/Header/index.tsx +++ b/docs/website/src/pages/components/Header/index.tsx @@ -43,7 +43,7 @@ const HomeHeader = ({ isPc }: { isPc: boolean }) => { const [stars, setStars] = useState(10000); const isBrowser = useIsBrowser(); const { cloudUrl } = useWindow(); - const { uploadConvertData } = useUploadData(); + const { uploadConvertData, bd_vid } = useUploadData(); const i18nMap: { [key: string]: { label: string; link: string } } = { en: { label: '中', link: '/zh-Hans/' }, @@ -133,7 +133,7 @@ const HomeHeader = ({ isPc }: { isPc: boolean }) => { 一样使用 Sealos! )} - + {i18nObj.startNow}
@@ -174,9 +174,11 @@ const HomeHeader = ({ isPc }: { isPc: boolean }) => { console.log('uploadConvertData'); uploadConvertData([ { - newType: 51 + newType: 1 } - ]); + ]) + .then((response) => response && response.json()) + .then((data) => console.log(data, 'bd_res')); } }} > @@ -198,7 +200,7 @@ const HomeHeader = ({ isPc }: { isPc: boolean }) => { )} - + {i18nObj.startNow}
diff --git a/docs/website/src/pages/index.tsx b/docs/website/src/pages/index.tsx index 418372d6f77..f0c129fb96b 100644 --- a/docs/website/src/pages/index.tsx +++ b/docs/website/src/pages/index.tsx @@ -57,8 +57,6 @@ const Home = () => { gtag('event', 'conversion', {'send_to': 'AW-786053845/LpbTCJ-8-coYENX16PYC'}); `} - - {/* */}
diff --git a/docs/website/src/pages/self-hosting/header/index.scss b/docs/website/src/pages/self-hosting/header/index.scss index 1f9c0bd3df2..bc57055a263 100644 --- a/docs/website/src/pages/self-hosting/header/index.scss +++ b/docs/website/src/pages/self-hosting/header/index.scss @@ -105,6 +105,7 @@ border-radius: 4px; background: rgba(255, 255, 255, 0.2); filter: blur(4px); + pointer-events: none; } .start-now-button { @@ -242,6 +243,7 @@ border-radius: 4px; background: rgba(255, 255, 255, 0.2); filter: blur(4px); + pointer-events: none; } .start-now-button { diff --git a/docs/website/static/global.js b/docs/website/static/global.js new file mode 100644 index 00000000000..be5e7bca225 --- /dev/null +++ b/docs/website/static/global.js @@ -0,0 +1,23 @@ +document.addEventListener("DOMContentLoaded", function () { + console.log('addEventListener') + const parentElement = document.body + parentElement.addEventListener("click", function (event) { + if (event.target.tagName === "A") { + const href = event.target.getAttribute("href") + const currentHostname = window.location.hostname + const bdId = sessionStorage.getItem("bd_vid") + console.log(bdId, 'bd_vid') + if (href.includes("sealos.io") || href.includes("sealos.top") || href.includes("sealos.run")) { + event.preventDefault() + console.log("特殊处理链接: " + href) + + const targetHostname = (currentHostname === "sealos.io") ? "sealos.io" : "sealos.top" + const modifiedHref = href.replace("sealos.io", targetHostname) + console.log(modifiedHref, '修改后的链接') + + event.target.href = modifiedHref + window.open(modifiedHref) + } + } + }) +}) diff --git a/docs/website/yarn.lock b/docs/website/yarn.lock index 7d3088d3bae..0d5f203176f 100644 --- a/docs/website/yarn.lock +++ b/docs/website/yarn.lock @@ -3661,6 +3661,11 @@ dot-prop@^5.2.0: dependencies: is-obj "^2.0.0" +dotenv@^16.3.1: + version "16.3.1" + resolved "https://registry.npmmirror.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e" + integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ== + duplexer3@^0.1.4: version "0.1.5" resolved "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.5.tgz"