Skip to content

Commit

Permalink
feat($active-header-links): sidebarLinkSelector & headerAnchorSelecto…
Browse files Browse the repository at this point in the history
…r option
  • Loading branch information
ulivz committed Nov 5, 2018
1 parent 62c3525 commit 3a79635
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 7 additions & 3 deletions packages/@vuepress/plugin-active-header-links/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const { path } = require('@vuepress/shared-utils')

module.exports = {
clientRootMixin: path.resolve(__dirname, 'mixin.js')
}
module.exports = (options) => ({
clientRootMixin: path.resolve(__dirname, 'mixin.js'),
define: {
AHL_SIDEBAR_LINK_SELECTOR: options.sidebarLinkSelector || '.sidebar-link',
AHL_HEADER_ANCHOR_SELECTOR: options.headerAnchorSelector || '.header-anchor'
}
})
6 changes: 4 additions & 2 deletions packages/@vuepress/plugin-active-header-links/mixin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global AHL_SIDEBAR_LINK_SELECTOR, AHL_HEADER_ANCHOR_SELECTOR */

import throttle from 'lodash.throttle'

function calculateCurrentAnchor (anchors) {
Expand Down Expand Up @@ -25,9 +27,9 @@ function calculateCurrentAnchor (anchors) {
}

function getAnchors () {
const sidebarLinks = [].slice.call(document.querySelectorAll('.sidebar-link'))
const sidebarLinks = [].slice.call(document.querySelectorAll(AHL_SIDEBAR_LINK_SELECTOR))
return [].slice
.call(document.querySelectorAll('.header-anchor'))
.call(document.querySelectorAll(AHL_HEADER_ANCHOR_SELECTOR))
.filter(anchor => sidebarLinks.some(sidebarLink => sidebarLink.hash === anchor.hash))
.map(el => {
return {
Expand Down

0 comments on commit 3a79635

Please sign in to comment.