-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New layout implementation and sidenav design (#6344)
- Updates the sidenav static generation logic to match `flutter/website` for improved build performance and consistency. Also removes the need for specifying `match-page-url-exactly` on directory index pages. - This changes the 11ty related `filters.ts` and `eleventyComputed.js` files. These changes have already been reviewed and been in use by `flutter/website` for a while. - Redesigns the sidenav for improved accessibility and reducing dependence on Bootstrap. - Reimplements the site layout in preparation for Bootstrap removal and improving scrolling. - Removes a bunch of now unneeded logic and styles, further supporting the later removal of Bootstrap. Fixes #5791 Fixes #5789 Contributes to #4164 Contributes to #3849 Prepares for #2625
- Loading branch information
Showing
23 changed files
with
415 additions
and
502 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// noinspection JSUnusedGlobalSymbols | ||
export default { | ||
activeNav: (data) => { | ||
const sidenav = data['sidenav']; | ||
|
||
const results = {}; | ||
_visitPermalinks(results, sidenav, []); | ||
return results; | ||
}, | ||
}; | ||
|
||
/** | ||
* @param results {object} | ||
* @param navTree {object[]} | ||
* @param path {number[]} | ||
*/ | ||
function _visitPermalinks(results, navTree, path) { | ||
navTree.forEach((entry, i) => { | ||
const permalink = entry['permalink']; | ||
const newPath = [...path, i + 1]; | ||
const children = entry['children']; | ||
const hasChildren = Array.isArray(children); | ||
|
||
if (typeof permalink === 'string' || permalink instanceof String) { | ||
_addLink(results, permalink, newPath, hasChildren); | ||
} | ||
|
||
if (hasChildren) { | ||
_visitPermalinks(results, children, newPath); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* @param results {object} | ||
* @param permalink {string} | ||
* @param path {number[]} | ||
* @param hasChildren {boolean} | ||
*/ | ||
function _addLink(results, permalink, path, hasChildren) { | ||
// Skip external links. | ||
if (permalink.startsWith('http')) { | ||
return; | ||
} | ||
|
||
// Throw an error if a permalink doesn't start with a `/`. | ||
if (!permalink.startsWith('/')) { | ||
throw new Error(`${permalink} does not begin with a '/'`); | ||
} | ||
|
||
// Split the specified permalink into parts. | ||
const parts = permalink.split('/'); | ||
|
||
// Add active nav data for the specified permalink. | ||
_addPart(results, path, parts, 1, hasChildren); | ||
} | ||
|
||
/** | ||
* @param result {object} | ||
* @param path {number[]} | ||
* @param parts {string[]} | ||
* @param index {number} | ||
* @param hasChildren {boolean} | ||
*/ | ||
function _addPart(result, path, parts, index, hasChildren = false) { | ||
const isLast = index === parts.length - 1; | ||
let current = result[parts[index]]; | ||
|
||
if (!current) { | ||
// If the current part isn't in the result map yet, add a new map. | ||
current = {}; | ||
result[parts[index]] = current; | ||
} | ||
|
||
// If this is the last part of the path, | ||
// store the active nav data. | ||
if (isLast) { | ||
const active = current['active']; | ||
// Override active nav data if | ||
// it doesn't already exist for this part, | ||
// or the current active data was from an entry with children. | ||
if (!active) { | ||
current['active'] = path; | ||
if (hasChildren) { | ||
current['has-children'] = true; | ||
} | ||
} else if (!hasChildren && current['has-children'] === true) { | ||
current['active'] = path; | ||
current['has-children'] = false; | ||
} | ||
} else { | ||
if (!current['paths']) { | ||
current['paths'] = {}; | ||
} | ||
|
||
// Continue to the next part. | ||
_addPart(current['paths'], path, parts, index + 1, hasChildren); | ||
} | ||
} |
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
Oops, something went wrong.