Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:docs add link proxy #4266

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/website/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# Misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
Expand Down
14 changes: 13 additions & 1 deletion docs/website/docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check
const generateAlgoliKey = () => "ce5b8e1e4d0d35ff587caf75ac404df4"
require('dotenv').config()

/** @type {import('@docusaurus/types').Config} */
const config = {
Expand All @@ -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.
Expand Down Expand Up @@ -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: [
Expand All @@ -207,6 +212,13 @@ const config = {
name: 'baidu-site-verification',
content: 'codeva-gAHDaifnOq',
},
},
{
tagName: 'meta',
attributes: {
name: 'baidu-site-verification',
content: 'codeva-E1X5UKtV9p',
},
}
],
plugins: [
Expand Down
9 changes: 5 additions & 4 deletions docs/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -52,4 +53,4 @@
"last 1 safari version"
]
}
}
}
16 changes: 9 additions & 7 deletions docs/website/src/hooks/useUploadData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
};

Expand All @@ -36,7 +38,7 @@ export default function useUploadData() {
}

return {
id,
bd_vid,
uploadConvertData
};
}
8 changes: 1 addition & 7 deletions docs/website/src/hooks/useWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions docs/website/src/pages/components/Header/index.phone.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
border-radius: 4px;
background: rgba(255, 255, 255, 0.2);
filter: blur(4px);
pointer-events: none;
}

.start-now-button {
Expand Down
1 change: 1 addition & 0 deletions docs/website/src/pages/components/Header/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
border-radius: 4px;
background: rgba(255, 255, 255, 0.2);
filter: blur(4px);
pointer-events: none;
}

.start-now-button {
Expand Down
12 changes: 7 additions & 5 deletions docs/website/src/pages/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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/' },
Expand Down Expand Up @@ -133,7 +133,7 @@ const HomeHeader = ({ isPc }: { isPc: boolean }) => {
一样使用 Sealos!
</h3>
)}
<a className="start-now-button" href={cloudUrl} target="_blank">
<a className="start-now-button" href={`${cloudUrl}?bd_vid=${bd_vid}`} target="_blank">
{i18nObj.startNow}
<div className="start-now-button-wrap"></div>
</a>
Expand Down Expand Up @@ -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'));
}
}}
>
Expand All @@ -198,7 +200,7 @@ const HomeHeader = ({ isPc }: { isPc: boolean }) => {
</Link>
</div>
)}
<a className="start-now-button" href={cloudUrl} target="_blank">
<a className="start-now-button" href={`${cloudUrl}?bd_vid=${bd_vid}`} target="_blank">
{i18nObj.startNow}
<div className="start-now-button-wrap"></div>
</a>
Expand Down
2 changes: 0 additions & 2 deletions docs/website/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ const Home = () => {
gtag('event', 'conversion', {'send_to': 'AW-786053845/LpbTCJ-8-coYENX16PYC'});
`}
</script>
<meta name="baidu-site-verification" content="codeva-gAHDaifnOq" />
{/* <script src="./linkInterception.js"></script> */}
</Helmet>
<Layout>
<div className="home">
Expand Down
2 changes: 2 additions & 0 deletions docs/website/src/pages/self-hosting/header/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
border-radius: 4px;
background: rgba(255, 255, 255, 0.2);
filter: blur(4px);
pointer-events: none;
}

.start-now-button {
Expand Down Expand Up @@ -242,6 +243,7 @@
border-radius: 4px;
background: rgba(255, 255, 255, 0.2);
filter: blur(4px);
pointer-events: none;
}

.start-now-button {
Expand Down
23 changes: 23 additions & 0 deletions docs/website/static/global.js
Original file line number Diff line number Diff line change
@@ -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)
}
}
})
})
5 changes: 5 additions & 0 deletions docs/website/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading