Skip to content

Commit 0253bae

Browse files
committed
Merge branch 'main' into rm-html
2 parents b17fba6 + d9d877a commit 0253bae

25 files changed

+486
-502
lines changed

src/_11ty/filters.ts

+37-26
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function registerFilters(eleventyConfig: UserConfig): void {
99
eleventyConfig.addFilter('toSimpleDate', toSimpleDate);
1010
eleventyConfig.addFilter('regexReplace', regexReplace);
1111
eleventyConfig.addFilter('toISOString', toISOString);
12-
eleventyConfig.addFilter('activeNavEntryIndexArray', activeNavEntryIndexArray);
12+
eleventyConfig.addFilter('activeNavForPage', activeNavForPage);
1313
eleventyConfig.addFilter('arrayToSentenceString', arrayToSentenceString);
1414
eleventyConfig.addFilter('underscoreBreaker', underscoreBreaker);
1515
eleventyConfig.addFilter('throwError', function (error: any) {
@@ -60,38 +60,49 @@ function toISOString(input: string | Date): string {
6060
}
6161
}
6262

63-
function activeNavEntryIndexArray(navEntryTree: any, pageUrlPath: string = ''): number[] | null {
64-
const activeEntryIndexes = _getActiveNavEntries(navEntryTree, pageUrlPath);
65-
return activeEntryIndexes.length === 0 ? null : activeEntryIndexes;
66-
}
63+
function activeNavForPage(pageUrlPath: string, activeNav: any) {
64+
// Split the path for this page, dropping everything before the path.
65+
// Example: dart.dev/tools/pub/package-layout ->
66+
// [tools, pub, package-layout]
67+
const parts = pageUrlPath.toLowerCase().split('/').slice(1);
68+
let currentPathPairs = activeNav;
69+
let lastAllowedBackupActive = [];
70+
71+
parts.forEach(part => {
72+
// If the current entry has active data,
73+
// allow its active data to be a backup if a later path isn't found.
74+
const currentEntryActiveData = currentPathPairs['active'];
75+
if (currentEntryActiveData) {
76+
lastAllowedBackupActive = currentEntryActiveData;
77+
}
6778

68-
function _getActiveNavEntries(navEntryTree: any, pageUrlPath = ''): number[] {
69-
// TODO(parlough): Simplify once standardizing with the Flutter site.
70-
for (let i = 0; i < navEntryTree.length; i++) {
71-
const entry = navEntryTree[i];
72-
73-
if (entry.children) {
74-
const descendantIndexes = _getActiveNavEntries(
75-
entry.children,
76-
pageUrlPath,
77-
);
78-
if (descendantIndexes.length > 0) {
79-
return [i + 1, ...descendantIndexes];
80-
}
79+
const paths = currentPathPairs['paths'];
80+
81+
// If the current entry has children paths, explore those next.
82+
if (paths) {
83+
currentPathPairs = paths;
8184
}
8285

83-
if (entry.permalink) {
84-
const isMatch = entry['match-page-url-exactly']
85-
? pageUrlPath === entry.permalink
86-
: pageUrlPath.includes(entry.permalink);
86+
// Get the data for the next part.
87+
const nextPair = currentPathPairs[part];
8788

88-
if (isMatch) {
89-
return [i + 1];
90-
}
89+
// If the next part of the path doesn't have data,
90+
// use the active data for the current backup.
91+
if (nextPair === undefined || nextPair === null) {
92+
return lastAllowedBackupActive;
9193
}
94+
95+
currentPathPairs = nextPair;
96+
});
97+
98+
// If the last path part has active data, use that,
99+
// otherwise fall back to the backup active data.
100+
let activeEntries = currentPathPairs['active'];
101+
if (activeEntries === undefined || activeEntries === null) {
102+
activeEntries = lastAllowedBackupActive;
92103
}
93104

94-
return [];
105+
return activeEntries;
95106
}
96107

97108
function arrayToSentenceString(list: string[], joiner: string = 'and'): string {

src/_data/eleventyComputed.js

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// noinspection JSUnusedGlobalSymbols
2+
export default {
3+
activeNav: (data) => {
4+
const sidenav = data['sidenav'];
5+
6+
const results = {};
7+
_visitPermalinks(results, sidenav, []);
8+
return results;
9+
},
10+
};
11+
12+
/**
13+
* @param results {object}
14+
* @param navTree {object[]}
15+
* @param path {number[]}
16+
*/
17+
function _visitPermalinks(results, navTree, path) {
18+
navTree.forEach((entry, i) => {
19+
const permalink = entry['permalink'];
20+
const newPath = [...path, i + 1];
21+
const children = entry['children'];
22+
const hasChildren = Array.isArray(children);
23+
24+
if (typeof permalink === 'string' || permalink instanceof String) {
25+
_addLink(results, permalink, newPath, hasChildren);
26+
}
27+
28+
if (hasChildren) {
29+
_visitPermalinks(results, children, newPath);
30+
}
31+
});
32+
}
33+
34+
/**
35+
* @param results {object}
36+
* @param permalink {string}
37+
* @param path {number[]}
38+
* @param hasChildren {boolean}
39+
*/
40+
function _addLink(results, permalink, path, hasChildren) {
41+
// Skip external links.
42+
if (permalink.startsWith('http')) {
43+
return;
44+
}
45+
46+
// Throw an error if a permalink doesn't start with a `/`.
47+
if (!permalink.startsWith('/')) {
48+
throw new Error(`${permalink} does not begin with a '/'`);
49+
}
50+
51+
// Split the specified permalink into parts.
52+
const parts = permalink.split('/');
53+
54+
// Add active nav data for the specified permalink.
55+
_addPart(results, path, parts, 1, hasChildren);
56+
}
57+
58+
/**
59+
* @param result {object}
60+
* @param path {number[]}
61+
* @param parts {string[]}
62+
* @param index {number}
63+
* @param hasChildren {boolean}
64+
*/
65+
function _addPart(result, path, parts, index, hasChildren = false) {
66+
const isLast = index === parts.length - 1;
67+
let current = result[parts[index]];
68+
69+
if (!current) {
70+
// If the current part isn't in the result map yet, add a new map.
71+
current = {};
72+
result[parts[index]] = current;
73+
}
74+
75+
// If this is the last part of the path,
76+
// store the active nav data.
77+
if (isLast) {
78+
const active = current['active'];
79+
// Override active nav data if
80+
// it doesn't already exist for this part,
81+
// or the current active data was from an entry with children.
82+
if (!active) {
83+
current['active'] = path;
84+
if (hasChildren) {
85+
current['has-children'] = true;
86+
}
87+
} else if (!hasChildren && current['has-children'] === true) {
88+
current['active'] = path;
89+
current['has-children'] = false;
90+
}
91+
} else {
92+
if (!current['paths']) {
93+
current['paths'] = {};
94+
}
95+
96+
// Continue to the next part.
97+
_addPart(current['paths'], path, parts, index + 1, hasChildren);
98+
}
99+
}

src/_data/side-nav.yml src/_data/sidenav.yml

-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
expanded: false
33
children:
44
- title: Introduction
5-
match-page-url-exactly: true
65
permalink: /language
76
- title: Syntax basics
87
children:
@@ -73,7 +72,6 @@
7372
- title: Class modifiers
7473
children:
7574
- title: Overview & usage
76-
match-page-url-exactly: true
7775
permalink: /language/class-modifiers
7876
- title: Class modifiers for API maintainers
7977
permalink: /language/class-modifiers-for-apis
@@ -91,7 +89,6 @@
9189
expanded: false
9290
children:
9391
- title: Sound null safety
94-
match-page-url-exactly: true
9592
permalink: /null-safety
9693
- title: Migrating to null safety
9794
permalink: /null-safety/migration-guide
@@ -106,7 +103,6 @@
106103
expanded: false
107104
children:
108105
- title: Overview
109-
match-page-url-exactly: true
110106
permalink: /libraries
111107
- title: dart:core
112108
permalink: /libraries/dart-core
@@ -140,7 +136,6 @@
140136
permalink: /effective-dart
141137
children:
142138
- title: Overview
143-
match-page-url-exactly: true
144139
permalink: /effective-dart
145140
- title: Style
146141
permalink: /effective-dart/style
@@ -206,7 +201,6 @@
206201
- title: Command-line & server apps
207202
children:
208203
- title: Overview
209-
match-page-url-exactly: true
210204
permalink: /server
211205
- title: Get started
212206
permalink: /tutorials/server/get-started
@@ -223,7 +217,6 @@
223217
- title: Web apps
224218
children:
225219
- title: Overview
226-
match-page-url-exactly: true
227220
permalink: /web
228221
- title: Get started
229222
permalink: /web/get-started
@@ -249,7 +242,6 @@
249242
children:
250243
- title: Overview
251244
permalink: /interop/js-interop
252-
match-page-url-exactly: true
253245
- title: Usage
254246
permalink: /interop/js-interop/usage
255247
- title: JS types
@@ -266,7 +258,6 @@
266258
expanded: false
267259
children:
268260
- title: Overview
269-
match-page-url-exactly: true
270261
permalink: /tools
271262
- title: Editors & debuggers
272263
children:
@@ -279,7 +270,6 @@
279270
- title: DartPad
280271
children:
281272
- title: Overview
282-
match-page-url-exactly: true
283273
permalink: /tools/dartpad
284274
- title: Troubleshooting DartPad
285275
permalink: /tools/dartpad/troubleshoot
@@ -373,7 +363,6 @@
373363
- title: Videos
374364
permalink: /resources/videos
375365
- title: Tutorials
376-
match-page-url-exactly: true
377366
permalink: /tutorials
378367

379368
- title: Related sites

src/_data/site.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ yt:
3333
watch: 'https://www.youtube.com/watch'
3434
playlist: 'https://www.youtube.com/playlist?list='
3535

36-
show_banner: true
36+
show_banner: false
3737

3838
# Increment this global og:image URL version number (used as a query parameter)
3939
# when you update any og:image file. (Also increment the corresponding number

src/_includes/navigation-main.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% assign page_url_path = page.url | regexReplace: '/index$|/index\.html$|\.html$|/$' | prepend: '/*' | append: '/' -%}
22

33
<nav id="mainnav" class="site-header">
4-
<div id="menu-toggle"><i class="material-symbols">menu</i></div>
4+
<div id="menu-toggle"><span class="material-symbols" title="Toggle side navigation menu." aria-label="Toggle side navigation menu." type="button">menu</span></div>
55
<a href="/" class="brand" title="{{site.title}}">
66
<img src="/assets/img/logo/logo-white-text.svg" alt="{{site.title}}">
77
</a>

src/_includes/navigation-side.html

+20-21
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,25 @@
44
id="search-side" autocomplete="off" placeholder="Search" aria-label="Search">
55
</form>
66

7-
<div class="site-sidebar">
8-
<ul class="navbar-nav">
9-
<li class="nav-item">
10-
<a href="/overview" class="nav-link">Overview</a>
11-
</li>
12-
<li class="nav-item">
13-
<a href="/community" class="nav-link">Community</a>
14-
</li>
15-
<li class="nav-item">
16-
<a href="https://dartpad.dev" class="nav-link">Try Dart</a>
17-
</li>
18-
<li class="nav-item">
19-
<a href="/get-dart" class="nav-link">Get Dart</a>
20-
</li>
21-
<li class="nav-item">
22-
<a href="/docs" class="nav-link">Docs</a>
23-
</li>
24-
<li aria-hidden="true"><div class="sidebar-primary-divider"></div></li>
25-
</ul>
7+
<ul class="navbar-nav">
8+
<li aria-hidden="true"><div class="sidenav-divider"></div></li>
9+
<li class="nav-item">
10+
<a href="/overview" class="nav-link">Overview</a>
11+
</li>
12+
<li class="nav-item">
13+
<a href="/community" class="nav-link">Community</a>
14+
</li>
15+
<li class="nav-item">
16+
<a href="https://dartpad.dev" class="nav-link">Try Dart</a>
17+
</li>
18+
<li class="nav-item">
19+
<a href="/get-dart" class="nav-link">Get Dart</a>
20+
</li>
21+
<li class="nav-item">
22+
<a href="/docs" class="nav-link">Docs</a>
23+
</li>
24+
<li aria-hidden="true"><div class="sidenav-divider"></div></li>
25+
</ul>
2626

27-
{% render 'sidenav-level-1.html', url:page.url, nav:side-nav %}
28-
</div>
27+
{% render 'sidenav-level-1.html', url:page.url, nav:sidenav, activeNav:activeNav %}
2928
</div>

src/_includes/sidenav-level-1.html

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
{% assign page_url_path = url | regexReplace: '/index$|/index\.html$|\.html$|/$' -%}
2-
{% assign active_entries = nav | activeNavEntryIndexArray: page_url_path -%}
1+
{% assign pageUrlPath = url | regexReplace: '/index$|/index\.html$|\.html$|/$' -%}
2+
{% assign activeEntries = pageUrlPath | activeNavForPage: activeNav -%}
33

4-
<ul class="nav flex-column">
4+
<ul class="nav">
55
{%- for entry in nav -%}
66
{% if entry == 'divider' -%}
7-
<li aria-hidden="true"><div class="sidebar-primary-divider"></div></li>
8-
{% elsif entry contains 'header' -%}
7+
<li aria-hidden="true"><div class="sidenav-divider"></div></li>
8+
{% elsif entry.header -%}
99
<li class="nav-header">{{entry.header}}</li>
1010
{% else -%}
11-
{% assign id = 'sidenav-' | append: forloop.index -%}
12-
{% if forloop.index == active_entries[0] -%}
11+
{% assign id = base_id | append: '-sidenav-' | append: forloop.index -%}
12+
{% if forloop.index == activeEntries[0] -%}
1313
{% assign isActive = true -%}
1414
{% assign class = 'active' -%}
1515
{% else -%}
@@ -26,13 +26,15 @@
2626
{% assign show = '' -%}
2727
{% endif -%}
2828
<li class="nav-item">
29-
<a class="nav-link {{class}} collapsible" data-toggle="collapse" href="#{{id}}" role="button" aria-expanded="{{expanded}}" aria-controls="{{id}}">{{entry.title}}</a>
30-
31-
<ul class="nav flex-column flex-nowrap collapse {{show}}" id="{{id}}">
29+
<button class="nav-link {{class}} collapsible" data-toggle="collapse" data-target="#{{id}}" role="button" aria-expanded="{{expanded}}" aria-controls="{{id}}">
30+
<span>{{entry.title}}</span>
31+
<span class="material-symbols expander" aria-hidden="true">expand_more</span>
32+
</button>
33+
<ul class="nav collapse {{show}}" id="{{id}}">
3234
{% if isActive -%}
33-
{%- render 'sidenav-level-2.html', parent_id:id, children:entry.children, active_entries:active_entries -%}
35+
{%- render 'sidenav-level-2.html', parentId:id, children:entry.children, activeEntries:activeEntries -%}
3436
{% else -%}
35-
{%- render 'sidenav-level-2.html', parent_id:id, children:entry.children -%}
37+
{%- render 'sidenav-level-2.html', parentId:id, children:entry.children -%}
3638
{% endif -%}
3739
</ul>
3840
</li>
@@ -45,7 +47,10 @@
4547
<li class="nav-item">
4648
<a class="nav-link {{class}}" href="{{entry.permalink}}"
4749
{%- if isExternal %} target="_blank" rel="noopener" {%- endif -%}>
48-
{{entry.title}}
50+
<div>
51+
<span>{{entry.title}}</span>
52+
{%- if isExternal %}<span class="material-symbols" aria-hidden="true">open_in_new</span>{%- endif -%}
53+
</div>
4954
</a>
5055
</li>
5156
{% endif -%}

0 commit comments

Comments
 (0)