This is an automated email from the ASF dual-hosted git repository.
guoqi 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 c716ceb6e4f fix: edit this page (#1422)
c716ceb6e4f is described below
commit c716ceb6e4fad34febd8562f7f25e599bbc61678
Author: Young <[email protected]>
AuthorDate: Tue Nov 29 09:03:49 2022 +0800
fix: edit this page (#1422)
---
.gitignore | 3 +-
doc/docusaurus.config.js | 70 +++++++++-----------
doc/src/css/edit.scss | 48 ++++++++++++++
doc/src/pages/edit.tsx | 154 ++++++++++++++++++++++++++++++++++++++++++++
scripts/generate-website.js | 7 ++
5 files changed, 240 insertions(+), 42 deletions(-)
diff --git a/.gitignore b/.gitignore
index 15c62d28128..be0ecfa9e36 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,7 +20,6 @@ lib/core/MetadataBlog.js
/blog/en/config/picked-posts-info.js
/blog/zh/config/picked-posts-info.js
-
# misc
.DS_Store
.env.local
@@ -49,3 +48,5 @@ scripts/yarn.lock
/doc/i18n/zh/docusaurus-plugin-content-docs-docs-*/**
scripts/temp/**
/config/repos-info.json
+/website/src/pages/edit.*
+/website/src/css/edit.*
diff --git a/doc/docusaurus.config.js b/doc/docusaurus.config.js
index 0e3debe96c3..ec1f63ec09f 100644
--- a/doc/docusaurus.config.js
+++ b/doc/docusaurus.config.js
@@ -1,14 +1,18 @@
const { ssrTemplate } = require('../config/ssrTemplate');
-const getEditUrl = ({
- projectName,
- version,
- locale,
- docPath,
- defaultBranch = 'master',
-}) => (version === 'current'
- ?
`https://github.com/apache/${projectName}/edit/${defaultBranch}/docs/${locale}/latest/${docPath}`
- : null);
+const getEditUrl = (props) => {
+ const {
+ projectName, version, locale, docPath, defaultBranch = 'master',
+ } = props;
+ // eslint-disable-next-line no-nested-ternary
+ const ver = version === 'current'
+ ? defaultBranch
+ : projectName === 'apisix-ingress-controller'
+ ? `v${version}`
+ : `release/${version}`;
+
+ return `${locale === 'zh' ? '/zh' :
''}/edit#https://github.com/apache/${projectName}/edit/${ver}/docs/${locale}/latest/${docPath}`;
+};
module.exports = {
title: 'Apache APISIX® -- Cloud-Native API Gateway',
@@ -80,12 +84,10 @@ module.exports = {
showLastUpdateTime: true,
routeBasePath: '/docs/apisix',
sidebarPath: require.resolve('./docs/apisix/sidebars.json'),
- editUrl({ docPath, version, locale }) {
+ editUrl(props) {
return getEditUrl({
+ ...props,
projectName: 'apisix',
- locale,
- docPath,
- version,
});
},
versions: {
@@ -104,12 +106,10 @@ module.exports = {
showLastUpdateTime: true,
routeBasePath: '/docs/dashboard',
sidebarPath: require.resolve('./docs/apisix-dashboard/sidebars.json'),
- editUrl({ docPath, version, locale }) {
+ editUrl(props) {
return getEditUrl({
+ ...props,
projectName: 'apisix-dashboard',
- locale,
- docPath,
- version,
});
},
},
@@ -125,12 +125,10 @@ module.exports = {
sidebarPath: require.resolve(
'./docs/apisix-ingress-controller/sidebars.json',
),
- editUrl({ docPath, version, locale }) {
+ editUrl(props) {
return getEditUrl({
+ ...props,
projectName: 'apisix-ingress-controller',
- locale,
- docPath,
- version,
});
},
},
@@ -144,12 +142,10 @@ module.exports = {
showLastUpdateTime: true,
routeBasePath: '/docs/helm-chart',
sidebarPath: require.resolve('./docs/apisix-helm-chart/sidebars.json'),
- editUrl({ docPath, version, locale }) {
+ editUrl(props) {
return getEditUrl({
+ ...props,
projectName: 'apisix-helm-chart',
- locale,
- docPath,
- version,
});
},
},
@@ -163,12 +159,10 @@ module.exports = {
showLastUpdateTime: true,
routeBasePath: '/docs/docker',
sidebarPath: require.resolve('./docs/apisix-docker/sidebars.json'),
- editUrl({ docPath, version, locale }) {
+ editUrl(props) {
return getEditUrl({
+ ...props,
projectName: 'apisix-docker',
- locale,
- docPath,
- version,
});
},
},
@@ -184,12 +178,10 @@ module.exports = {
sidebarPath: require.resolve(
'./docs/apisix-java-plugin-runner/sidebars.json',
),
- editUrl({ docPath, version, locale }) {
+ editUrl(props) {
return getEditUrl({
+ ...props,
projectName: 'apisix-java-plugin-runner',
- locale,
- docPath,
- version,
defaultBranch: 'main',
});
},
@@ -206,12 +198,10 @@ module.exports = {
sidebarPath: require.resolve(
'./docs/apisix-go-plugin-runner/sidebars.json',
),
- editUrl({ docPath, version, locale }) {
+ editUrl(props) {
return getEditUrl({
+ ...props,
projectName: 'apisix-go-plugin-runner',
- locale,
- docPath,
- version,
});
},
},
@@ -227,12 +217,10 @@ module.exports = {
sidebarPath: require.resolve(
'./docs/apisix-python-plugin-runner/sidebars.json',
),
- editUrl({ docPath, version, locale }) {
+ editUrl(props) {
return getEditUrl({
+ ...props,
projectName: 'apisix-python-plugin-runner',
- locale,
- docPath,
- version,
});
},
},
diff --git a/doc/src/css/edit.scss b/doc/src/css/edit.scss
new file mode 100644
index 00000000000..682d2b97fc4
--- /dev/null
+++ b/doc/src/css/edit.scss
@@ -0,0 +1,48 @@
+.page {
+ max-width: var(--ifm-container-width);
+ margin: 0 auto;
+ padding: 2rem var(--ifm-spacing-horizontal);
+ width: 45%;
+
+ a {
+ color: var(--color-primary) !important;
+ }
+}
+
+.page-title {
+ font-size: 2.5rem;
+ font-weight: 800;
+ margin-top: 2rem;
+}
+
+p {
+ font-size: 1.2rem;
+ line-height: 1.5;
+ margin: 1rem 0;
+ color: #666;
+}
+
+.edit-btn {
+ padding: 12px 18px;
+ font-size: 18px;
+ font-weight: 600;
+ border-radius: 0.5rem;
+ transition: all 0.3s ease 0s;
+ background: var(--color-primary);
+ color: white;
+ border: none;
+ box-sizing: border-box;
+ display: flex;
+ flex-direction: row;
+ -webkit-box-align: center;
+ align-items: center;
+ -webkit-box-pack: center;
+ justify-content: center;
+ cursor: pointer;
+ margin-top: 2rem;
+ margin-bottom: 8rem;
+
+ &:hover {
+ filter: brightness(105%);
+ }
+}
diff --git a/doc/src/pages/edit.tsx b/doc/src/pages/edit.tsx
new file mode 100644
index 00000000000..b05c299ac4a
--- /dev/null
+++ b/doc/src/pages/edit.tsx
@@ -0,0 +1,154 @@
+import type { FC } from 'react';
+import React, { useCallback, useState, useEffect } from 'react';
+import Layout from '@theme/Layout';
+import Head from '@docusaurus/Head';
+import Link from '@docusaurus/Link';
+import '../css/edit.scss';
+import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
+
+const Edit: FC = () => {
+ const [pathExist, setPathExist] = useState(true);
+ const [isLoading, setIsLoading] = useState(false);
+ const {
+ i18n: { currentLocale },
+ } = useDocusaurusContext();
+ const title = currentLocale.startsWith('en') ? 'Before editing docs' :
'编辑文档前';
+
+ const getPath = () => window.location.hash.slice(1);
+
+ useEffect(() => {
+ const path = getPath();
+
+ setIsLoading(true);
+ 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();
+ if (!pathExist) {
+ const pathArr = path.replace('edit', 'new').split('/');
+ pathArr[pathArr.length - 1] = `?filename=${pathArr.at(-1)}`;
+ path = pathArr.join('/');
+ }
+ window.location.replace(path);
+ }, [pathExist]);
+
+ return (
+ <Layout>
+ <Head>
+ <meta
+ name="twitter:title"
+ content={`${title} - Apache APISIX® - Cloud-Native API Gateway`}
+ />
+ <meta
+ name="twitter:description"
+ content="Apache APISIX is a dynamic, real-time, high-performance
Cloud-Native API gateway, based on the Nginx library and etcd."
+ />
+ <meta name="twitter:site" content="@apacheapisix" />
+ <meta
+ name="og:description"
+ content="Apache APISIX is a dynamic, real-time, high-performance
Cloud-Native API gateway, based on the Nginx library and etcd."
+ />
+ </Head>
+ {!isLoading && (
+ <div className="page">
+ <h1 className="page-title">{title}</h1>
+ {currentLocale.startsWith('en') && (
+ <>
+ <p>
+ First, thank you for your willingness to contribute to the
documentation of Apache
+ APISIX and affiliated projects.
+ </p>
+ <p>
+ But before you begin, please have a look and understand the
+ {' '}
+ <Link
+ style={{
+ color: `var(--color-primary)`,
+ }}
+
href="https://apisix.apache.org/docs/general/documentation-style-guide/"
+ >
+ Documentation Style Guide
+ </Link>
+ {' '}
+ to help you complete your contribution more efficiently and
seamlessly.
+ </p>
+ {!pathExist && (
+ <>
+ {' '}
+ <p>
+ ...But, We could not find what you were looking for. If
you find the doc exist,
+ and this link should not be broken, please
+ {' '}
+ <Link
+
href="https://github.com/apache/apisix-website/issues/new/choose"
+ target="_blank"
+ rel="noreferrer"
+ >
+ submit an Issue
+ </Link>
+ .
+ </p>
+ </>
+ )}
+ <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.'}
+ </p>
+ <button className="edit-btn" type="button" onClick={edit}>
+ Let's start editing
+ </button>
+ </>
+ )}
+ {currentLocale.startsWith('zh') && (
+ <>
+ <p>首先,感谢您愿意向 Apache APISIX 及其相关项目贡献文档。</p>
+ <p>
+ 但在开始之前,请先阅读并充分理解
+ {' '}
+ <Link
href="https://apisix.apache.org/docs/general/documentation-style-guide/">
+ Documentation Style Guide
+ </Link>
+ {' '}
+ 来帮助您快速了解如何贡献文档。
+ </p>
+ {!pathExist && (
+ <>
+ {' '}
+ <p>
+ 然而,我们现在无法找到这篇文档,一般情况下,这是因为英文文档尚未被翻译为对应的中文文档。
+ </p>
+ <p>
+ 如果您在检查后发现该链接对应的文档已经存在,请向 APISIX Website
+ {' '}
+ <Link
+
href="https://github.com/apache/apisix-website/issues/new/choose"
+ target="_blank"
+ rel="noreferrer"
+ >
+ 提交 Issue
+ </Link>
+ 。
+ </p>
+ </>
+ )}
+ <p>
+ {pathExist
+ ? '当您准备完成后,单击下方按钮,以开始编辑文档。'
+ : '如果不存在,欢迎您点击下方按钮,向 Apache APISIX
社区贡献英文对应的中文文档。或者您也可以先尝试编辑英文文档。'}
+ </p>
+ <button className="edit-btn" type="button" onClick={edit}>
+ {pathExist ? '开始编辑' : '创建翻译'}
+ </button>
+ </>
+ )}
+ </div>
+ )}
+ </Layout>
+ );
+};
+
+export default Edit;
diff --git a/scripts/generate-website.js b/scripts/generate-website.js
index 5c25223c99a..0efa4371ccc 100644
--- a/scripts/generate-website.js
+++ b/scripts/generate-website.js
@@ -8,6 +8,13 @@ const tasks = new Listr([
title: `Change working dir`,
task: () => chdir('../'),
},
+ {
+ title: `Copy docs edit to website`,
+ task: () => Promise.allSettled([
+ exec('cp ./doc/src/css/edit.scss ./website/src/css'),
+ exec('cp ./doc/src/pages/edit.tsx ./website/src/pages'),
+ ]),
+ },
{
title: `Build website's all parts`,
task: () => Promise.allSettled([