From 73b7e5a1ccb4c20929b8357862f7585503eb7792 Mon Sep 17 00:00:00 2001 From: Zev Averbach Date: Fri, 11 Feb 2022 19:48:45 +0100 Subject: [PATCH] add anchor links for each mentor/project for easy direct linking (#170) --- _includes/mentors.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/_includes/mentors.md b/_includes/mentors.md index e5711c5..b7f4c2a 100644 --- a/_includes/mentors.md +++ b/_includes/mentors.md @@ -453,4 +453,43 @@ people.forEach(person => { }); }); e.remove(); + +Array + .from(document.querySelectorAll("h3")) + .filter(el => !['Expectations For Mentees', 'Missing Mentor Topics', 'Exercism.io', 'Expectations For Mentors'] + .includes(el.innerText) + ) + .forEach(el => addAnchorLink(el)) + + +const addAnchorLink = el => { + const anchor = document.createElement('a') + anchor.href = `#${el.id}` + const svg = createSVGForAnchorLink() + anchor.appendChild(svg) + + const anchorSpan = document.createElement('span') + anchorSpan.appendChild(anchor) + el.appendChild(anchorSpan) +} + +const createSVGForAnchorLink = () => { + // use anchor link SVG icon from https://heroicons.com/ + let svg = document.createElementNS("http://www.w3.org/2000/svg", "svg") + svg.setAttribute("class", "h-5 w-5") + svg.setAttribute("viewBox", "0 0 20 20") + svg.setAttribute("fill", "currentColor") + + let path = document.createElementNS("http://www.w3.org/2000/svg", "path") + path.setAttribute("fill-rule", "evenodd") + path.setAttribute("d", "M12.586 4.586a2 2 0 112.828 2.828l-3 3a2 2 0 01-2.828 0 1 1 0 00-1.414 1.414 4 4 0 005.656 0l3-3a4 4 0 00-5.656-5.656l-1.5 1.5a1 1 0 101.414 1.414l1.5-1.5zm-5 5a2 2 0 012.828 0 1 1 0 101.414-1.414 4 4 0 00-5.656 0l-3 3a4 4 0 105.656 5.656l1.5-1.5a1 1 0 10-1.414-1.414l-1.5 1.5a2 2 0 11-2.828-2.828l3-3z") + path.setAttribute("clip-rule", "evenodd") + svg.appendChild(path) + + svg.style.height = ".8em" + svg.style.marginLeft = ".5em" + + return svg +} +