diff --git a/gatsby-node.js b/gatsby-node.js index b76993c91dcd2846786f20ace096f74ca5a8be13..0d1ab8752afd875b7caa958f416ec6c8ae19b88d 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -81,7 +81,8 @@ exports.createPages = async ({ graphql, actions }) => { } // 创建文档页面 - docs.data.allMarkdownRemark.nodes.forEach((node) => { + const allDocsNodes = docs.data.allMarkdownRemark.nodes + allDocsNodes.forEach((node) => { const { slug, lang, version, docType, fileName, relativePath } = node.fields // 处理语法树 @@ -107,6 +108,25 @@ exports.createPages = async ({ graphql, actions }) => { slug, lang, version, docType, fileName, relativePath, diagramTree } }) + + // 处理中文版本存在,英文版本不存在的情况,创建中文页面 + if (lang === 'zh') { + const enPath = `/en/${docType}/${version}/${fileName}` + const isExits = allDocsNodes.find(item => item.fields.slug === enPath) + if (!isExits) { + createPage({ + path: enPath, + component: path.resolve('./src/templates/doc.js'), + context: { + tocPath: `/en/${docType}/${version}/toc`, + slug, + lang: 'en', + realSlug: enPath, + version, docType, fileName, relativePath, diagramTree + } + }) + } + } }) // 创建页面重定向,如:/ /zh /zh/mogdb /zh/mogdb/v2.1.0 等URL,重定向到产品指定版本的首页 const createPageRedirect = (fromPath, toPath) => { diff --git a/src/styles/doc.scss b/src/styles/doc.scss index 9eeccd7e1d45101502edeac5bc32d513630ea3d7..1cf76e1af231a52ef3ed25385272cb7d0158bb9c 100644 --- a/src/styles/doc.scss +++ b/src/styles/doc.scss @@ -24,6 +24,18 @@ flex-shrink: 0; background: #FFFFFF; } + & .page-not-found { + padding: 4px; + border-radius: 2px; + background: #f5f6f8; + margin-bottom: 12px; + & .text { + transform: scale(.9); + font-size: 12px; + color: #303133; + transform-origin: left center; + } + } } // 文档目录菜单 .doc-directory-box { diff --git a/src/templates/components/docDirectoryMenu.js b/src/templates/components/docDirectoryMenu.js index 60705a08f53e2b0b509a75791eb552241af0c947..880c1ce94c97e9bcf73b2dfae8b9b5102c5ba288 100644 --- a/src/templates/components/docDirectoryMenu.js +++ b/src/templates/components/docDirectoryMenu.js @@ -4,10 +4,10 @@ import { Tooltip } from 'antd' // 文档目录菜单 const DocDirectoryMenu = ({ tableOfContents, pageContext }) => { - const { lang, slug, relativePath } = pageContext + const { lang, slug, relativePath, realSlug } = pageContext const docMenu = tableOfContents.replace(/\/#/g, '#') const [scrollTop, setScrollTop] = useState(0) - const issueHref = `https://gitee.com/enmotech/mogdb-docs/issues/new?&description=原始文件:[/${relativePath}](https://docs.mogdb.io${slug})` + const issueHref = `https://gitee.com/enmotech/mogdb-docs/issues/new?&description=原始文件:[/${relativePath}](https://docs.mogdb.io${realSlug || slug})` useEffect(() => { // 获取当前滚动的高度 diff --git a/src/templates/components/docPageMenu.js b/src/templates/components/docPageMenu.js index dd809de4903f81e417c67bad06f01222b8c1f68b..ace47ad52be816d0804c9ff062c1db22882a86c9 100644 --- a/src/templates/components/docPageMenu.js +++ b/src/templates/components/docPageMenu.js @@ -2,7 +2,7 @@ import * as React from "react" // 文档底部上一页下一页切换菜单 const DocPageMenu = ({ tocNodes, pageContext }) => { - const { lang, version, docType, slug } = pageContext || {} + const { lang, version, docType, realSlug, slug } = pageContext || {} const pageMenuArr = [] @@ -12,7 +12,8 @@ const DocPageMenu = ({ tocNodes, pageContext }) => { const urlPrefix = `/${lang}/${docType}/${version}/` - const activeIdx = tocList.findIndex(i => urlPrefix + i === slug) + const pageSlug = realSlug || slug + const activeIdx = tocList.findIndex(i => urlPrefix + i === pageSlug) if (activeIdx > 0) { pageMenuArr.push({ diff --git a/src/templates/components/docToc.js b/src/templates/components/docToc.js index 55abee28c39cf3044eb786462c4464c9a901ac85..00a16d4bba4a0b91f5060b5740453354cb9ffeb8 100644 --- a/src/templates/components/docToc.js +++ b/src/templates/components/docToc.js @@ -8,11 +8,11 @@ import html from './remark-html' // 版本切换 const DocToc = (props) => { const { tocNodes, pageContext } = props; - const { lang, version, docType, slug } = pageContext + const { lang, version, docType, slug, realSlug } = pageContext const tocRef = useRef(null) const tocLinkPrefix = `/${lang}/${docType}/${version}/` const _html = remark() - .use(html, { sanitize: true, tocLinkPrefix, slug }) + .use(html, { sanitize: true, tocLinkPrefix, slug: realSlug || slug }) .processSync(tocNodes) const bindClickEventToTOC = () => { diff --git a/src/templates/doc.js b/src/templates/doc.js index 4276caed4f8aee23d60cc9ab17acca312814a6e5..8801d653ec35ca8c7068c2858c287ad6cfbdf9f1 100644 --- a/src/templates/doc.js +++ b/src/templates/doc.js @@ -21,7 +21,7 @@ import DocDirectoryMenu from './components/docDirectoryMenu' const DocTmptPage = ({ data, pageContext }) => { const { frontmatter, html, tableOfContents } = data.docNode - const { lang, diagramTree } = pageContext + const { lang, diagramTree, realSlug } = pageContext const domRef = useRef(null); useLayoutEffect(() => { @@ -94,6 +94,7 @@ const DocTmptPage = ({ data, pageContext }) => {
+ { realSlug &&
Note: Relevant language content is not yet available.
}