diff --git a/src/_data/helpers.js b/src/_data/helpers.js new file mode 100644 index 0000000..22f4e70 --- /dev/null +++ b/src/_data/helpers.js @@ -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; + }, +}; \ No newline at end of file