From 5b9a091029f3bc8cdc7cdb08bef078484b8181fd Mon Sep 17 00:00:00 2001 From: khalilcodes Date: Mon, 13 Jun 2022 22:48:01 +0300 Subject: [PATCH 1/2] [site/links][xs]: modify path source --- site/components/Tooltip.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/components/Tooltip.js b/site/components/Tooltip.js index 619b7c9..99be3f7 100644 --- a/site/components/Tooltip.js +++ b/site/components/Tooltip.js @@ -117,7 +117,7 @@ export const Tooltip = ({ render, ...props }) => { if (filePath.includes('notes')) { return } - const page = allOtherPages.find(p => p._raw.sourceFilePath === filePath) + const page = allOtherPages.find(p => p._raw.flattenedPath === filePath) content = documentExtract(page.body.raw); } catch { return From 07dd5269921d61b95240604689eca279316b1b30 Mon Sep 17 00:00:00 2001 From: khalilcodes Date: Mon, 13 Jun 2022 22:50:03 +0300 Subject: [PATCH 2/2] [site/links][m]: add logic for next links --- site/components/Anchor.js | 46 +++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/site/components/Anchor.js b/site/components/Anchor.js index f239f93..9ef5df3 100644 --- a/site/components/Anchor.js +++ b/site/components/Anchor.js @@ -1,5 +1,6 @@ +import { useEffect, useState } from "react" +import Link from 'next/link'; import { Tooltip } from './Tooltip'; - /** * Component for adding previews on hovering over anchor tags with relative paths */ @@ -8,17 +9,44 @@ export const Anchor = (props) => { const pathIsRelative = (path) => { return path && path.indexOf("http:") !== 0 && - path.indexOf("https:") !== 0 && - path.indexOf("#") !== 0 + path.indexOf("https:") !== 0 } - if (pathIsRelative(props.href)) { + const href = props.href.endsWith(".md") + ? props.href.replace(".md", "") + : props.href; + + const [ path, setPath ] = useState(href) + + useEffect(() => { + let isMount = true + if (isMount) { + const link = document.createElement("a") + link.href = href + setPath(link.pathname) + } + return () => { + setPath(href) + isMount = false + } + },[]) + + if (pathIsRelative(href)) { + if (href.indexOf("#") !== 0) { + return ( + ( + + + + )} + /> + ) + } return ( - ( - - )} - /> + + + ) } - return ; + return ; };