From 24e18de6e100ec4e74befb4cc46e41d80f2859cd Mon Sep 17 00:00:00 2001 From: TheThomaas Date: Mon, 13 Nov 2023 21:35:49 +0100 Subject: [PATCH] Add helpers file --- src/_data/helpers.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/_data/helpers.js 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