astro-accelerator 0.0.79 → 0.0.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/public/css/main.css
CHANGED
package/public/js/main.js
CHANGED
|
@@ -7,6 +7,7 @@ import { setClickableBlocks } from './modules/click-blocks.js';
|
|
|
7
7
|
import { setExternalLinkAttributes } from './modules/external-links.js';
|
|
8
8
|
import { monitorInputType } from './modules/input-type.js';
|
|
9
9
|
import { enableSharing } from './modules/share.js';
|
|
10
|
+
import { highlightCurrentHeading } from './modules/toc.js';
|
|
10
11
|
|
|
11
12
|
const resizedEventName = addResizedEvent();
|
|
12
13
|
|
|
@@ -18,6 +19,7 @@ addIntersectionObserver('.anim-show-parent img, .anim-show-parent .list-item');
|
|
|
18
19
|
addListImageIntersectionObserver('.post-list img');
|
|
19
20
|
monitorInputType();
|
|
20
21
|
enableSharing();
|
|
22
|
+
highlightCurrentHeading('.page-toc a');
|
|
21
23
|
|
|
22
24
|
// @ts-ignore
|
|
23
25
|
const f = site_features ?? {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { qsa } from './query.js';
|
|
4
|
+
|
|
5
|
+
let links = [];
|
|
6
|
+
let current = '';
|
|
7
|
+
const headings = [];
|
|
8
|
+
const highlightClass = 'highlight';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Makes an entire block clickable based on a data-attribute, usually "data-destination"
|
|
12
|
+
*
|
|
13
|
+
* Example: You have a list of blog posts, including featured images. If you make the title
|
|
14
|
+
* clickable, clicks on the image won't open the blog. Adding links to the images means
|
|
15
|
+
* keyboard users have to tab twice as much to get through the list.
|
|
16
|
+
*
|
|
17
|
+
* Use clickable blocks to allow keyboard users to tab through the real links, but still
|
|
18
|
+
* capture clicks elsewhere on the block.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
function highlightCurrentHeading(tocSelector) {
|
|
22
|
+
links = qsa(tocSelector);
|
|
23
|
+
|
|
24
|
+
links.forEach((link) => {
|
|
25
|
+
const linkParts = link.href.split('#');
|
|
26
|
+
if (linkParts.length === 2) {
|
|
27
|
+
const id = linkParts[1];
|
|
28
|
+
headings.push(document.getElementById(id));
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
recheck();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function highlight(id) {
|
|
36
|
+
links.forEach((link) => {
|
|
37
|
+
link.classList.remove(highlightClass);
|
|
38
|
+
|
|
39
|
+
if (link.href.indexOf(`#${id}`) > -1) {
|
|
40
|
+
link.classList.add(highlightClass);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function recheck() {
|
|
46
|
+
const docTop = Math.floor(document.documentElement.scrollTop);
|
|
47
|
+
const vh = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0)
|
|
48
|
+
|
|
49
|
+
const validItems = [];
|
|
50
|
+
|
|
51
|
+
headings.forEach((elem) => {
|
|
52
|
+
|
|
53
|
+
const isValid = (docTop + vh) - elem.offsetTop > (vh / 3);
|
|
54
|
+
if (isValid) {
|
|
55
|
+
validItems.push(elem);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const item = validItems.pop();
|
|
60
|
+
|
|
61
|
+
if (item && item.id !== current) {
|
|
62
|
+
console.log('Reading', item.id);
|
|
63
|
+
current = item.id;
|
|
64
|
+
highlight(item.id);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
window.setTimeout(recheck, 1000);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { highlightCurrentHeading };
|
|
@@ -9,18 +9,19 @@ type Props = {
|
|
|
9
9
|
lang: string;
|
|
10
10
|
frontmatter: Frontmatter;
|
|
11
11
|
headings: { depth: number; slug: string; text: string; }[];
|
|
12
|
+
expanded?: boolean;
|
|
12
13
|
};
|
|
13
|
-
const { lang, frontmatter, headings } = Astro.props satisfies Props;
|
|
14
|
+
const { lang, frontmatter, headings, expanded } = Astro.props satisfies Props;
|
|
14
15
|
|
|
15
16
|
// Language
|
|
16
17
|
const _ = Lang(lang);
|
|
17
18
|
|
|
18
19
|
// Logic
|
|
19
|
-
|
|
20
|
+
const openAttribute = expanded ? 'open' : null;
|
|
20
21
|
---
|
|
21
22
|
{headings?.length > 0 &&
|
|
22
23
|
<nav class="page-toc" aria-label={ _(Translations.aria.toc) }>
|
|
23
|
-
<details>
|
|
24
|
+
<details open={ openAttribute }>
|
|
24
25
|
<summary>{ _(Translations.toc.title) }</summary>
|
|
25
26
|
<ol>
|
|
26
27
|
{headings.map((heading) =>(
|