Skip to content

Yini/add jp appdev #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
chore: add ja app dev docs
  • Loading branch information
YiniXu9506 committed Nov 4, 2021
commit 93f1147dd5f86e3c9e4defbaa33cb09bea4803c3
59 changes: 51 additions & 8 deletions create-pages/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const {
genVersionChunks,
} = require('./utils')

const languages = ['en', 'zh', 'ja']

const createDocs = async ({ graphql, createPage, createRedirect }) => {
const docTemplate = path.resolve(`${__dirname}/../src/templates/doc.js`)

Expand Down Expand Up @@ -69,6 +71,35 @@ const createDocs = async ({ graphql, createPage, createRedirect }) => {
}
`)

const docsJa = await graphql(`
query {
allMdx(
filter: {
fields: { langCollection: { eq: "markdown-pages/contents/ja" } }
fileAbsolutePath: { regex: "/^(?!.*TOC).*$/" }
frontmatter: { draft: { ne: true } }
}
) {
nodes {
id
fields {
langCollection
}
frontmatter {
aliases
}
parent {
... on File {
relativeDirectory
relativePath
base
}
}
}
}
}
`)

// create pages for different language docs
function _createDocs(docs, locale, pathPrefix = '') {
const nodes = docs.data.allMdx.nodes
Expand All @@ -83,12 +114,23 @@ const createDocs = async ({ graphql, createPage, createRedirect }) => {
const _fullPath = `${replacePath(relativeDir, base)}`
const fullPath = `${pathPrefix}${_fullPath}`
node.path = fullPath
const filePathInDiffLang = path.resolve(
`${__dirname}/../markdown-pages/contents${
locale === 'en' ? '/zh/' : '/en/'
}${relativePath}`
)
node.langSwitchable = fs.existsSync(filePathInDiffLang) ? true : false
const switchableLangs = {}

languages.forEach((lang) => {
if (locale != lang) {
const filePathInDiffLang = path.resolve(
`${__dirname}/../markdown-pages/contents/${lang}/${relativePath}`
)

iSSwitchable = fs.existsSync(filePathInDiffLang) ? true : false

switchableLangs[lang] = iSSwitchable
} else {
switchableLangs[lang] = true
}
})

node.switchableLangs = switchableLangs
const vChunks = genVersionChunks(_fullPath)
node.version = vChunks[0]
node.pathWithoutVersion = vChunks[1]
Expand All @@ -115,7 +157,7 @@ const createDocs = async ({ graphql, createPage, createRedirect }) => {
pathPrefix,
tocPath,
parent,
langSwitchable,
switchableLangs,
} = node
createPage({
path: path,
Expand All @@ -131,7 +173,7 @@ const createDocs = async ({ graphql, createPage, createRedirect }) => {
downloadURL,
fullPath: path,
versions: versionsMap[node.pathWithoutVersion],
langSwitchable,
switchableLangs,
},
})

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

_createDocs(docsEn, 'en')
_createDocs(docsZh, 'zh', '/zh')
_createDocs(docsJa, 'ja', '/ja')
}

module.exports = createDocs
11 changes: 11 additions & 0 deletions create-pages/intl.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ const createIntlPages = ({ page, actions }) => {
},
})
)

if (pagePath === '/search/') {
createPage({
...page,
path: `/ja${pagePath}`,
context: {
...page.context,
locale: 'ja',
},
})
}
}

module.exports = createIntlPages
9 changes: 8 additions & 1 deletion gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ module.exports = {
path: `${__dirname}/markdown-pages/contents/zh`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `markdown-pages/contents/ja`,
path: `${__dirname}/markdown-pages/contents/ja`,
},
},
{
resolve: `gatsby-plugin-mdx`,
options: {
Expand Down Expand Up @@ -87,7 +94,7 @@ module.exports = {
resolve: `gatsby-plugin-sitemap`,
options: {
output: `/sitemap.xml`,
exclude: ['/404', '/zh/404', '/search', '/zh/search'],
exclude: ['/404', '/zh/404', '/search', '/zh/search', '/jp/search'],
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion markdown-pages/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function main(argv) {
ref,
path: path,
},
`${__dirname}/contents/${path}/docs-appdev/${ref}`,
`${__dirname}/contents/${path}/docs-appdev/master`,
[
() => createReplaceImagePathStream(DEV_GUIDE_IMAGE_CDN_URL),
() => createReplaceCopyableStream(),
Expand Down
Empty file.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"download:docs-appdev:all": "./scripts/download-docs-appdev.sh",
"download:docs-appdev:zh:all": "./scripts/download-docs-appdev-zh.sh",
"download:docs-appdev:en:all": "./scripts/download-docs-appdev-en.sh",
"download:docs-appdev:ja:all": "./scripts/download-docs-appdev-ja.sh",
"sync": "node markdown-pages/cli.js sync"
},
"lint-staged": {
Expand Down
1 change: 1 addition & 0 deletions scripts/download-docs-appdev-ja.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn download:docs-appdev ja add-tdds-documents
5 changes: 3 additions & 2 deletions scripts/download-docs-appdev.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
yarn download:docs-appdev zh
yarn download:docs-appdev en
yarn download:docs-appdev zh add-tdds-documents
yarn download:docs-appdev en add-tdds-documents
yarn download:docs-appdev ja add-tdds-documents
6 changes: 5 additions & 1 deletion src/components/IntlLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { useIntl } from 'react-intl'
const IntlLink = ({ to, children, type, ...rest }) => {
const intl = useIntl()

const localeTo = `${intl.locale === 'en' ? '' : '/' + intl.locale}${to}`
const localeTo = `${
(intl.locale === 'ja' && to === '/appdev/dev') || intl.locale === 'zh'
? '/' + intl.locale
: ''
}${to}`
const linkType = type

return (
Expand Down
51 changes: 32 additions & 19 deletions src/components/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@ import AddIcon from '@material-ui/icons/Add'
import LanguageIcon from '@material-ui/icons/Language'
import Socials from './socials'
import IntlLink from '../components/IntlLink'
import { footerColumnsZh, footerColumnsEn } from '../data/footer'
import {
footerColumnsZh,
footerColumnsEn,
footerColumnsJa,
} from '../data/footer'
import { useLocation } from '@reach/router'
import { useSelector } from 'react-redux'
import { FormattedMessage } from 'react-intl'

const Footer = React.memo((prop) => {
const locale = prop.locale
const langSwitchable = prop.langSwitchable
const switchableLangs = prop.switchableLangs
const location = useLocation()
const currentPathname = location.pathname
const footerColumns = locale === 'zh' ? footerColumnsZh : footerColumnsEn
const footerColumns =
locale === 'en'
? footerColumnsEn
: locale === 'zh'
? footerColumnsZh
: footerColumnsJa

const { FooterLogoSVG } = useStaticQuery(
graphql`
Expand Down Expand Up @@ -55,22 +64,13 @@ const Footer = React.memo((prop) => {

const switchToLang = (lang) => {
let currentPathnameArr = currentPathname.split('/')
let preLang
switch (lang) {
case 'zh':
preLang = '/zh'
break

case 'en':
preLang = ''
currentPathnameArr.splice(1, 1)
break

default:
break

const preLang = lang === 'en' ? '' : lang
if (locale !== 'en') {
currentPathnameArr.splice(1, 1)
}

return langSwitchable
return switchableLangs[lang]
? preLang + currentPathnameArr.join('/')
: docInfo.type === 'tidbcloud'
? preLang + '/tidb/stable/'
Expand All @@ -95,7 +95,7 @@ const Footer = React.memo((prop) => {
className="dropdown-item"
>
English
{!langSwitchable && locale === 'zh' && (
{locale !== 'en' && !switchableLangs['en'] && (
<span className="tooltiptext">
<FormattedMessage id="langSwitchTip" />
</span>
Expand All @@ -106,7 +106,7 @@ const Footer = React.memo((prop) => {
className="dropdown-item"
>
简体中文
{!langSwitchable && locale === 'en' && (
{locale !== 'zh' && !switchableLangs['zh'] && (
<span className="tooltiptext">
<FormattedMessage
id={
Expand All @@ -118,6 +118,19 @@ const Footer = React.memo((prop) => {
</span>
)}
</Link>
{docInfo.type === 'appdev' && (
<Link
to={locale === 'ja' ? currentPathname : switchToLang('ja')}
className="dropdown-item"
>
日本語
{locale !== 'ja' && !switchableLangs['ja'] && (
<span className="tooltiptext">
<FormattedMessage id="langSwitchTip" />
</span>
)}
</Link>
)}
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Layout = ({
locale,
children,
forbidResetDocInfo = false,
langSwitchable,
switchableLangs = { en: true, zh: true },
}) => {
const dispatch = useDispatch()

Expand Down Expand Up @@ -49,7 +49,7 @@ const Layout = ({
<IntlProvider locale={locale} messages={flat(langMap[locale])}>
<Navbar locale={locale} />
<main>{children}</main>
<Footer locale={locale} langSwitchable={langSwitchable} />
<Footer locale={locale} switchableLangs={switchableLangs} />
</IntlProvider>
)
}
Expand Down
10 changes: 5 additions & 5 deletions src/components/navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ const Navbar = (prop) => {

useEffect(() => {
const pageType =
locale === 'zh'
? location.pathname.split('/')[2]
: location.pathname.split('/')[1]
locale === 'en'
? location.pathname.split('/')[1]
: location.pathname.split('/')[2]
setActiveNav(pageType)
}, [locale, location.pathname])

Expand Down Expand Up @@ -107,7 +107,7 @@ const Navbar = (prop) => {
</IntlLink>

<IntlLink
to="/tools/"
to="/tools"
className={`navbar-item with-main-section ${
(activeNav === 'tools' ||
activeNav === 'tidb-data-migration' ||
Expand All @@ -120,7 +120,7 @@ const Navbar = (prop) => {
>
<FormattedMessage id="navbar.tools" />
</IntlLink>
{locale === 'en' && (
{locale !== 'zh' && (
<IntlLink
to="/tidbcloud/public-preview"
className={`navbar-item with-main-section ${
Expand Down
Loading