From 8250aaf9d6795a6ac9f96a929f6f5adf7b82115d Mon Sep 17 00:00:00 2001 From: Sivert Date: Fri, 20 Oct 2023 23:41:37 +0200 Subject: [PATCH] Added back to top button and fixed links --- components/MdxConvertedComponents.tsx | 2 +- config/animations.ts | 2 +- pages/posts/[slug].tsx | 27 ++++++++++++++-- posts/introduction.mdx | 20 +++++++++--- posts/sivert.mdx | 44 +++++++++++++++++++++++++++ 5 files changed, 87 insertions(+), 8 deletions(-) create mode 100644 posts/sivert.mdx diff --git a/components/MdxConvertedComponents.tsx b/components/MdxConvertedComponents.tsx index ff91ccc..e5dfca5 100644 --- a/components/MdxConvertedComponents.tsx +++ b/components/MdxConvertedComponents.tsx @@ -67,7 +67,7 @@ Components["KBD"] = (props) => { Components["Link"] = (props) => { return ( - + {props.children} ); diff --git a/config/animations.ts b/config/animations.ts index 8cde79d..83c2e27 100644 --- a/config/animations.ts +++ b/config/animations.ts @@ -1,5 +1,5 @@ const exitAnimation = { opacity: 0, y: 10, transition: { duration: .1, ease: 'linear' } } -const transition = { type: 'spring', stiffness: 200 } +export const transition = { type: 'spring', stiffness: 200 } export const staggerTransition = { staggerChildren: 0.05 } as const export const ArticleCardVariant = { diff --git a/pages/posts/[slug].tsx b/pages/posts/[slug].tsx index 1d81e79..9838ae4 100644 --- a/pages/posts/[slug].tsx +++ b/pages/posts/[slug].tsx @@ -2,13 +2,15 @@ import { format, parseISO } from "date-fns"; import { allPosts, Post } from "contentlayer/generated"; import { useMDXComponent } from "next-contentlayer/hooks"; import MotionWrapper from "components/MotionWrapper"; -import { ArticleContentVariant, staggerTransition } from "config/animations"; +import { ArticleContentVariant, staggerTransition, transition } from "config/animations"; import StaggerWrapper from "components/StaggerWrapper"; -import React from "react"; +import React, { useEffect, useState } from "react"; import { Components } from "components/MdxConvertedComponents"; import { ImageWithFallback } from "components/ImageWithFallback"; import { Comments } from "components/Comments"; import { HeadMetaGenerator } from "components/HeadMetaGenerator"; +import {FaArrowUp} from 'react-icons/fa'; +import {motion, useMotionValueEvent, useScroll} from 'framer-motion' export async function getStaticPaths() { const paths: string[] = allPosts.map((post) => post.url); @@ -31,6 +33,9 @@ export async function getStaticProps({ params }) { const PostLayout = ({ post }: { post: Post }) => { const MDXContent = useMDXComponent(post.body.code); + const [isOpen, setIsOpen] = useState(false); + const scroll = useScroll(); + useMotionValueEvent(scroll.scrollY, "change", (latest) => setIsOpen(latest > 360)) return ( <> @@ -40,6 +45,24 @@ const PostLayout = ({ post }: { post: Post }) => { metaImg={post.image ? `${post.image}` : null} title={post.title} /> + +
+ +
+