Skip to content

Commit c023e07

Browse files
author
YiniXu9506
committed
chore: add ja app dev docs
1 parent 45be58a commit c023e07

File tree

21 files changed

+331
-45
lines changed

21 files changed

+331
-45
lines changed

create-pages/doc.js

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const {
88
genVersionChunks,
99
} = require('./utils')
1010

11+
const languages = ['en', 'zh', 'ja']
12+
1113
const createDocs = async ({ graphql, createPage, createRedirect }) => {
1214
const docTemplate = path.resolve(`${__dirname}/../src/templates/doc.js`)
1315

@@ -69,6 +71,35 @@ const createDocs = async ({ graphql, createPage, createRedirect }) => {
6971
}
7072
`)
7173

74+
const docsJa = await graphql(`
75+
query {
76+
allMdx(
77+
filter: {
78+
fields: { langCollection: { eq: "markdown-pages/contents/ja" } }
79+
fileAbsolutePath: { regex: "/^(?!.*TOC).*$/" }
80+
frontmatter: { draft: { ne: true } }
81+
}
82+
) {
83+
nodes {
84+
id
85+
fields {
86+
langCollection
87+
}
88+
frontmatter {
89+
aliases
90+
}
91+
parent {
92+
... on File {
93+
relativeDirectory
94+
relativePath
95+
base
96+
}
97+
}
98+
}
99+
}
100+
}
101+
`)
102+
72103
// create pages for different language docs
73104
function _createDocs(docs, locale, pathPrefix = '') {
74105
const nodes = docs.data.allMdx.nodes
@@ -83,12 +114,23 @@ const createDocs = async ({ graphql, createPage, createRedirect }) => {
83114
const _fullPath = `${replacePath(relativeDir, base)}`
84115
const fullPath = `${pathPrefix}${_fullPath}`
85116
node.path = fullPath
86-
const filePathInDiffLang = path.resolve(
87-
`${__dirname}/../markdown-pages/contents${
88-
locale === 'en' ? '/zh/' : '/en/'
89-
}${relativePath}`
90-
)
91-
node.langSwitchable = fs.existsSync(filePathInDiffLang) ? true : false
117+
const switchableLangs = {}
118+
119+
languages.forEach((lang) => {
120+
if (locale != lang) {
121+
const filePathInDiffLang = path.resolve(
122+
`${__dirname}/../markdown-pages/contents/${lang}/${relativePath}`
123+
)
124+
125+
iSSwitchable = fs.existsSync(filePathInDiffLang) ? true : false
126+
127+
switchableLangs[lang] = iSSwitchable
128+
} else {
129+
switchableLangs[lang] = true
130+
}
131+
})
132+
133+
node.switchableLangs = switchableLangs
92134
const vChunks = genVersionChunks(_fullPath)
93135
node.version = vChunks[0]
94136
node.pathWithoutVersion = vChunks[1]
@@ -115,7 +157,7 @@ const createDocs = async ({ graphql, createPage, createRedirect }) => {
115157
pathPrefix,
116158
tocPath,
117159
parent,
118-
langSwitchable,
160+
switchableLangs,
119161
} = node
120162
createPage({
121163
path: path,
@@ -131,7 +173,7 @@ const createDocs = async ({ graphql, createPage, createRedirect }) => {
131173
downloadURL,
132174
fullPath: path,
133175
versions: versionsMap[node.pathWithoutVersion],
134-
langSwitchable,
176+
switchableLangs,
135177
},
136178
})
137179

@@ -152,6 +194,7 @@ const createDocs = async ({ graphql, createPage, createRedirect }) => {
152194

153195
_createDocs(docsEn, 'en')
154196
_createDocs(docsZh, 'zh', '/zh')
197+
_createDocs(docsJa, 'ja', '/ja')
155198
}
156199

157200
module.exports = createDocs

create-pages/intl.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ const createIntlPages = ({ page, actions }) => {
3535
},
3636
})
3737
)
38+
39+
if (pagePath === '/search/') {
40+
createPage({
41+
...page,
42+
path: `/ja${pagePath}`,
43+
context: {
44+
...page.context,
45+
locale: 'ja',
46+
},
47+
})
48+
}
3849
}
3950

4051
module.exports = createIntlPages

gatsby-config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ module.exports = {
4040
path: `${__dirname}/markdown-pages/contents/zh`,
4141
},
4242
},
43+
{
44+
resolve: `gatsby-source-filesystem`,
45+
options: {
46+
name: `markdown-pages/contents/ja`,
47+
path: `${__dirname}/markdown-pages/contents/ja`,
48+
},
49+
},
4350
{
4451
resolve: `gatsby-plugin-mdx`,
4552
options: {
@@ -87,7 +94,7 @@ module.exports = {
8794
resolve: `gatsby-plugin-sitemap`,
8895
options: {
8996
output: `/sitemap.xml`,
90-
exclude: ['/404', '/zh/404', '/search', '/zh/search'],
97+
exclude: ['/404', '/zh/404', '/search', '/zh/search', '/jp/search'],
9198
},
9299
},
93100
{

markdown-pages/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ function main(argv) {
179179
ref,
180180
path: path,
181181
},
182-
`${__dirname}/contents/${path}/docs-appdev/${ref}`,
182+
`${__dirname}/contents/${path}/docs-appdev/master`,
183183
[
184184
() => createReplaceImagePathStream(DEV_GUIDE_IMAGE_CDN_URL),
185185
() => createReplaceCopyableStream(),

markdown-pages/contents/ja/docs-appdev/master/.gitkeep

Whitespace-only changes.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
"download:docs-appdev:all": "./scripts/download-docs-appdev.sh",
103103
"download:docs-appdev:zh:all": "./scripts/download-docs-appdev-zh.sh",
104104
"download:docs-appdev:en:all": "./scripts/download-docs-appdev-en.sh",
105+
"download:docs-appdev:ja:all": "./scripts/download-docs-appdev-ja.sh",
105106
"sync": "node markdown-pages/cli.js sync"
106107
},
107108
"lint-staged": {

scripts/download-docs-appdev-ja.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yarn download:docs-appdev ja add-tdds-documents

scripts/download-docs-appdev.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
yarn download:docs-appdev zh
2-
yarn download:docs-appdev en
1+
yarn download:docs-appdev zh add-tdds-documents
2+
yarn download:docs-appdev en add-tdds-documents
3+
yarn download:docs-appdev ja add-tdds-documents

src/components/footer.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { FormattedMessage } from 'react-intl'
1212

1313
const Footer = React.memo((prop) => {
1414
const locale = prop.locale
15-
const langSwitchable = prop.langSwitchable
15+
const switchableLangs = prop.switchableLangs
1616
const location = useLocation()
1717
const currentPathname = location.pathname
1818
const footerColumns = locale === 'zh' ? footerColumnsZh : footerColumnsEn
@@ -55,22 +55,13 @@ const Footer = React.memo((prop) => {
5555

5656
const switchToLang = (lang) => {
5757
let currentPathnameArr = currentPathname.split('/')
58-
let preLang
59-
switch (lang) {
60-
case 'zh':
61-
preLang = '/zh'
62-
break
63-
64-
case 'en':
65-
preLang = ''
66-
currentPathnameArr.splice(1, 1)
67-
break
68-
69-
default:
70-
break
58+
59+
const preLang = lang === 'en' ? '' : lang
60+
if (locale !== 'en') {
61+
currentPathnameArr.splice(1, 1)
7162
}
7263

73-
return langSwitchable
64+
return switchableLangs[lang]
7465
? preLang + currentPathnameArr.join('/')
7566
: docInfo.type === 'tidbcloud'
7667
? preLang + '/tidb/stable/'
@@ -95,7 +86,7 @@ const Footer = React.memo((prop) => {
9586
className="dropdown-item"
9687
>
9788
English
98-
{!langSwitchable && locale === 'zh' && (
89+
{locale !== 'en' && !switchableLangs['en'] && (
9990
<span className="tooltiptext">
10091
<FormattedMessage id="langSwitchTip" />
10192
</span>
@@ -106,7 +97,7 @@ const Footer = React.memo((prop) => {
10697
className="dropdown-item"
10798
>
10899
简体中文
109-
{!langSwitchable && locale === 'en' && (
100+
{locale !== 'zh' && !switchableLangs['zh'] && (
110101
<span className="tooltiptext">
111102
<FormattedMessage
112103
id={
@@ -118,6 +109,19 @@ const Footer = React.memo((prop) => {
118109
</span>
119110
)}
120111
</Link>
112+
{docInfo.type === 'appdev' && (
113+
<Link
114+
to={locale === 'ja' ? currentPathname : switchToLang('ja')}
115+
className="dropdown-item"
116+
>
117+
日本語
118+
{locale !== 'ja' && !switchableLangs['ja'] && (
119+
<span className="tooltiptext">
120+
<FormattedMessage id="langSwitchTip" />
121+
</span>
122+
)}
123+
</Link>
124+
)}
121125
</div>
122126
</div>
123127
</div>

0 commit comments

Comments
 (0)