Add helpers file

This commit is contained in:
TheThomaas 2023-11-13 21:35:49 +01:00
parent dcc9e5e66a
commit 24e18de6e1

23
src/_data/helpers.js Normal file
View 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;
},
};