Skip to content

Commit bb23388

Browse files
Update site.js
1 parent 52e183a commit bb23388

File tree

1 file changed

+158
-159
lines changed
  • EssentialCSharp.Web/wwwroot/js

1 file changed

+158
-159
lines changed
Lines changed: 158 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,117 @@
1-
import {
2-
createApp,
3-
ref,
4-
reactive,
5-
onMounted,
6-
markRaw,
7-
watch,
8-
computed,
9-
} from "vue";
10-
import { useWindowSize } from "vue-window-size";
11-
12-
/**
13-
* @typedef {Object} TocItem
14-
* @prop {number} [level]
15-
* @prop {string} [key]
16-
* @prop {string} [href]
17-
* @prop {string} [title]
18-
* @prop {TocItem[]} [items]
19-
*/
20-
/** @type {TocItem} */
21-
const tocData = markRaw(TOC_DATA);
22-
23-
//Add new content or features here:
24-
25-
const featuresComingSoonList = [
26-
{
27-
title: "Client-side Compiler",
28-
text: "Write, compile, and run code snippets right from your browser. Enjoy hands-on experience with the code as you go through the site.",
29-
},
30-
{
31-
title: "Interactive Code Listings",
32-
text: "Edit, compile, and run the code listings found throughout Essential C#.",
33-
},
34-
{
35-
title: "Hyperlinking",
36-
text: "Easily navigate to interesting and relevant sites as well as related sections in Essential C#.",
37-
},
38-
{
39-
title: "Table of Contents Filtering",
40-
text: "The Table of Contents filter will let you narrow down the list of topics to help you quickly and easily find your destination.",
41-
},
42-
];
43-
44-
const contentComingSoonList = [
45-
{
46-
title: "Experimental attribute",
47-
text: "New feature from C# 12.0.",
48-
},
49-
{
50-
title: "Source Generators",
51-
text: "A newer .NET feature.",
52-
},
53-
{
54-
title: "C# 13.0 Features",
55-
text: "Various new features coming in .C# 13.0",
56-
},
57-
];
58-
59-
const completedFeaturesList = [
60-
{
61-
title: "Copying Header Hyperlinks",
62-
text: "Easily copy a header URL to link to a book section.",
63-
},
64-
{
65-
title: "Home Page",
66-
text: "Add a home page that features a short description of the book and a high level mindmap.",
67-
},
68-
{
69-
title: "Keyboard Shortcuts",
70-
text: "Quickly navigate through the book via keyboard shortcuts (right/left arrows, 'n', 'p').",
71-
},
72-
];
73-
74-
/**
75-
* Find the path of TOC entries that lead to the current page.
76-
* @param {TocItem[]} path
77-
* @param {TocItem[]} items
78-
* @returns {TocItem[] | undefined} path of items to the current page
79-
* */
80-
function findCurrentPage(path, items) {
81-
for (const item of items) {
82-
const itemPath = [item, ...path];
83-
if (window.location.href.endsWith("/" + item.href)) {
1+
import {
2+
createApp,
3+
ref,
4+
reactive,
5+
onMounted,
6+
markRaw,
7+
watch,
8+
computed,
9+
} from "vue";
10+
import { useWindowSize } from "vue-window-size";
11+
12+
/**
13+
* @typedef {Object} TocItem
14+
* @prop {number} [level]
15+
* @prop {string} [key]
16+
* @prop {string} [href]
17+
* @prop {string} [title]
18+
* @prop {TocItem[]} [items]
19+
*/
20+
/** @type {TocItem} */
21+
const tocData = markRaw(TOC_DATA);
22+
23+
//Add new content or features here:
24+
25+
const featuresComingSoonList = [
26+
{
27+
title: "Client-side Compiler",
28+
text: "Write, compile, and run code snippets right from your browser. Enjoy hands-on experience with the code as you go through the site.",
29+
},
30+
{
31+
title: "Interactive Code Listings",
32+
text: "Edit, compile, and run the code listings found throughout Essential C#.",
33+
},
34+
{
35+
title: "Hyperlinking",
36+
text: "Easily navigate to interesting and relevant sites as well as related sections in Essential C#.",
37+
},
38+
{
39+
title: "Table of Contents Filtering",
40+
text: "The Table of Contents filter will let you narrow down the list of topics to help you quickly and easily find your destination.",
41+
},
42+
];
43+
44+
const contentComingSoonList = [
45+
{
46+
title: "Experimental attribute",
47+
text: "New feature from C# 12.0.",
48+
},
49+
{
50+
title: "Source Generators",
51+
text: "A newer .NET feature.",
52+
},
53+
{
54+
title: "C# 13.0 Features",
55+
text: "Various new features coming in .C# 13.0",
56+
},
57+
];
58+
59+
const completedFeaturesList = [
60+
{
61+
title: "Copying Header Hyperlinks",
62+
text: "Easily copy a header URL to link to a book section.",
63+
},
64+
{
65+
title: "Home Page",
66+
text: "Add a home page that features a short description of the book and a high level mindmap.",
67+
},
68+
{
69+
title: "Keyboard Shortcuts",
70+
text: "Quickly navigate through the book via keyboard shortcuts (right/left arrows, 'n', 'p').",
71+
},
72+
];
73+
74+
/**
75+
* Find the path of TOC entries that lead to the current page.
76+
* @param {TocItem[]} path
77+
* @param {TocItem[]} items
78+
* @returns {TocItem[] | undefined} path of items to the current page
79+
* */
80+
function findCurrentPage(path, items) {
81+
for (const item of items) {
82+
const itemPath = [item, ...path];
83+
if (window.location.href.endsWith("/" + item.href) ||
84+
window.location.href.endsWith("/" + item.key)
85+
) {
8486
return itemPath;
85-
}
86-
if (window.location.href.endsWith("/" + item.key)) {
87-
return itemPath;
88-
}
89-
90-
const recursivePath = findCurrentPage(itemPath, item.items);
91-
if (recursivePath) return recursivePath;
92-
}
93-
}
94-
95-
function openSearch() {
96-
const el = document
97-
.getElementById("docsearch")
98-
.querySelector(".DocSearch-Button");
99-
el.click();
100-
}
101-
102-
const smallScreenSize = 768;
103-
104-
const removeHashPath = (path) => {
105-
if (!path) {
106-
return null;
107-
}
108-
let index = path.indexOf("#");
109-
index = index > 0 ? index : path.length;
110-
return path.substring(0, index);
111-
};
112-
// v-bind dont like the # in the url
113-
const nextPagePath = removeHashPath(NEXT_PAGE);
114-
const previousPagePath = removeHashPath(PREVIOUS_PAGE);
115-
87+
}
88+
89+
const recursivePath = findCurrentPage(itemPath, item.items);
90+
if (recursivePath) return recursivePath;
91+
}
92+
}
93+
94+
function openSearch() {
95+
const el = document
96+
.getElementById("docsearch")
97+
.querySelector(".DocSearch-Button");
98+
el.click();
99+
}
100+
101+
const smallScreenSize = 768;
102+
103+
const removeHashPath = (path) => {
104+
if (!path) {
105+
return null;
106+
}
107+
let index = path.indexOf("#");
108+
index = index > 0 ? index : path.length;
109+
return path.substring(0, index);
110+
};
111+
// v-bind dont like the # in the url
112+
const nextPagePath = removeHashPath(NEXT_PAGE);
113+
const previousPagePath = removeHashPath(PREVIOUS_PAGE);
114+
116115
const app = createApp({
117116
setup() {
118117
const { width: windowWidth } = useWindowSize();
@@ -242,8 +241,8 @@ const app = createApp({
242241
block: "center",
243242
inline: "center",
244243
});
245-
});
246-
244+
});
245+
247246
const enableTocFilter = ref('none');
248247
const searchQuery = ref('');
249248

