[site/components][f]: definitions preview on hover
This commit is contained in:
parent
5ef39edfe7
commit
1ba2193870
|
|
@ -1,4 +1,5 @@
|
||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
|
import { useRouter } from 'next/router'
|
||||||
import {unified} from 'unified'
|
import {unified} from 'unified'
|
||||||
import rehypeParse from 'rehype-parse'
|
import rehypeParse from 'rehype-parse'
|
||||||
import find from 'unist-util-find'
|
import find from 'unist-util-find'
|
||||||
|
|
@ -10,6 +11,7 @@ const textStyles = (theme) => ({
|
||||||
background: theme === 'light' ? '#fff' : '#000',
|
background: theme === 'light' ? '#fff' : '#000',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
const display = (data, theme) => {
|
const display = (data, theme) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|
@ -24,17 +26,31 @@ const display = (data, theme) => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getAbsolutePath = ({ currentPath, basePath, relativePath }) => {
|
||||||
|
console.log({ currentPath, basePath, relativePath });
|
||||||
|
const absolutePath = currentPath.slice(1).split("/")
|
||||||
|
absolutePath.pop(); // remove current page name
|
||||||
|
absolutePath.unshift(basePath);
|
||||||
|
absolutePath.push(relativePath);
|
||||||
|
console.log(absolutePath);
|
||||||
|
return absolutePath.join("/");
|
||||||
|
}
|
||||||
|
|
||||||
export const Content = (props) => {
|
export const Content = (props) => {
|
||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
data: "",
|
data: "",
|
||||||
isLoaded: false,
|
isLoaded: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
useEffect(async () => {
|
useEffect(async () => {
|
||||||
// const path = `/concepts/${props.value}`;
|
const basePath = "http://localhost:3000";
|
||||||
// console.log(path)
|
const currentPath = router.asPath;
|
||||||
const path = "http://localhost:3000/concepts/bitcoin";
|
const relativePath = props.value.split(".")[0]; // temp remove .md
|
||||||
fetch(path).then((response) => {
|
const absolutePath = getAbsolutePath({ currentPath, basePath, relativePath });
|
||||||
|
console.log(absolutePath);
|
||||||
|
fetch(absolutePath).then((response) => {
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
console.log(`Looks like there was a problem. Status Code: ${response.status}`)
|
console.log(`Looks like there was a problem. Status Code: ${response.status}`)
|
||||||
return
|
return
|
||||||
|
|
@ -51,7 +67,6 @@ export const Content = (props) => {
|
||||||
const p = find(main, (node) => {
|
const p = find(main, (node) => {
|
||||||
return node.tagName === "p"
|
return node.tagName === "p"
|
||||||
})
|
})
|
||||||
// console.log(toString(p))
|
|
||||||
setState({
|
setState({
|
||||||
data: toString(p),
|
data: toString(p),
|
||||||
isLoaded: true,
|
isLoaded: true,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue