Add helpers file
This commit is contained in:
parent
dcc9e5e66a
commit
24e18de6e1
23
src/_data/helpers.js
Normal file
23
src/_data/helpers.js
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* Returns back some attributes based on wether the
|
||||||
|
* link is active or a parent of an active item
|
||||||
|
*
|
||||||
|
* @param {String} itemUrl The link in question
|
||||||
|
* @param {String} pageUrl The page context
|
||||||
|
* @returns {String} The attributes or empty
|
||||||
|
*/
|
||||||
|
getLinkActiveState(itemUrl, pageUrl) {
|
||||||
|
let response = '';
|
||||||
|
|
||||||
|
if (itemUrl === pageUrl) {
|
||||||
|
response = ' aria-current="page"';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemUrl.length > 1 && pageUrl.indexOf(itemUrl) === 0) {
|
||||||
|
response += ' data-state="active"';
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
};
|
||||||
Loading…
Reference in a new issue