From ce5966d7a06d59e21c6d4ef30c75c795e7ec7e8e Mon Sep 17 00:00:00 2001 From: zhujingyang <72259332+zjy365@users.noreply.github.com> Date: Tue, 7 Nov 2023 10:34:52 +0800 Subject: [PATCH] fix:docs head meta (#4262) --- docs/website/docusaurus.config.js | 13 +++++- docs/website/src/hooks/useUploadData.ts | 42 +++++++++++++++++++ .../src/pages/components/Header/index.tsx | 17 +++++++- docs/website/src/pages/index.tsx | 7 ++++ .../src/pages/self-hosting/product/index.tsx | 2 + 5 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 docs/website/src/hooks/useUploadData.ts diff --git a/docs/website/docusaurus.config.js b/docs/website/docusaurus.config.js index c6f4d5bc161..7bcc4e62505 100644 --- a/docs/website/docusaurus.config.js +++ b/docs/website/docusaurus.config.js @@ -10,7 +10,9 @@ const config = { onBrokenLinks: "warn", onBrokenMarkdownLinks: "warn", favicon: "img/favicon.ico", - + customFields: { + bdToken: process.env.BD_TOKEN, + }, // GitHub pages deployment config. // If you aren't using GitHub pages, you don't need these. organizationName: "labring", // Usually your GitHub org/user name. @@ -198,6 +200,15 @@ const config = { async: false, } ], + headTags: [ + { + tagName: 'meta', + attributes: { + name: 'baidu-site-verification', + content: 'codeva-gAHDaifnOq', + }, + } + ], plugins: [ 'docusaurus-plugin-sass', async function myPlugin (context, options) { diff --git a/docs/website/src/hooks/useUploadData.ts b/docs/website/src/hooks/useUploadData.ts new file mode 100644 index 00000000000..1d4239f7a2a --- /dev/null +++ b/docs/website/src/hooks/useUploadData.ts @@ -0,0 +1,42 @@ +import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; +import { useEffect, useState } from 'react'; +import useIsBrowser from '@docusaurus/useIsBrowser'; + +export default function useUploadData() { + const isBrowser = useIsBrowser(); + const [id, setId] = useState(''); + const { + siteConfig: { customFields } + } = useDocusaurusContext(); + + useEffect(() => { + if (!isBrowser) return; + let bd_vid = sessionStorage.getItem('bd_vid'); + if (bd_vid) setId(bd_vid); + }, [isBrowser]); + + async function uploadConvertData(params: { newType: number }[]) { + if (!isBrowser || !customFields?.bdToken || !id) return; + const url = 'https://ocpc.baidu.com/ocpcapi/api/uploadConvertData'; + const logidUrl = `${window.location.origin}?bd_vid=${id}`; + console.log(customFields, id, '========', logidUrl); + + const data = { + token: customFields.bdToken, + conversionTypes: params.map((newType) => ({ logidUrl: logidUrl, newType: newType })) + }; + + return fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(data) + }); + } + + return { + id, + uploadConvertData + }; +} diff --git a/docs/website/src/pages/components/Header/index.tsx b/docs/website/src/pages/components/Header/index.tsx index 49f2487807c..d1e77f2aa30 100644 --- a/docs/website/src/pages/components/Header/index.tsx +++ b/docs/website/src/pages/components/Header/index.tsx @@ -9,6 +9,7 @@ import LogoIcon from '@site/static/icons/sealos.svg'; import React, { useEffect, useState } from 'react'; import VideoPlayer from '../VideoPlayer'; import './index.scss'; +import useUploadData from '@site/src/hooks/useUploadData'; const navbar = [ { @@ -42,6 +43,7 @@ const HomeHeader = ({ isPc }: { isPc: boolean }) => { const [stars, setStars] = useState(10000); const isBrowser = useIsBrowser(); const { cloudUrl } = useWindow(); + const { uploadConvertData } = useUploadData(); const i18nMap: { [key: string]: { label: string; link: string } } = { en: { label: '中', link: '/zh-Hans/' }, @@ -164,7 +166,20 @@ const HomeHeader = ({ isPc }: { isPc: boolean }) => {
{navbar.map((item) => ( - + { + if (item.key === 'contact') { + console.log('uploadConvertData'); + uploadConvertData([ + { + newType: 51 + } + ]); + } + }} + > {item.label} ))} diff --git a/docs/website/src/pages/index.tsx b/docs/website/src/pages/index.tsx index 585c2352def..418372d6f77 100644 --- a/docs/website/src/pages/index.tsx +++ b/docs/website/src/pages/index.tsx @@ -37,6 +37,12 @@ const Home = () => { loadUmamiScript(); }, []); + useEffect(() => { + const urlParams = new URLSearchParams(window.location.search); + const bd_vidValue = urlParams.get('bd_vid'); + sessionStorage.setItem('bd_vid', bd_vidValue); + }, []); + const HomeRender = (
@@ -52,6 +58,7 @@ const Home = () => { `} + {/* */}
diff --git a/docs/website/src/pages/self-hosting/product/index.tsx b/docs/website/src/pages/self-hosting/product/index.tsx index 887459f7b42..f4b9c884942 100644 --- a/docs/website/src/pages/self-hosting/product/index.tsx +++ b/docs/website/src/pages/self-hosting/product/index.tsx @@ -4,6 +4,7 @@ import React from 'react'; export default function Product() { const standard = ['工单服务', '应用管理', '高可用数据库', '应用市场', '多租户', '计量/配额']; + const company = [ '工单/即时通信服务', '周一到周五, 8h 内响应', @@ -13,6 +14,7 @@ export default function Product() { '多租户', '计量/配额' ]; + const contact = [ '定制化开发与业务云原生化服务', '超大规模集群',