From 1d38776351a17bd85d87512b666c94241490ba78 Mon Sep 17 00:00:00 2001 From: shuai Date: Mon, 17 Feb 2025 14:30:13 +0800 Subject: [PATCH 1/4] fix: add nginx.con file --- Dockerfile | 3 +++ nginx.conf | 31 +++++++++++++++++++++++++ src/components/HomePageHeader/index.tsx | 2 +- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 nginx.conf diff --git a/Dockerfile b/Dockerfile index 5560e5b24f..5a844dede0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,8 @@ FROM nginx:alpine +RUN rm /etc/nginx/conf.d/default.conf +COPY nginx.conf /etc/nginx/conf.d/default.conf + COPY ./build /usr/share/nginx/html EXPOSE 80 diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000000..34009b23bf --- /dev/null +++ b/nginx.conf @@ -0,0 +1,31 @@ +server { + listen 80; + server_name localhost; + + # 静态文件服务 + location / { + root /usr/share/nginx/html; + index index.html; + try_files $uri $uri/ /index.html; + } + + location /github-stars/ { + proxy_pass https://img.shields.io/github/stars/; + proxy_set_header Host img.shields.io; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_ssl_protocols TLSv1.2 TLSv1.3; + proxy_ssl_ciphers HIGH:!aNULL:!MD5; + } + + location /mixpanel/ { + proxy_pass https://api-js.mixpanel.com/track/; + proxy_set_header Host api-js.mixpanel.com; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_pass_request_headers on; + proxy_pass_request_body on; + } +} diff --git a/src/components/HomePageHeader/index.tsx b/src/components/HomePageHeader/index.tsx index 48ed3412a0..e350f56e90 100644 --- a/src/components/HomePageHeader/index.tsx +++ b/src/components/HomePageHeader/index.tsx @@ -40,7 +40,7 @@ const HomeHead: FC = () => { useEffect(() => { - fetch('https://img.shields.io/github/stars/apache/answer') + fetch('/github-stars/apache/answer') .then((response) => response.text()) .then((data) => { const num = data.match(/(.*?)<\/text>/)[1]; From ed149b50c40a20e519fa1dc6de35a0515604dd66 Mon Sep 17 00:00:00 2001 From: shuai Date: Mon, 17 Feb 2025 14:41:40 +0800 Subject: [PATCH 2/4] fix: delete nginx.conf file --- Dockerfile | 3 --- nginx.conf | 31 ------------------------------- 2 files changed, 34 deletions(-) delete mode 100644 nginx.conf diff --git a/Dockerfile b/Dockerfile index 5a844dede0..5560e5b24f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,5 @@ FROM nginx:alpine -RUN rm /etc/nginx/conf.d/default.conf -COPY nginx.conf /etc/nginx/conf.d/default.conf - COPY ./build /usr/share/nginx/html EXPOSE 80 diff --git a/nginx.conf b/nginx.conf deleted file mode 100644 index 34009b23bf..0000000000 --- a/nginx.conf +++ /dev/null @@ -1,31 +0,0 @@ -server { - listen 80; - server_name localhost; - - # 静态文件服务 - location / { - root /usr/share/nginx/html; - index index.html; - try_files $uri $uri/ /index.html; - } - - location /github-stars/ { - proxy_pass https://img.shields.io/github/stars/; - proxy_set_header Host img.shields.io; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_ssl_protocols TLSv1.2 TLSv1.3; - proxy_ssl_ciphers HIGH:!aNULL:!MD5; - } - - location /mixpanel/ { - proxy_pass https://api-js.mixpanel.com/track/; - proxy_set_header Host api-js.mixpanel.com; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_pass_request_headers on; - proxy_pass_request_body on; - } -} From 7ad09ede0ff5654966d1f4d8ff8db43da5a01604 Mon Sep 17 00:00:00 2001 From: shuai Date: Mon, 17 Feb 2025 14:42:56 +0800 Subject: [PATCH 3/4] fix: fetch url change --- src/components/HomePageHeader/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/HomePageHeader/index.tsx b/src/components/HomePageHeader/index.tsx index e350f56e90..48ed3412a0 100644 --- a/src/components/HomePageHeader/index.tsx +++ b/src/components/HomePageHeader/index.tsx @@ -40,7 +40,7 @@ const HomeHead: FC = () => { useEffect(() => { - fetch('/github-stars/apache/answer') + fetch('https://img.shields.io/github/stars/apache/answer') .then((response) => response.text()) .then((data) => { const num = data.match(/(.*?)<\/text>/)[1]; From e3a2cc4e5246f5f3dea0a91ef9df9d20d76a2f61 Mon Sep 17 00:00:00 2001 From: shuai Date: Mon, 17 Feb 2025 15:09:42 +0800 Subject: [PATCH 4/4] fix: heade add scp meta tag --- docusaurus.config.js | 5 +++ src/theme/Heading/index.tsx | 63 +++++++++++++++++++++++++++++ src/theme/Heading/styles.module.css | 35 ++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 src/theme/Heading/index.tsx create mode 100644 src/theme/Heading/styles.module.css diff --git a/docusaurus.config.js b/docusaurus.config.js index 8655389dd2..c1d91abd18 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -82,6 +82,11 @@ const config = { ({ metadata: [ {name: 'keywords', content: 'Free, Open-source, Q&A Platform, Knowledge Sharing Platform, Community Forum, Knowledge Base, Developer Hub, Support Center'}, + { + name: 'http-equiv', + content: 'Content-Security-Policy', + value: "default-src 'self' data: blob: 'unsafe-inline' https://www.apachecon.com/ https://www.communityovercode.org/ https://analytics.apache.org/ https://api-js.mixpanel.com/track/; connect-src https://api-js.mixpanel.com/track/;" + } ], colorMode: { defaultMode: 'light', diff --git a/src/theme/Heading/index.tsx b/src/theme/Heading/index.tsx new file mode 100644 index 0000000000..1384e02383 --- /dev/null +++ b/src/theme/Heading/index.tsx @@ -0,0 +1,63 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import React from 'react'; +import clsx from 'clsx'; +import {translate} from '@docusaurus/Translate'; +import {useThemeConfig} from '@docusaurus/theme-common'; +import Link from '@docusaurus/Link'; +import useBrokenLinks from '@docusaurus/useBrokenLinks'; +import type {Props} from '@theme/Heading'; + +import styles from './styles.module.css'; + +export default function Heading({as: As, id, ...props}: Props): JSX.Element { + const brokenLinks = useBrokenLinks(); + const { + navbar: {hideOnScroll}, + } = useThemeConfig(); + // H1 headings do not need an id because they don't appear in the TOC. + if (As === 'h1' || !id) { + return ; + } + + brokenLinks.collectAnchor(id); + + const anchorTitle = translate( + { + id: 'theme.common.headingLinkTitle', + message: 'Direct link to {heading}', + description: 'Title for link to heading', + }, + { + heading: typeof props.children === 'string' ? props.children : id, + }, + ); + + return ( + + + {props.children} + + ​ + + + ); +} diff --git a/src/theme/Heading/styles.module.css b/src/theme/Heading/styles.module.css new file mode 100644 index 0000000000..1b7c5cdbd6 --- /dev/null +++ b/src/theme/Heading/styles.module.css @@ -0,0 +1,35 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/* +When the navbar is sticky, ensure that on anchor click, +the browser does not scroll that anchor behind the navbar +See https://twitter.com/JoshWComeau/status/1332015868725891076 + */ +.anchorWithStickyNavbar { + scroll-margin-top: calc(var(--ifm-navbar-height) + 0.5rem); +} + +.anchorWithHideOnScrollNavbar { + scroll-margin-top: 0.5rem; +} + +:global(.hash-link) { + opacity: 0; + padding-left: 0.5rem; + transition: opacity var(--ifm-transition-fast); + user-select: none; +} + +:global(.hash-link::before) { + content: '#'; +} + +:global(.hash-link:focus), +:global(*:hover > .hash-link) { + opacity: 1; +}