-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable sub-directories in docs/ (#705)
- Loading branch information
1 parent
49c27b7
commit d04b3ca
Showing
10 changed files
with
135 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright (c) 2017-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
const path = require('path'); | ||
const escapeStringRegexp = require('escape-string-regexp'); | ||
const env = require('./env.js'); | ||
|
||
// Return the subdirectory path from a reference directory | ||
// Example: | ||
// (file: 'docs/projectA/test.md', refDir: 'subDir') | ||
// returns 'projectA' | ||
function getSubDir(file, refDir) { | ||
let subDir = path.dirname(path.relative(refDir, file)); | ||
subDir = subDir.replace('\\', '/'); | ||
return subDir !== '.' ? subDir : null; | ||
} | ||
|
||
// Get the corresponding enabled language locale of a file. | ||
// Example: | ||
// (file: '/website/translated_docs/ko/projectA/test.md', refDir: 'website/translated_docs') | ||
// returns 'ko' | ||
function getLanguage(file, refDir) { | ||
let regexSubFolder = new RegExp( | ||
'/' + escapeStringRegexp(path.basename(refDir)) + '/(.*)/.*/' | ||
); | ||
const match = regexSubFolder.exec(file); | ||
|
||
// Avoid misinterpreting subdirectory as language | ||
if (match && env.translation.enabled) { | ||
const enabledLanguages = env.translation | ||
.enabledLanguages() | ||
.map(language => language.tag); | ||
if (enabledLanguages.indexOf(match[1]) !== -1) { | ||
return match[1]; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
module.exports = { | ||
getSubDir, | ||
getLanguage, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters