-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Enable sub-directories in docs/ #705
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
64b3d71
enable subdirectory for docs
endiliey b386c73
modify test to include subdir doc
endiliey a907809
re-implement to support nested subdirectories
endiliey dab7f38
implement relative path builder in docslayout next/prev
endiliey 29c2e21
refactor & add comment
endiliey f5d8f66
refactor again & comment
endiliey b2ddfe3
add windows compatibility
endiliey c519ea5
refactor & remove test docs:)
endiliey a4aa8c7
address code review
endiliey 09ebf6d
Merge remote-tracking branch 'upstream/master' into subdir
endiliey 32cafe0
modify crowdin.yaml to include subdir docs
endiliey 2a84d97
update crowdin yaml docs
endiliey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ const path = require('path'); | |
const assert = require('assert'); | ||
|
||
const env = require('./env.js'); | ||
const utils = require('./utils.js'); | ||
const siteConfig = require(CWD + '/siteConfig.js'); | ||
|
||
const ENABLE_TRANSLATION = fs.existsSync(CWD + '/languages.js'); | ||
|
@@ -194,7 +195,27 @@ function diffLatestDoc(file, id) { | |
// the version of the file to be used, and its language | ||
function processVersionMetadata(file, version, useVersion, language) { | ||
const metadata = extractMetadata(fs.readFileSync(file, 'utf8')).metadata; | ||
metadata.source = 'version-' + useVersion + '/' + path.basename(file); | ||
|
||
// Add subdirectory information to versioned_doc metadata | ||
// Example: `versioned_docs/version-1.1.6/projectA/readme.md` file with id `version-1.1.6-readme` | ||
// and original_id `readme` will have metadata id of `version-1.1.6-projectA/readme` and original_id `projectA/readme` | ||
const subDir = utils.getSubDir( | ||
file, | ||
path.join(CWD, 'versioned_docs', `version-${useVersion}`) | ||
); | ||
if (subDir) { | ||
metadata.original_id = subDir + '/' + metadata.original_id; | ||
metadata.id = metadata.id.replace( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you use template strings instead of concatenating the strings? It'll be easier to read. |
||
'version-' + useVersion + '-', | ||
'version-' + useVersion + '-' + subDir + '/' | ||
); | ||
} | ||
|
||
metadata.source = | ||
'version-' + | ||
useVersion + | ||
'/' + | ||
(subDir ? subDir + '/' + path.basename(file) : path.basename(file)); | ||
|
||
const latestVersion = versions[0]; | ||
|
||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please extract this path transformation code out into a function somewhere, perhaps into utils.