Refactor(server): share logic between server.js & generate.js#856
Merged
endiliey merged 10 commits intofacebook:masterfrom Jul 24, 2018
Merged
Refactor(server): share logic between server.js & generate.js#856endiliey merged 10 commits intofacebook:masterfrom
endiliey merged 10 commits intofacebook:masterfrom
Conversation
Contributor
|
Deploy preview for docusaurus-preview ready! Built with commit ea03634 |
yangshun
approved these changes
Jul 23, 2018
Contributor
yangshun
left a comment
There was a problem hiding this comment.
Thanks! I'm glad we have ESLint in place before we started all these refactoring. Having linting makes things safer.
lib/server/docs.js
Outdated
| function getRedirectStr(metadata) { | ||
| if ( | ||
| !env.translation.enabled || | ||
| metadata.permalink.indexOf('docs/en') === -1 |
Contributor
Author
There was a problem hiding this comment.
Done.
I changed it to .includes() instead. Couldn't find any .contains() method in javascript 😂
lib/server/docs.js
Outdated
| } | ||
|
|
||
| function getComponent(rawContent, mdToHtml, metadata) { | ||
| function getStr(rawContent, mdToHtml, metadata) { |
Contributor
There was a problem hiding this comment.
Maybe getMarkup will be a better name
Contributor
|
My bad @endiliey I got mixed up by the naming myself. I meant |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Changes
Mostly refactoring into reusable functions and add small test for it
Refactor duplicate/ similar logic in
server.jsandgenerate.jsandreadMetadata.jstogetMetadatainblog.jshttps://github.com/facebook/Docusaurus/blob/9f718a5097dfa7f549690a711fb151ea82a335a8/lib/server/generate.js#L156-L164
https://github.com/facebook/Docusaurus/blob/9f718a5097dfa7f549690a711fb151ea82a335a8/lib/server/server.js#L255-L267
https://github.com/facebook/Docusaurus/blob/9f718a5097dfa7f549690a711fb151ea82a335a8/lib/server/readMetadata.js#L326-L335
Refactor duplicate in
server.jsandgenerate.jstogetPagesinblog.jshttps://github.com/facebook/Docusaurus/blob/9f718a5097dfa7f549690a711fb151ea82a335a8/lib/server/server.js#L202-L224
https://github.com/facebook/Docusaurus/blob/9f718a5097dfa7f549690a711fb151ea82a335a8/lib/server/generate.js#L180-L193
Refactor duplicate path replacement to a function in
blog.jssuch ashttps://github.com/facebook/Docusaurus/blob/9f718a5097dfa7f549690a711fb151ea82a335a8/lib/server/readMetadata.js#L320-L325
https://github.com/facebook/Docusaurus/blob/9f718a5097dfa7f549690a711fb151ea82a335a8/lib/server/generate.js#L150-L155
Simplify docs redirectStr generation to function
getRedirectStrin docs.jshttps://github.com/facebook/Docusaurus/blob/9f718a5097dfa7f549690a711fb151ea82a335a8/lib/server/generate.js#L95-L109
Refactor duplicate in
server.jsandgenerate.json blogPost generationhttps://github.com/facebook/Docusaurus/blob/9f718a5097dfa7f549690a711fb151ea82a335a8/lib/server/generate.js#L166-L175
https://github.com/facebook/Docusaurus/blob/9f718a5097dfa7f549690a711fb151ea82a335a8/lib/server/server.js#L269-L281
Add test for several key functions in new
blog.jsRemove redundant comments & some nits
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Links still work as per normal
https://deploy-preview-856--docusaurus-preview.netlify.com/
Related PRs
#847
#854