@@ -262,8 +261,8 @@ const app = createApp({
262261
matches = matches || childMatches;
263262
}
264263
return matches;
265-
}
266-
264+
}
265+
267266
watch(searchQuery, (newQuery) => {
268267
if (!newQuery) {
269268
expandedTocs.clear();
@@ -281,48 +280,48 @@ const app = createApp({
281280
}
282281
});
283282
}
284-
});
285-
283+
});
284+
286285
function normalizeString(str) {
287286
return str.replace(/[^\w\s]|_/g, "").replace(/\s+/g, " ").toLowerCase();
288-
}
289-
290-
return {
291-
previousPageUrl,
292-
nextPageUrl,
293-
goToPrevious,
294-
goToNext,
295-
openSearch,
296-
297-
snackbarMessage,
298-
snackbarColor,
299-
copyToClipboard,
300-
301-
contentComingSoonList,
302-
featuresComingSoonList,
303-
completedFeaturesList,
304-
305-
sidebarShown,
306-
sidebarTab,
307-
308-
smallScreen,
309-
310-
sectionTitle,
311-
tocData,
312-
expandedTocs,
313-
currentPage,
314-
chapterParentPage,
287+
}
288+
289+
return {
290+
previousPageUrl,
291+
nextPageUrl,
292+
goToPrevious,
293+
goToNext,
294+
openSearch,
295+
296+
snackbarMessage,
297+
snackbarColor,
298+
copyToClipboard,
299+
300+
contentComingSoonList,
301+
featuresComingSoonList,
302+
completedFeaturesList,
303+
304+
sidebarShown,
305+
sidebarTab,
306+
307+
smallScreen,
308+
309+
sectionTitle,
310+
tocData,
311+
expandedTocs,
312+
currentPage,
313+
chapterParentPage,
315314

316315
searchQuery,
317-
filteredTocData,
318-
enableTocFilter
319-
};
320-
},
321-
});
322-
323-
app.component("toc-tree", {
324-
props: ["item", "expandedTocs", "currentPage"],
325-
template: "#toc-tree",
326-
});
327-
328-
app.mount("#app");
316+
filteredTocData,
317+
enableTocFilter
318+
};
319+
},
320+
});
321+
322+
app.component("toc-tree", {
323+
props: ["item", "expandedTocs", "currentPage"],
324+
template: "#toc-tree",
325+
});
326+
327+
app.mount("#app");

0 commit comments

Comments
 (0)