From 72d8b4e6bee0ffac79e96dd649a9da2adb86b507 Mon Sep 17 00:00:00 2001 From: name Date: Wed, 27 Sep 2023 11:34:23 +0000 Subject: 2023-09-26 --- docusaurus/src/theme/NotFound/DDoSProtection.tsx | 13 +---- docusaurus/src/theme/NotFound/Redirection.tsx | 59 ++++++++++++++++++++ docusaurus/src/theme/NotFound/index.tsx | 37 +++++-------- docusaurus/src/theme/NotFound/redirectInput.tsx | 70 ------------------------ 4 files changed, 77 insertions(+), 102 deletions(-) create mode 100644 docusaurus/src/theme/NotFound/Redirection.tsx delete mode 100644 docusaurus/src/theme/NotFound/redirectInput.tsx (limited to 'docusaurus/src/theme/NotFound') diff --git a/docusaurus/src/theme/NotFound/DDoSProtection.tsx b/docusaurus/src/theme/NotFound/DDoSProtection.tsx index 6cd8c04..b861669 100644 --- a/docusaurus/src/theme/NotFound/DDoSProtection.tsx +++ b/docusaurus/src/theme/NotFound/DDoSProtection.tsx @@ -1,19 +1,14 @@ -/** - * @license - * SPDX-License-Identifier: AGPL-3.0-or-later - * This file is part of Wolfree. - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - */ +/* SPDX-License-Identifier: AGPL-3.0-or-later */ import React from "react"; -const DDoSProtection = () => ( +export default (): React.JSX.Element => (
@@ -30,5 +25,3 @@ const DDoSProtection = () => (
); - -export default DDoSProtection; diff --git a/docusaurus/src/theme/NotFound/Redirection.tsx b/docusaurus/src/theme/NotFound/Redirection.tsx new file mode 100644 index 0000000..3fe2d6d --- /dev/null +++ b/docusaurus/src/theme/NotFound/Redirection.tsx @@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: AGPL-3.0-or-later */ + +import React from "react"; +import typescriptNever from "../../functions/typescriptNever"; + +export default (): React.JSX.Element => { + React.useEffect((): void => { + const pathname = window.location.pathname; + + const isExample = pathname.includes("/example"); + + if (isExample === true) { + const topic = "topic " + pathname.split("/").pop().replace(/-/g, " "); + const url = new URL("/input/", window.location.href); + url.searchParams.set("i", topic); + window.location.replace(url); + } else if (isExample === false) { + window.location.replace("/"); + } else { + window.location.replace("/"); + typescriptNever(isExample); + } + }, []); // Empty dependency array means the effect runs only once after initial render. + + return <>; +}; + +/* + * test case: + * + * - Passing + * - elementary-math + * - Goal: https://www.wolframalpha.com/examples/mathematics/elementary-math + * - Doesn't work: http://localhost/input?i=elementary+math + * - Does work: http://localhost/input?i=topic+elementary+math + * - common-core-math-functions + * - Goal: https://wc.wolframalpha.com/examples/mathematics/common-core-math/common-core-math-functions + * - Doesn't work: http://localhost/input?i=common+core+math+functions + * - Does work: http://localhost/input?i=topic+common+core+math+functions + * + * - Failing + * - continuity + * - Goal: https://www.wolframalpha.com/examples/mathematics/calculus-and-analysis/continuity + * - Does not work: http://localhost/input?i=topic+continuity + * - Does work: (not found yet) + * - neuroscience + * - Goal: https://www.wolframalpha.com/examples/science-and-technology/life-sciences/neuroscience + * - Does not work: http://localhost/input?i=topic+neuroscience + * - Does work: (not found yet) + * - molecular-biology + * - Goal: https://wc.wolframalpha.com/examples/science-and-technology/life-sciences/molecular-biology + * - Does not work: http://localhost/input?i=topic+molecular+biology + * - Does work: (not found yet) + * - personal-finance + * - Goal: https://www.wolframalpha.com/examples/everyday-life/personal-finance + * - Does not work: http://localhost/input?i=topic+personal+finance + * - Does work: (not found yet) + * + */ diff --git a/docusaurus/src/theme/NotFound/index.tsx b/docusaurus/src/theme/NotFound/index.tsx index d5e0208..15e9fe6 100644 --- a/docusaurus/src/theme/NotFound/index.tsx +++ b/docusaurus/src/theme/NotFound/index.tsx @@ -1,28 +1,21 @@ -/** - * @license - * SPDX-License-Identifier: AGPL-3.0-or-later - * This file is part of Wolfree. - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - */ +/* SPDX-License-Identifier: AGPL-3.0-or-later */ -import React from "react"; -import NotFound from "@theme-original/NotFound"; -import redirectInput from "./redirectInput"; import DDoSProtection from "./DDoSProtection"; +import NotFound from "@theme-original/NotFound"; +import React from "react"; +import Redirection from "./Redirection"; -const NotFoundWrapper = (props: React.JSX.IntrinsicAttributes) => { - redirectInput(); - return ( - <> - -
- -
- - ); -}; - -export default NotFoundWrapper; +export default ( + props: React.JSX.ElementAttributesProperty +): React.JSX.Element => ( + <> + + +
+ +
+ +); // How can I customize the 404 page? · facebook/docusaurus · Discussion #6030 // https://github.com/facebook/docusaurus/discussions/6030 diff --git a/docusaurus/src/theme/NotFound/redirectInput.tsx b/docusaurus/src/theme/NotFound/redirectInput.tsx deleted file mode 100644 index 4e29b4a..0000000 --- a/docusaurus/src/theme/NotFound/redirectInput.tsx +++ /dev/null @@ -1,70 +0,0 @@ -/** - * @license - * SPDX-License-Identifier: AGPL-3.0-or-later - * This file is part of Wolfree. - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - */ - -import { useEffect } from "react"; - -const redirectInput = () => { - useEffect(() => { - const redirectToInputPage = () => { - const pathname = window.location.pathname; - - const isExample = pathname.includes("/example"); - if (!isExample) { - window.location.href = "/"; - return; - } - - const filename = pathname.split("/").pop(); - if (!filename) { - window.location.href = "/"; - return; - } - - const topic = "topic " + filename.replace(/-/g, " "); - const url = new URL("/input/", window.location.href); - url.searchParams.set("i", topic); - window.location.href = url.href; - }; - - redirectToInputPage(); - }, []); // The effect runs only once on mount -}; - -export default redirectInput; - -/* - * test case: - * - * - Passing - * - elementary-math - * - Goal: https://www.wolframalpha.com/examples/mathematics/elementary-math - * - Doesn't work: http://localhost/input?i=elementary+math - * - Does work: http://localhost/input?i=topic+elementary+math - * - common-core-math-functions - * - Goal: https://wc.wolframalpha.com/examples/mathematics/common-core-math/common-core-math-functions - * - Doesn't work: http://localhost/input?i=common+core+math+functions - * - Does work: http://localhost/input?i=topic+common+core+math+functions - * - * - Failing - * - continuity - * - Goal: https://www.wolframalpha.com/examples/mathematics/calculus-and-analysis/continuity - * - Does not work: http://localhost/input?i=topic+continuity - * - Does work: (not found yet) - * - neuroscience - * - Goal: https://www.wolframalpha.com/examples/science-and-technology/life-sciences/neuroscience - * - Does not work: http://localhost/input?i=topic+neuroscience - * - Does work: (not found yet) - * - molecular-biology - * - Goal: https://wc.wolframalpha.com/examples/science-and-technology/life-sciences/molecular-biology - * - Does not work: http://localhost/input?i=topic+molecular+biology - * - Does work: (not found yet) - * - personal-finance - * - Goal: https://www.wolframalpha.com/examples/everyday-life/personal-finance - * - Does not work: http://localhost/input?i=topic+personal+finance - * - Does work: (not found yet) - * - */ -- cgit v1.2.3