Skip to content

Simplify site nav generation - #1221

Merged
ang-zeyu merged 1 commit into
MarkBind:masterfrom
ang-zeyu:site-nav-refactor
Jun 7, 2020
Merged

Simplify site nav generation#1221
ang-zeyu merged 1 commit into
MarkBind:masterfrom
ang-zeyu:site-nav-refactor

Conversation

@ang-zeyu

Copy link
Copy Markdown
Contributor

What is the purpose of this pull request? (put "X" next to an item, remove the rest)

• [ ] Documentation update
• [ ] Bug fix
• [ ] New feature
• [ ] Enhancement to an existing feature
• [x] Other, please explain:

Code maintainability

What is the rationale for this request?

  • simplify the recursive algorithm used in site nav generation to an iterative one
  • should also bring some performance benefits since we are no longer constantly reparsing / outputting the html across recursive calls of formatSiteNav

What changes did you make? (Give an overview)

  • merged formatSiteNav into insertSiteNav since the recursion is removed
  • the new algorithm simply iterates through ul elements one by one, and its direct li child elements, formatting it the same way the old algorithm did
  • extract some more constants to constants.js

Testing instructions:

  • npm run test should pass ( no test file updates here )

Proposed commit message: (wrap lines at 72 characters)
Simplify site nav generation

The site nav generation algorithm is heavily recursive.

Let's remove the recursion in favour of a simple iterative process.

Comment threadsrc/Page.js
}

const siteNavContent = fs.readFileSync(siteNavPath, 'utf8');
if (siteNavContent === '') {

@ang-zeyuang-zeyuMay 4, 2020

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

handled by navigationElements.length === 0 below

@ang-zeyuang-zeyu mentioned this pull request May 4, 2020
@ang-zeyu
ang-zeyuforce-pushed the site-nav-refactor branch 3 times, most recently from 9a0a7bf to b1ecb97CompareMay 5, 2020 08:15
@ang-zeyu
ang-zeyu requested a review from yamgentMay 19, 2020 15:48
The site nav generation algorithm is heavily recursive.
Let's remove the recursion in favour of a simple iterative process.
@ang-zeyuang-zeyu added this to the v2.15.0 milestone Jun 7, 2020
@ang-zeyu
ang-zeyu merged commit 4140a70 into MarkBind:masterJun 7, 2020
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@ang-zeyu