This is an automated email from the ASF dual-hosted git repository.

young pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-website.git


The following commit(s) were added to refs/heads/master by this push:
     new d689b3447eb Fix: Added redirection to GitHub index when no hash 
present (#1789)
d689b3447eb is described below

commit d689b3447eb2409a0c3ecbbbe7db256f55bad1d1
Author: Sujan Thapa <[email protected]>
AuthorDate: Mon Jun 3 13:04:47 2024 +0545

    Fix: Added redirection to GitHub index when no hash present (#1789)
---
 doc/src/pages/edit.tsx | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/doc/src/pages/edit.tsx b/doc/src/pages/edit.tsx
index b05c299ac4a..2914c8291b4 100644
--- a/doc/src/pages/edit.tsx
+++ b/doc/src/pages/edit.tsx
@@ -9,6 +9,8 @@ import useDocusaurusContext from 
'@docusaurus/useDocusaurusContext';
 const Edit: FC = () => {
   const [pathExist, setPathExist] = useState(true);
   const [isLoading, setIsLoading] = useState(false);
+  const INDEX_URL = 'https://github.com/apache/apisix';
+
   const {
     i18n: { currentLocale },
   } = useDocusaurusContext();
@@ -20,6 +22,7 @@ const Edit: FC = () => {
     const path = getPath();
 
     setIsLoading(true);
+
     fetch(path.replace('github.com', 
'raw.githubusercontent.com').replace('/edit', ''))
       .then((res) => setPathExist(res.status !== 404))
       .finally(() => setIsLoading(false));
@@ -27,11 +30,17 @@ const Edit: FC = () => {
 
   const edit = useCallback(() => {
     let path = getPath();
+
     if (!pathExist) {
       const pathArr = path.replace('edit', 'new').split('/');
       pathArr[pathArr.length - 1] = `?filename=${pathArr.at(-1)}`;
       path = pathArr.join('/');
     }
+
+    if (!path?.includes(INDEX_URL)) {
+      path = INDEX_URL;
+    }
+
     window.location.replace(path);
   }, [pathExist]);
 
@@ -96,7 +105,7 @@ const Edit: FC = () => {
               <p>
                 {pathExist
                   ? 'When you are ready, click the button below to start 
editing the document.'
-                  : 'You can also still try to edit the document by click the 
below button.'}
+                  : 'You can also still try to edit the document by clicking 
the below button.'}
               </p>
               <button className="edit-btn" type="button" onClick={edit}>
                 Let&apos;s start editing

Reply via email to