Skip to content

Commit 3a79635

Browse files
committed
feat($active-header-links): sidebarLinkSelector & headerAnchorSelector option
1 parent 62c3525 commit 3a79635

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
const { path } = require('@vuepress/shared-utils')
22

3-
module.exports = {
4-
clientRootMixin: path.resolve(__dirname, 'mixin.js')
5-
}
3+
module.exports = (options) => ({
4+
clientRootMixin: path.resolve(__dirname, 'mixin.js'),
5+
define: {
6+
AHL_SIDEBAR_LINK_SELECTOR: options.sidebarLinkSelector || '.sidebar-link',
7+
AHL_HEADER_ANCHOR_SELECTOR: options.headerAnchorSelector || '.header-anchor'
8+
}
9+
})

packages/@vuepress/plugin-active-header-links/mixin.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* global AHL_SIDEBAR_LINK_SELECTOR, AHL_HEADER_ANCHOR_SELECTOR */
2+
13
import throttle from 'lodash.throttle'
24

35
function calculateCurrentAnchor (anchors) {
@@ -25,9 +27,9 @@ function calculateCurrentAnchor (anchors) {
2527
}
2628

2729
function getAnchors () {
28-
const sidebarLinks = [].slice.call(document.querySelectorAll('.sidebar-link'))
30+
const sidebarLinks = [].slice.call(document.querySelectorAll(AHL_SIDEBAR_LINK_SELECTOR))
2931
return [].slice
30-
.call(document.querySelectorAll('.header-anchor'))
32+
.call(document.querySelectorAll(AHL_HEADER_ANCHOR_SELECTOR))
3133
.filter(anchor => sidebarLinks.some(sidebarLink => sidebarLink.hash === anchor.hash))
3234
.map(el => {
3335
return {

0 commit comments

Comments
 (0)