Skip to content
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

Refactor(server): share logic between server.js & generate.js #856

Merged
merged 10 commits into from
Jul 24, 2018

Conversation

endiliey
Copy link
Contributor

@endiliey endiliey commented Jul 17, 2018

Changes

Mostly refactoring into reusable functions and add small test for it

  1. Refactor duplicate/ similar logic in server.js and generate.js and readMetadata.js to getMetadata in blog.js
    https://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

  2. Refactor duplicate in server.js and generate.js to getPages in blog.js
    https://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

  3. Refactor duplicate path replacement to a function in blog.js such as
    https://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

  4. Simplify docs redirectStr generation to function getRedirectStr in docs.js
    https://github.com/facebook/Docusaurus/blob/9f718a5097dfa7f549690a711fb151ea82a335a8/lib/server/generate.js#L95-L109

  5. Refactor duplicate in server.js and generate.js on blogPost generation
    https://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

  6. Add test for several key functions in new blog.js

  7. Remove redundant comments & some nits

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

  1. Test Locally
yarn start

Links still work as per normal

  1. Test in netlify
    https://deploy-preview-856--docusaurus-preview.netlify.com/

Related PRs

#847
#854

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jul 17, 2018
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Jul 17, 2018

Deploy preview for docusaurus-preview ready!

Built with commit ea03634

https://deploy-preview-856--docusaurus-preview.netlify.com

@endiliey endiliey changed the title Refactor + add more tests (Part 3) refactor(server): share blog logic between server.js & generate.js Jul 22, 2018
@endiliey endiliey changed the title refactor(server): share blog logic between server.js & generate.js refactor(server): share logic between server.js & generate.js Jul 22, 2018
Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'm glad we have ESLint in place before we started all these refactoring. Having linting makes things safer.

function getRedirectStr(metadata) {
if (
!env.translation.enabled ||
metadata.permalink.indexOf('docs/en') === -1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use .contains()

Copy link
Contributor Author

@endiliey endiliey Jul 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

I changed it to .includes() instead. Couldn't find any .contains() method in javascript 😂

@@ -82,7 +83,7 @@ function replaceAssetsLink(oldContent) {
return lines.join('\n');
}

function getComponent(rawContent, mdToHtml, metadata) {
function getStr(rawContent, mdToHtml, metadata) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe getMarkup will be a better name

@yangshun yangshun changed the title refactor(server): share logic between server.js & generate.js Refactor(server): share logic between server.js & generate.js Jul 23, 2018
@yangshun
Copy link
Contributor

My bad @endiliey I got mixed up by the naming myself. I meant includes(). Feel free to merge this PR yourself.

@endiliey endiliey merged commit afec4bd into facebook:master Jul 24, 2018
@endiliey endiliey deleted the blog branch July 24, 2018 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants