summaryrefslogtreecommitdiffstats
path: root/docusaurus/src/theme/NotFound/redirectInput.tsx
blob: 4e29b4a7cf821e1f656f3d46f9727fee542cc376 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
 * @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)
 *
 */