Skip to content

Commit 93f1147

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

File tree

21 files changed

+299
-48
lines changed

21 files changed

+299
-48
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/IntlLink.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { useIntl } from 'react-intl'
66
const IntlLink = ({ to, children, type, ...rest }) => {
77
const intl = useIntl()
88

9-
const localeTo = `${intl.locale === 'en' ? '' : '/' + intl.locale}${to}`
9+
const localeTo = `${
10+
(intl.locale === 'ja' && to === '/appdev/dev') || intl.locale === 'zh'
11+
? '/' + intl.locale
12+
: ''
13+
}${to}`
1014
const linkType = type
1115

1216
return (

0 commit comments

Comments
 (0)