Skip to content

Commit 1fb2ffb

Browse files
Add helper method + more key => keys fixes
1 parent 98f4423 commit 1fb2ffb

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

EssentialCSharp.Web/Views/Shared/_Layout.cshtml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@
200200

201201
<div v-cloak v-if="sidebarTab == 'toc'" class="toc-tree" id="toc">
202202
<ul class="tree">
203-
<toc-tree v-for="item in filteredTocData" :item="item" :expanded-tocs="expandedTocs" :current-page="currentPage"></toc-tree>
203+
<toc-tree v-for="item in filteredTocData" :item="item" :expanded-tocs="expandedTocs" :current-page="currentPage" :first-or-default="firstOrDefault"></toc-tree>
204204
</ul>
205205
</div>
206206
<div v-cloak>
@@ -278,7 +278,7 @@
278278
<template id="toc-tree">
279279
<li v-if="item.items.length">
280280
<details :open="expandedTocs.has(item.keys)"
281-
v-on:toggle="!$event.target.open ? expandedTocs.delete(item.key) : expandedTocs.add(item.key)">
281+
v-on:toggle="!$event.target.open ? expandedTocs.delete(item.keys) : expandedTocs.add(item.keys)">
282282
<summary :class="{
283283
'toc-content' : item.level==0,
284284
'nested' : item.level>
@@ -299,7 +299,7 @@
299299
}" :href="item.href"> Introduction
300300
</a>
301301
</li>
302-
<toc-tree v-for="childItem in item.items" :item="childItem" :expanded-tocs="expandedTocs" :current-page="currentPage"></toc-tree>
302+
<toc-tree v-for="childItem in item.items" :item="childItem" :expanded-tocs="expandedTocs" :current-page="currentPage" :first-or-default="firstOrDefault"></toc-tree>
303303
</ul>
304304
<hr class="divider" v-if="item.level === 0" />
305305
</details>

EssentialCSharp.Web/wwwroot/js/site.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { useWindowSize } from "vue-window-size";
1212
/**
1313
* @typedef {Object} TocItem
1414
* @prop {number} [level]
15-
* @prop {string} [key]
15+
* @prop {string[]} [keys]
1616
* @prop {string} [href]
1717
* @prop {string} [title]
1818
* @prop {TocItem[]} [items]
@@ -84,7 +84,7 @@ function findCurrentPage(path, items) {
8484
return itemPath;
8585
}
8686
for (let key of item.keys) {
87-
if (window.location.href.endsWith("/" + item.key)) {
87+
if (window.location.href.endsWith("/" + key)) {
8888
return itemPath;
8989
}
9090
}
@@ -187,11 +187,16 @@ const app = createApp({
187187

188188
const sidebarShown = ref(false);
189189

190+
/**
191+
* Find the first element of a list, otherwise null
192+
* @param {string[]} list
193+
* @returns {string | undefined} first element or null
194+
* */
190195
function firstOrDefault(list) {
191196
if (list.length > 0) {
192197
return list[0];
193198
}
194-
return null;
199+
return undefined;
195200
}
196201

197202
const smallScreen = computed(() => {
@@ -313,6 +318,7 @@ const app = createApp({
313318

314319
sidebarShown,
315320
sidebarTab,
321+
firstOrDefault,
316322

317323
smallScreen,
318324

@@ -330,7 +336,7 @@ const app = createApp({
330336
});
331337

332338
app.component("toc-tree", {
333-
props: ["item", "expandedTocs", "currentPage"],
339+
props: ["item", "expandedTocs", "currentPage", "firstOrDefault"],
334340
template: "#toc-tree",
335341
});
336342

0 commit comments

Comments
 (0)