SkyeYoung commented on code in PR #1789:
URL: https://github.com/apache/apisix-website/pull/1789#discussion_r1584227559
##########
doc/src/pages/edit.tsx:
##########
@@ -20,18 +22,26 @@ const Edit: FC = () => {
const path = getPath();
setIsLoading(true);
+
+ if (path === '' || !path.includes('https://github.com/apache')) {
+ setPathExist(false);
+ setIsLoading(false);
+ return;
+ }
+
fetch(path.replace('github.com',
'raw.githubusercontent.com').replace('/edit', ''))
.then((res) => setPathExist(res.status !== 404))
.finally(() => setIsLoading(false));
}, []);
const edit = useCallback(() => {
- let path = getPath();
+ const path = getPath();
+
if (!pathExist) {
- const pathArr = path.replace('edit', 'new').split('/');
- pathArr[pathArr.length - 1] = `?filename=${pathArr.at(-1)}`;
- path = pathArr.join('/');
Review Comment:
This logic will actually jump to the github url of "Create a new file".
The working logic is: The document site uses English as fallback, and when
documents in Chinese or other languages do not exist, they will automatically
be displayed in English. But at this time, `edit url` will still use the path
of the corresponding language.
For example, `/xxx` exists, but the document `/zh/xxx` does not exist.
Assume that the edit url of the latter is `github/zh/xxx`. Since the document
does not exist at this time, the content in `/xxx` will be displayed, but the
edit url Still `github/zh/xxx`. Apparently at this point, (at least I thought
so,) clicking this link should create this non-existent `/zh/xxx`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]